imshow() in OpenCV doesn't work for cv::Mat type CV_32F?

4k views Asked by At

I have a float array

float* data; // stores pixel gray color 
cv::Mat img(h,w,CV_32F,data);
cv::namedWindow("Display window");
cv::imshow( "Display window", img );

Then what I get is :

enter image description here

I searched for many resources but couldnt find out. I doubt it's the problem of the type but I compared with the definition and I think it's ok.

Can anyone tell me the reason?

1

There are 1 answers

2
zindarod On BEST ANSWER

If your image is a single channel one, then you convert it to CV_8U by:

float* data; // stores pixel gray color 

cv::Mat img(h,w,CV_32F,data), 8u_image;

img.convertTo(8u_image,CV_8U);

cv::namedWindow("Display window");

cv::imshow( "Display window", 8u_image );