繁体   English   中英

cv::Mat.data 总是返回相同的值

[英]cv::Mat.data always returns the same value

我有一个红色图像 - 仅用于测试。 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”。

如果我将图像更改为完全黄色,它会返回完全相同的值。 怎么可能?

问候, 简

好的,对不起,我明白了。 你看不到它。 我为SrcImageDestImage提供了相同的图像,所以DestImage = Mat(newWidth, newHeight, SrcImage.type()); 覆盖图像。 在该行之前,值是正确的。

对不起……

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM