Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV错误:cv::Mat::at中的断言失败((无符号)i0<;(无符号)size.p[0])_C++_C_Opencv - Fatal编程技术网

C++ OpenCV错误:cv::Mat::at中的断言失败((无符号)i0<;(无符号)size.p[0])

C++ OpenCV错误:cv::Mat::at中的断言失败((无符号)i0<;(无符号)size.p[0]),c++,c,opencv,C++,C,Opencv,我试图在500x500白色背景图像上绘制点 void Lab1() { float px[500]; float py[500]; float x, y; int nrPoints; //citire puncte din fisier FILE *pfile; pfile = fopen("points0.txt", "r"); //punere in variabila fscanf(pfile, "

我试图在500x500白色背景图像上绘制点

void Lab1() {

    float px[500];
    float py[500];
    float x, y;
    int nrPoints;
        //citire puncte din fisier
    FILE *pfile;
    pfile = fopen("points0.txt", "r");

        //punere in variabila
    fscanf(pfile, "%d", &nrPoints);

       //facem o imagine de 500/500 alba
    Mat whiteImg(500, 500, CV_8UC3);

    for (int i = 0; i < 500; i++) {
        for (int j = 0; j < 500; j++) {
            whiteImg.at<Vec3b>(i, j)[0] = 255; // b
            whiteImg.at<Vec3b>(i, j)[1] = 255; // g
            whiteImg.at<Vec3b>(i, j)[2] = 255; // r

        }
    }


      //punem punctele intr-un vector,pentru a le putea pozitiona ulterior in imaginea alba.

    for (int i = 0; i < nrPoints; i++) {
        fscanf(pfile, "%f%f", &x, &y);

        px[i] = x;
        py[i] = y;
        //afisam punctele
        printf("%f ", px[i]);
        printf("%f\n", py[i]);
    }

      //punem punctele pe imagine

    for (int i = 0; i < nrPoints; i++) {
        whiteImg.at<Vec3b>(px[i],py[i]) = 0;
    }

    imshow("img",whiteImg);
    fclose(pfile);
     //system("pause");
    waitKey();
}
void Lab1(){
浮动px[500];
浮动py[500];
浮动x,y;
积分;
//城市点灯酒店
文件*pfile;
pfile=fopen(“points0.txt”、“r”);
//瓦里比拉的普内雷
fscanf(pfile、%d、&nR点);
//facem o imagine de 500/500阿尔巴
Mat whiteImg(500500,CV_8UC3);
对于(int i=0;i<500;i++){
对于(int j=0;j<500;j++){
(i,j)[0]=255;//b
whiteImg.at(i,j)[1]=255;//g
(i,j)[2]=255;//r
}
}
//在白质影像中,有一种特殊的斑点。
对于(int i=0;i
问题在于:

whiteImg.at<Vec3b>(px[i],py[i]) = 0;
whiteImg.at(px[i],py[i])=0;
我无法避免这个错误:

OpenCV错误:在cv::Mat::at文件c:\users\toder\desktop\anul4\srf\laburi\U srf\opencvapplication-vs2015\U 31\U basic\OpenCV\include\opencv2\core\Mat.inl.hpp第917行中,断言失败((无符号)i0<(无符号)size.p[0])


你宣布你的垫子是

Mat(500, 500, CV_8UC3); 
CV_8UC3表示它有三个通道:一个用于红色,一个用于蓝色,一个用于绿色。不能在具有三个通道(Vec3b)的Mat中设置0(整数)。考虑到要在图像中的给定点设置值0,要打印的点颜色为黑色

您可以这样做:

whiteImg.at<Vec3b>(px[i],py[i]) = Vec3b(0,0,0);
whiteImg.at(px[i],py[i])=Vec3b(0,0,0);
或者,为了与您的代码风格保持一致:

whiteImg.at<Vec3b>(px[i],py[i])[0] = 0; //Blue Channel
whiteImg.at<Vec3b>(px[i],py[i])[1] = 0; //Green Channel
whiteImg.at<Vec3b>(px[i],py[i])[2] = 0; //Red Channel
whiteImg.at(px[i],py[i])[0]=0//蓝色通道
在(px[i],py[i])[1]=0//绿色通道
(px[i],py[i])[2]=0//红色通道
哪种语言?C++或C—选择一个。考虑到你使用模板以及C++ opencv API的一些部分,我认为C是不可能的……我没有看到任何输入的验证。您确定
px
py
的所有值都在图像的范围内吗顺便说一句,
cv::Mat::at
的第一个参数是行号。我将
px
读取为
x
坐标,即列号。