简体   繁体   中英

OpenCV imshow bug? - pixel colors

I have spent half day to find the error. Finally I found this strange thing:

In one part of my code method1 I do the following:

Mat prevgray, gray, flow, cflow, frame;
cvtColor(frame1, prevgray, CV_BGR2GRAY);
cvtColor(frame2, gray, CV_BGR2GRAY);
calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
...

In other part, method2, I create new Mat and try to display it :

Mat result(480,640, CV_8UC3);
result.at<cv::Vec3b>(y,x)[0] = b;
result.at<cv::Vec3b>(y,x)[1] = g;
result.at<cv::Vec3b>(y,x)[2] = r;
namedWindow( "jojw", CV_WINDOW_AUTOSIZE );
imshow("jojw",result);
waitKey(0);

The result is this image:

在此处输入图片说明

However, if I don't use calcOpticalFlowFarneback method. I comment out it or return before code reaches it. The result image is OK.

What's happening?

Please help me

Solved myself. 12 hours spent to get this stupid error. Is that error? I still don't understand but the solution is to create zeros mat:

Mat result = Mat::zeros(480,640, CV_8UC3);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM