[英]cv::Mat.data always returns the same value
I have a red image - just for testing.我有一个红色图像 - 仅用于测试。 The RGB Color is (217/18/36).
RGB 颜色为 (217/18/36)。
I perform the following code:我执行以下代码:
void QuaterImage(Mat& SrcImage, Mat& DestImage, bool Downsample) {
int newWidth = 0, newHeight = 0;
int newOrigWidth = 0, newOrigHeight = 0;
if (SrcImage.cols % 2 > 0) { newOrigWidth = SrcImage.cols - 1; } else { newOrigWidth = SrcImage.cols; }
if (SrcImage.rows % 2 > 0) { newOrigHeight = SrcImage.rows - 1; } else { newOrigHeight = SrcImage.rows; }
if (SrcImage.depth() != CV_8U) { return; }
newHeight = newOrigHeight / 2;
newWidth = newOrigWidth / 2;
DestImage = Mat(newWidth, newHeight, SrcImage.type());
int r = 0, c = 0;
uchar* DataPtr = SrcImage.ptr<uchar>(0);
std::cout << std::to_string(*DataPtr) << std::endl;
return;
}
It always returns "205".它总是返回“205”。
If I change the image to be complettely yellow, it returns the exact same value.如果我将图像更改为完全黄色,它会返回完全相同的值。 How can that be?
怎么可能?
Regards, Jan问候, 简
Ok, sorry, I got it.好的,对不起,我明白了。 You could not see it.
你看不到它。 I was giving the same image for
SrcImage
and DestImage
, so the line DestImage = Mat(newWidth, newHeight, SrcImage.type());
我为
SrcImage
和DestImage
提供了相同的图像,所以DestImage = Mat(newWidth, newHeight, SrcImage.type());
overwrote the image.覆盖图像。 Before that line, the values are correct.
在该行之前,值是正确的。
Sorry for that...对不起……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.