Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display a Mat in Opencv

Tags:

c++

opencv

For the mat which stores images, it is easy to show it using imshow.But if the data type of the Mat is CV_32FC1, how can I display this mat ?

I tried imshow, but the display figure is totally white and when I zoom int, it is still totally blank, and I cannot see the float numbers in mat.

Is there anyone who knows how to show entire mat matrix ?

p.s.: thanks for replying. I will post some codes and figures to show more details: codes:

Mat mat1;
mat1 = Mat::ones(3,4,CV_32FC1);
mat1 = mat1 * 200;
imshow("test", mat1);
waitKey(0);

Mat dst;
normalize(mat1, dst, 0, 1, NORM_MINMAX);
imshow("test1", dst);
waitKey(0);

mat1.convertTo(dst, CV_8UC1);
imshow("test2", dst);
waitKey(0);

return 0;

output:

enter image description here

after I zoom in by 150%:

enter image description here

Then after I zoom in by 150%, we can see that 'test' is totally white and we cannot see its element values. 'test1' is totally black and we still cannot see its element values. But for 'test2', it is gray and we can see its element value which is 200.

Does this experiment mean that imshow()can only show CV_8UC1 and we cannot show any other datatyes ?

like image 632
tqjustc Avatar asked Nov 28 '22 15:11

tqjustc


1 Answers

If image is a Mat of type CV_32F, If the image is 32-bit floating-point, imshow() multiplies the pixel values by 255 - that is, the value range [0,1] is mapped to [0,255]. So your floating point image has to have a range 0 .. 1.

This will display a CV32F image, no matter what the range is:

        cv::Mat dst
        cv::normalize(image, dst, 0, 1, cv::NORM_MINMAX);
        cv::imshow("test", dst);
        cv::waitKey(0);
like image 185
Bull Avatar answered Dec 04 '22 04:12

Bull