我试图找到所选像素的颜色。 我收到了这个错误:
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.at<Vec3f>(x, y);
我尝试了float示例和uchar(在代码中使用),我得到了同样的错误。