bal*_*erc 6 c++ interpolation opencv image-processing
我定义了一个包含 2 个值的数组,并尝试使用 imgproc 模块的调整大小函数将其大小调整为 10 个元素,并使用线性插值作为插值方法。
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) << " ";
}
Run Code Online (Sandbox Code Playgroud)
我期望的输出是:
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Run Code Online (Sandbox Code Playgroud)
然而我得到的是:
0 0 0 0.136364 0.318182 0.5 0.681818 0.863636 1 1 1
Run Code Online (Sandbox Code Playgroud)
显然,我对调整大小如何工作的理解从根本上来说是错误的。有人可以告诉我我做错了什么吗?诚然,OpenCV 对于这种简单的线性插值来说有点大材小用,但请帮助我解决这里的问题。