【问题标题】:Convert full frame fish eye to equirectangular mathematically以数学方式将全帧鱼眼转换为等距矩形
【发布时间】:2016-12-02 08:17:42
【问题描述】:

我想将全帧鱼眼图像转换为 equirectangular,所以我可以用它来进行全景拼接。为此,我使用了 Hugin 和 libpano,它们运行良好。以下图像已由hugin 转换。我想知道可以实现这种或类似变换的数学方程。

原图

转换后的图像

【问题讨论】:

    标签: opencv image-processing panoramas image-stitching fisheye


    【解决方案1】:

    使用这个link 作为参考,我已经成功地将图像转换为接近生成的一个hugin。它仍然需要亚像素采样以获得更好的图像质量

     #include <iostream>
     #include <sstream>
     #include <time.h>
     #include <stdio.h>
     #include <opencv2/core/core.hpp>
     #include <opencv2/imgproc/imgproc.hpp>
     #include <opencv2/calib3d/calib3d.hpp>
     #include <opencv2/highgui/highgui.hpp>
     using namespace std;
     using namespace cv;
     #define PI 3.1415926536
     Point2f getInputPoint(int x, int y,int srcwidth, int srcheight)
     {
        Point2f pfish;
        float theta,phi,r;
        Point3f psph;
        //float FOV = PI;
        float FOV =(float)PI/180 * 150;
        float FOV2 = (float)PI/180 * 120;;
        float width = srcwidth;
        float height = srcheight;
        theta = PI * (x / width - 0.5); // -pi to pi
        phi = PI * (y / height - 0.5);  // -pi/2 to pi/2
        psph.x = cos(phi) * sin(theta);
        psph.y = cos(phi) * cos(theta);
        psph.z = sin(phi);
        theta = atan2(psph.z,psph.x);
        phi = atan2(sqrt(psph.x*psph.x+psph.z*psph.z),psph.y);
        r = width * phi / FOV;
        float r2 = height * phi / FOV2;
        pfish.x = 0.5 * width + r * cos(theta);
        pfish.y = 0.5 * height + r2 * sin(theta);
        return pfish;
    }
    int main(int argc, char **argv)
    {
        if(argc< 3)
            return 0;
        Mat orignalImage = imread(argv[1]);
        if(orignalImage.empty())
        {
            cout<<"Empty image\n";
            return 0;
        }
        Mat outImage(orignalImage.rows,orignalImage.cols,CV_8UC3);
            //getInputPoint(0,5,10,10);
        namedWindow("result",CV_WINDOW_NORMAL);
        for(int i=0; i<outImage.cols; i++)
        {
            for(int j=0; j<outImage.rows; j++)
            {
    
                Point2f inP =  getInputPoint(i,j,orignalImage.cols,orignalImage.rows);
                //cout<<"in "<<i<<","<<j<<endl;
                //cout<<"out "<<inP.x<<","<<inP.y<<endl;
                Point inP2((int)inP.x,(int)inP.y);
                if(inP2.x >= orignalImage.cols || inP2.y >= orignalImage.rows)
                    continue;
                if(inP2.x < 0 || inP2.y < 0)
                    continue;
                Vec3b color = orignalImage.at<Vec3b>(inP2);
                outImage.at<Vec3b>(Point(i,j)) = color;
    
            }
        }
    
        imshow("result",outImage);
        imwrite(argv[2],outImage);
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-11-21
      • 2011-07-10
      • 2016-12-21
      • 2019-08-05
      • 1970-01-01
      • 2016-02-14
      • 2018-04-03
      • 2014-12-22
      • 1970-01-01
      相关资源
      最近更新 更多