4

I define an array of 2 values, and try to use the imgproc module's resize function to resize it to 10 elements with linear interpolation as interpolation method.

cv::Mat input = cv::Mat(1, 2, CV_32F);
input.at<float>(0, 0) = 0.f;
input.at<float>(0, 1) = 1.f;
cv::Mat output = cv::Mat(1, 11, CV_32F);
cv::resize(input, output, output.size(), 0, 0, cv::INTER_LINEAR);
for(int i=0; i<11; ++i)
{
    std::cout<< output.at<float>(0, i) << " ";
}

The output I would have expected is:

0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

What I get however is:

0 0 0 0.136364 0.318182 0.5 0.681818 0.863636 1 1 1

Clearly, my understanding of how resize works is wrong at a fundamental level. Can someone please tell me what I am doing wrong? Admittedly, OpenCV is an overkill for such simple linear interpolation, but please do help me with what is wrong here.

4

1 回答 1

3

这真的很简单。OpenCV 是一个图像处理库。所以你应该记住我们正在处理图像。

看看我们在目标图像中只有 8 个像素时的输出

0 0 0.125 0.375 0.625 0.875 1 1

如果您看一下这张图片,就很容易理解调整大小的行为

例子

正如您在此链接中看到的,您正在使用图像转换库:“本节中的函数执行 2D 图像的各种几何转换”

你想要这个结果

在此处输入图像描述

但它不会正确插入原始的 2 像素图像

于 2013-08-08T11:04:26.273 回答