nowmengxin 2021-11-11 15:33 采纳率: 100%
浏览 10
已结题

怎么看懂问题出在哪里

代码

#include <stdio.h>
#include <string>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include<opencv2/highgui/highgui_c.h>

using namespace std;
using namespace cv;

int main()
{
    // 图像读取及判断
    Mat srcImage = imread("F:\\轮胎网图.jpg");
    if (!srcImage.data)
        return 1;
    // 灰度转换
    Mat srcGray;
    cvtColor(srcImage, srcGray, CV_RGB2GRAY);
    namedWindow("srcGray", CV_NORMAL);
    imshow("srcGray", srcGray);
    GaussianBlur(srcGray, srcGray, Size(11,11 ), 0);
    threshold(srcGray, srcGray, 0, 255, CV_THRESH_OTSU);
    namedWindow("otsuResultImage", CV_NORMAL);
    imshow("otsuResultImage", srcGray);

    //五个颜色,聚类之后的颜色随机从这里面选择
    Scalar colorTab[] = {
        Scalar(255,255,255),
        Scalar(0,0,0),
    };

    int width = srcGray.cols;//图像的宽
    int height = srcGray.rows;//图像的高
    int channels = srcGray.channels();//图像的通道数
    cout << width << height << "tong dao"<<channels << endl;
    //初始化一些定义
    int sampleCount = width * height;//所有的像素
    int clusterCount = 2;//分类数
    Mat points(sampleCount, channels, CV_8U, Scalar(0));//points用来保存所有的数据
    Mat labels;//聚类后的标签
    Mat center(clusterCount, 1, points.type());//聚类后的类别的中心

    //将灰度图图像的像素转到到样本数据
    int index = 0;
    for (int row = 0; row < height; row++)
    {
        for (int col = 0; col < width; col++)
        {
            index = row * width + col;  //为每个像素点赋索引值,一行一行的进行
            int bgr = srcGray.at<uchar>(row, col);// 8U 类型的 RGB 彩色图像可以使用 <Vec3b>
            points.at<float>(index) = static_cast<int>(bgr);  //通道的分量
            //cv::mat的成员函数: .at(int y, int x)可以用来存取图像中对应坐标为(x,y)的元素坐标。
        }
    }
    //运行K-means算法
    //MAX_ITER也可以称为COUNT最大迭代次数,EPS最高精度,10表示最大的迭代次数,0.1表示结果的精确度
    TermCriteria criteria = TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 10, 0.1);
    cv::kmeans(points, clusterCount, labels, criteria, 3, KMEANS_PP_CENTERS, center);

    //显示图像分割结果
    Mat result = Mat::zeros(srcGray.size(), srcGray.type());//创建一张结果图
    for (int i = 0; i < srcGray.rows; i++)
    {
        for (int j = 0; j < srcGray.cols; j++)
        {
            index = i * width + j;
            int label = labels.at<int>(index,0);//每一个像素属于哪个标签
            result.at<uchar>(i, j) = colorTab[label][0];//对结果图中的每一个通道进行赋值
        }
    };
    imshow("Kmeans", result);
    cv::waitKey(0);
    return 0;
}

报错是这个

img


提示的有900多行是啥意思,我程序没有900行为啥提示这么多行,还有如何知道这个900行错误是如何转换到现有的代码是多少行错误?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 11月19日
    • 创建了问题 11月11日

    悬赏问题

    • ¥15 解决一个加好友限制问题 或者有好的方案
    • ¥15 关于#java#的问题,请各位专家解答!
    • ¥15 急matlab编程仿真二阶震荡系统
    • ¥20 TEC-9的数据通路实验
    • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
    • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
    • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
    • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
    • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
    • ¥30 求解达问题(有红包)