2013-04-24 77 views
4

我正在执行OpenCV校准样本中描述的摄像机校准(对镜头校正工作良好)。另外,我现在想要做一个空间校正。当相机与棋盘格不平行时意味着我想获得使棋盘格与相机平行的旋转。这就是我在做什么:正确的空间摄像机方向

// calculate intrinsic matrix and distortion coefficients for lens correction and get 
// the rotation "rotation" 
cvCalibrateCamera2(object_points,image_points,point_counts,cvGetSize(gray_image), 
        intrinsic_matrix, distortion_coeffs, 
        rotation,NULL, 
        0); 
... 
// convert the rotation to a 3x3 matrix 
cv::Rodrigues(rotation,rotMtx,cv::noArray()); 
// generate maps for lens correction 
cv::initUndistortRectifyMap(intrinsic,distortion,cv::Mat(), 
          cv::getOptimalNewCameraMatrix(intrinsic,distortion,imageSize,1,imageSize,0), 
                 imageSize, CV_16SC2,*handle->mapx,*handle->mapy); 
... 
// perform lens correction 
cv::remap(cv::Mat(sImage),dImage,*handle->mapx,*handle->mapy,cv::INTER_LINEAR); 
... 
// apply the rotation to make the mage parallel to the camera 
cv::warpPerspective(dImage,dImage2,rotMtx,cv::Size(handle->width,handle->height),cv::INTER_LANCZOS4,cv::BORDER_TRANSPARENT,cv::Scalar()); 

由cvCalibrateCamera2()返回旋转旋转3X1值= 0,所以返回的东西!但warpPerspective()不旋转图像。

这里有什么问题?我应该如何正确“平行”图像?

回答

2

从我的这个课题的认识,您使用的是旋转矩阵“并行”图像提供两个像平面之间旋转。你正在寻找的是从图像平面到相机平面的转变。这需要计算平面之间的单应性。你需要弄清楚矩阵将你从图像平面转移到相机平面。使用此矩阵来平行化图像。

另外,calibrateCamera为您提供正向转换,回到您需要反转矩阵的原始图像。

尝试阅读本 - Homography

提示:使用焦距&主点信息,图像&相机平面之间移动。

+0

warpPerspective()对于转换没有做任何事情,所以它似乎不是(非)倒置矩阵的问题。 – Elmi 2013-05-06 13:28:46

+0

同样,您不能像使用_Rodrigues_函数调用那样使用'rotMtx'。您需要使用相机的焦距和主要点首先计算3x3 __homography__矩阵。使用此矩阵进行转换。 – Pranjal 2013-05-06 15:04:03

+0

但是... cvCalibrateCamera2()返回了什么样的旋转 - 它可以用于什么? – Elmi 2013-05-06 17:33:59