-1

Original Image

Undistorted image

Scaramuzza omnidirectional camera calibration toolbox has been used to calibrate and save the camera parameters. Then these parameters are used to get the panaromic view from the 180 degree FOV fisheye camera. I have followed the omnidirectional camera calibration tutorial from here. How can I undistort the bottom part of the panaromic image? or how can I undistort some sepcific image points?

Tutul
  • 1
  • 1

1 Answers1

0

Following code can be used to get the undistorted panaroma image:

#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>


void create_panoramic_undistortion_LUT(CvMat* mapx, CvMat* mapy, float Rmin, float 
Rmax, float xc, float yc)
{
int i, j;
float theta;
int width = mapx->width;
int height = mapx->height;
float* data_mapx = mapx->data.fl;
float* data_mapy = mapy->data.fl;
float rho;

for (i = 0; i < height; i++)
    for (j = 0; j < width; j++)
    {
        theta = -((float)j) / width * 2 * 3.1416; // Note, if you would like to flip 
the image, just inverte the sign of theta
        rho = Rmax - (Rmax - Rmin) / height * i;
        *(data_mapx + i * width + j) = yc + rho * sin(theta); //in OpenCV "x" is the
        *(data_mapy + i * width + j) = xc + rho * cos(theta);
    }
}


int main() {


IplImage* src1 = cvLoadImage("test_catadioptric6.jpg");
CvSize size_pan_image = cvSize(1100, 400);        // size of the undistorted 
panoramic image
IplImage* dst_pan = cvCreateImage(size_pan_image, 8, 3);    // undistorted panoramic 
image
CvMat* mapx_pan = cvCreateMat(dst_pan->height, dst_pan->width, CV_32FC1);
CvMat* mapy_pan = cvCreateMat(dst_pan->height, dst_pan->width, CV_32FC1);
float Rmax = 920;  // the maximum radius of the region you would like to undistort 
into a panorama
float Rmin = 150;
float xc = 959;
float yc = 959;
create_panoramic_undistortion_LUT(mapx_pan, mapy_pan, Rmin, Rmax, xc, yc);

cvRemap(src1, dst_pan, mapx_pan, mapy_pan, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, 
cvScalarAll(0));
CvSize size_pan = cvSize(800, 800);
IplImage* dst = cvCreateImage(size_pan, 8, 3);

cvResize(src1, dst, CV_INTER_LINEAR);


cvNamedWindow("Original Catadioptric camera image", 1);
cvShowImage("Original Catadioptric camera image", dst);
cvNamedWindow("Undistorted Panoramic Image", 1);
cvShowImage("Undistorted Panoramic Image", dst_pan);
cvWaitKey();
cvReleaseImage(&src1);
cvReleaseImage(&dst_pan);
cvReleaseMat(&mapx_pan);
cvReleaseMat(&mapy_pan);
return 0;

};

undistorted panaroma

Tutul
  • 1
  • 1
  • Why are you using OpenCV's C API? It's been deprecated for nearly a decade now. If you're writing new code, you should be using the C++ API all the way. – beaker Feb 26 '19 at 23:46