Scaramuzza全向摄像机校准工具箱已用于校准和保存摄像机参数。然后使用这些参数从180度FOV鱼眼镜头获取全景视图。我遵循了here中的全向相机校准教程。如何使全景图像的底部变形?或如何使某些分离的图像点失真?
答案 0 :(得分:0)
以下代码可用于获取未失真的全景图像:
#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;
};