【问题标题】:How to do a non-linear perspective stretch with OpenCV?如何使用 OpenCV 进行非线性透视拉伸?
【发布时间】:2019-01-31 22:54:36
【问题描述】:

我需要执行一种图像拉伸,在顶部缩小,在底部放大。我不会像 warpPerspective 那样丢失部分图像。 OpenCV 有这种功能吗?

original image

desired result

【问题讨论】:

    标签: opencv perspective stretch


    【解决方案1】:

    我找到了一种使用remap 函数并使用指数函数重新映射每个像素的方法:

       cv::Mat mapX, mapY;
       mapX.create(m_nRemapHeight, m_nRemapWidth, CV_32FC1);
       mapY.create(m_nRemapHeight, m_nRemapWidth, CV_32FC1);
    
       for (int j = 0; j < m_nRemapHeight; j++)
       {
          for (int i = 0; i < m_nRemapWidth; i++)
          {
             mapX.at<float>(j, i) = (float)i;
             float t = (m_nRemapHeight * 0.5f);    
             float r = j + t;
             float fVal = ((r*r) / (m_nRemapHeight + t * 2));
             fVal -= ((t*t) / (m_nRemapHeight + t * 2));
             mapY.at<float>(j, i) = fVal;
          }
       }
       cv::remap(srcMat, dstMat, matX, matY, CV_INTER_LINEAR, 0);
    

    【讨论】:

      猜你喜欢
      • 2011-06-27
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 2014-05-04
      • 1970-01-01
      • 2014-12-20
      相关资源
      最近更新 更多