如何在Opencv中显示Mat [英] how to display a Mat in Opencv

查看:130
本文介绍了如何在Opencv中显示Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于存储图像的垫子,使用imshow可以很容易地显示它.但是,如果垫子的数据类型为CV_32FC1,如何显示该垫子?

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 ?

我尝试了imshow,但是显示图形是完全白色的,当我将int缩放时,它仍然是完全空白的,并且我看不到垫子中的浮点数.

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 .:感谢您的回复.我将发布一些代码和数字以显示更多详细信息: 代码:

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;

输出:

放大150%之后:

然后,当我放大150%后,我们可以看到'test'是完全白色的,我们看不到它的元素值. 'test1'完全是黑色的,我们仍然看不到它的元素值.但是对于"test2",它是灰色的,我们可以看到其元素值为200.

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.

这个实验是否意味着imshow()只能显示CV_8UC1而我们不能显示任何其他数据类型?

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

推荐答案

如果image是CV_32F类型的Mat,如果图像是32位浮点,则

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.

无论范围是多少,这都会显示CV32F图像:

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);

这篇关于如何在Opencv中显示Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆