我有一张红色图片 - 仅供测试。 RGB颜色为(217/18/36)。
我执行以下代码:
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;
}
它总是返回“205”。
如果我将图像更改为完全黄色,则返回完全相同的值。怎么可能?
此致,Jan
好的,对不起,我明白了。你看不到它。我为SrcImage
和DestImage
提供相同的图像,所以线DestImage = Mat(newWidth, newHeight, SrcImage.type());
overwrote图像。在该行之前,值是正确的。
对不起...