【OpenCV】imshow

函数原型:

void imshow(const string& winname, InputArray mat)
参数:
winname – Name of the window.
image – Image to be shown.

功能:

Displays an image in the specified window.

接下来主要说明一下当显示非uchar即非CV_8U类型的图像时,imshow是怎么操作的。

opencv中图像的基本数据类型有:

#define CV_8U   0
#define CV_8S   1
#define CV_16U  2
#define CV_16S  3
#define CV_32S  4
#define CV_32F  5
#define CV_64F  6

imshow在显示图像时,会将上面各种类型的数据都映射到[0, 255]。

在显示图像之前,imshow会判断输入图像的数据类型是否为CV_8U,如果不是,则会对图像数据进行转换,具体的转换方式如下:

int src_depth = CV_MAT_DEPTH(src->type); // 获取输入图像的数据类型
double scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255; // 获取scale
double shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0; // 获取shift

在通过上面的方式确定scale和shift之后,接下来便是对数据进行转换:

cvConvertScale( src, dst, scale, shift );

通过转换得到的dst便是用来显示的图像了。

文档中的说明:

The function may scale the image, depending on its depth:
If the image is 8-bit unsigned, it is displayed as is.
If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the value range [0,255*256] is mapped to [0,255].
If the image is 32-bit floating-point, the pixel values are multiplied by 255. That is, the value range [0,1] is mapped to [0,255].

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值