首页 > 解决方案 > OpenCV convertTo 从 bmp 图像到 double/CV_64FC1 没有给出与 Matlab 中相同的值

问题描述

在 OpenCV C++ 中,我尝试过

cv::Mat mat=cv::imread("input.bmp");
mat.convertTo(mat, CV_64FC1, 1.0/255.0);
for (int i=0; i<2; i++) {
    std::cout<<"\n";
    for (int j=0; j<2; j++) {
        std::cout<<mat.at<double>(i,j)<< " ";
    }   
}

这些值与我在 Matlab 中得到的值相匹配,但如果我尝试:

for (int i=314; i<316; i++) {
    std::cout<<"\n";
    for (int j=350; j<352; j++) {
        std::cout<<mat.at<double>(i,j)<< " ";
    }   
}

我得到的值是

.165 .189 
.274 .208

在 Matlab 中,如果我这样做

im=imread("input.bmp")
im2double(im(315:316,351:352))

我明白了

.294 .310
.317 .294

为什么是这样?

标签: c++opencv

解决方案


推荐阅读