OpenCV C++错误-断言失败

OpenCV C++错误-断言失败,c++,opencv,C++,Opencv,我正在尝试查找选定像素的颜色。 我得到了这个错误: Unhandled exception at 0x770FC42D in OpenCV_Test.exe: Microsoft C++ exception: cv::Exception at memory location 0x003atEEB84. 在控制台中,它写入了断言错误 我使用了以下代码: static void onMouse(int event, int x, int y, int, void* imgptr){ if

我正在尝试查找选定像素的颜色。 我得到了这个错误:

Unhandled exception at 0x770FC42D in OpenCV_Test.exe: Microsoft C++ exception: cv::Exception at memory location 0x003atEEB84.
在控制台中,它写入了断言错误

我使用了以下代码:

static void onMouse(int event, int x, int y, int, void* imgptr){
    if (event != 1)
        return;
    else{
            Mat& imgMat = (*(Mat*)imgptr);
            Vec3f intensity = imgMat.at<Vec3f>(Point(x,y));
            uchar blue = intensity.val[0];
            uchar green = intensity.val[1];
            uchar red = intensity.val[2];

            imshow("Display window", imgMat);
            waitKey(1);
    }
}

int main(){

    Mat img = imread("colorImg2.jpg");

    if (!img.data)
    {
        std::cout << " --(!) Error reading images " << std::endl; return -1;
    }

    namedWindow("Display window", 0);
    setMouseCallback("Display window", onMouse, &img);

    imshow("Display window", img);
    waitKey(0);

}
我看到它发生在这条直线上,Vec3f intensity=imgMat.atx,y;
我尝试了float示例和代码中使用的uchar,但得到了相同的错误。

您等待onMouse事件处理程序中的按键有什么原因吗?只等一毫秒?这就是问题所在:谢谢!!!更改代码后忘记删除它…应该是Vec3b。Vec3f甚至会导致缓冲区溢出