[英]OpenCV convertTo()
I came across this code:我遇到了这个代码:
image.convertTo(temp_image,CV_16SC3);
I saw the description of the convertTo() function from here , but what confuses me is image
.我从这里看到了 convertTo() 函数的描述,但让我感到困惑的是
image
。 How can we read the above code?我们如何阅读上面的代码? What would be the relation between
image
and temp_image
? image
和temp_image
之间的关系是什么?
Thanks.谢谢。
The other answers here are correct, but lack some details.这里的其他答案是正确的,但缺少一些细节。 Let me try.
让我试试。
image.convertTo(temp_image,CV_16SC3);
You have a source image image
, and a destination image temp_image
.您有一个源图像
image
和一个目标图像temp_image
。 You didn't specify the type of image
, but probably is CV_8UC3
or CV_32FC3
, ie a 3 channel image (since convertTo
doesn't change the number of channels), where each channel has depth 8 bit ( unsigned char
, CV_ 8U C3) or 32 bit ( float
, CV_ 32F C3).您没有指定
image
的类型,但可能是CV_8UC3
或CV_32FC3
,即 3 通道图像(因为convertTo
不会改变通道数),其中每个通道的深度为 8 位( unsigned char
,CV_ 8U C3)或 32 位( float
, CV_ 32F C3 )。
This line of code will change the depth of each channel, so that temp_image
has each channel of depth 16 bit ( short
).这行代码会改变每个通道的深度,这样
temp_image
每个通道的深度都是 16 位( short
)。 Specifically it's a signed short
, since the type specifier has the S : CV_16 S C3.具体来说,它是一个有
signed short
,因为类型说明符有S : CV_16 S C3。
Note that if you are narrowing down the depth, as in the case from float
to signed short
, then saturate_cast
will make sure that all the values in temp_image
will be in the correct range, ie in [–32768, 32767] for signed short
.请注意,如果您正在缩小深度,如从
float
到signed short
,则saturate_cast
将确保temp_image
中的所有值都在正确的范围内,即在 [–32768, 32767] 中表示有signed short
。
Why you need to change the depth of an image?为什么需要改变图像的深度?
imread
, or want to store with imwrite
images with 16bit depth.imread
阅读,或者想要使用 16 位深度的imwrite
图像存储。 This are usually used (AFAIK) in medical or graphics application to allow a wider range of colors.An image is a matrix of pixel information (ie a 1080p
image will be a 1,920 × 1,080
matrix where each entry contains rbg
values for that pixel).图像是像素信息矩阵(即
1080p
图像将是1,920 × 1,080
矩阵,其中每个条目包含该像素的rbg
值)。 All you are doing is reformatting that matrix (each pixel entry, iteratively) into a new type ( CV_16SC3
) so it can be read by different programs.您所做的就是将该矩阵(每个像素条目,迭代地)重新格式化为新类型(
CV_16SC3
),以便不同的程序可以读取它。
The temp_image
is a new matrix of pixel information based off of image
formatted into CV_16SC3
. temp_image
是一个新的像素信息矩阵,基于格式化为CV_16SC3
的image
。
The first one is a source , the second one - destination .第一个是源,第二个是目的地。 So, it takes image, converts it into type CV_16SC3 and stores in temp_image.
因此,它获取图像,将其转换为 CV_16SC3 类型并存储在 temp_image 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.