c++ - 我可以用 opencv 提供的函数替换这个插值函数吗?

标签 c++ opencv interpolation

我从 here 中获取了这个函数:

bool interpolate(const Mat &im, float ofsx, float ofsy, float a11, float a12, float a21, float a22, Mat &res)
{         
   bool ret = false;
   // input size (-1 for the safe bilinear interpolation)
   const int width = im.cols-1;
   const int height = im.rows-1;
   // output size
   const int halfWidth  = res.cols >> 1;
   const int halfHeight = res.rows >> 1;
   int dim = res.rows * res.cols;
   float *out = res.ptr<float>(0);
   for (int j=-halfHeight; j<=halfHeight; ++j)
   {
      const float rx = ofsx + j * a12;
      const float ry = ofsy + j * a22;
      #pragma omp simd
      for(int i=-halfWidth; i<=halfWidth; ++i)
      {
         float wx = rx + i * a11;
         float wy = ry + i * a21;
         const int x = (int) floor(wx);
         const int y = (int) floor(wy);
         if (x >= 0 && y >= 0 && x < width && y < height)
         {
            // compute weights
            wx -= x; wy -= y;
            // bilinear interpolation
            *out++ = 
               (1.0f - wy) * ((1.0f - wx) * im.at<float>(y,x)   + wx * im.at<float>(y,x+1)) +
               (       wy) * ((1.0f - wx) * im.at<float>(y+1,x) + wx * im.at<float>(y+1,x+1));
         } else {
            *out++ = 0;
            ret =  true; // touching boundary of the input            
         }
      }
   }
   return ret;
}

我不知道插值具体是什么,但是看this opencv page , 它似乎是使用 INTER_LINEAR 的双线性插值。关键是我不知道如何为上面的代码调用等效的 opencv 函数。

此函数在两个不同的点被调用 here .

最佳答案

您不能仅使用 openCV 应用简单的插值, 它必须是图像处理操作的一部分,例如变形或调整大小操作。

我认为您正在尝试对扭曲仿射进行矢量化,英特尔平台上最简单和最高效的代码是使用 IPP。 否则,我会让 Opencv Warp 仿射来完成这项工作。

关于c++ - 我可以用 opencv 提供的函数替换这个插值函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43136875/

相关文章:

c++ - 如何在 VC++ 中禁用 Windows TCP/IP 堆栈 [以编程方式]

python - 基于训练集的 OpenCV (Python) 图像分类

3d 数组的 Python 2d 插值

java - OpenCV 作为 JBoss——作为全局模块

python - 使用多个 y 值进行插值

c# - 如何在使用图形类设置插值后保存位图

c++ - 让应用程序拥有 CPU 和 GPU 计算后端的最佳方式是什么

c++ - 如何为 nvcc 添加预定义宏?

c++ - 如何在 OpenCV 中使用 16 位灰度?

opencv - 模板匹配——不同尺寸的模板和图像