正确的空间相机方向

时间:2013-04-24 17:52:50

标签: opencv matrix rotation camera-calibration

我正在执行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()不会旋转图像。

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

1 个答案:

答案 0 :(得分:2)

根据我对主题的理解,您用来“并行化”的旋转矩阵在两个图像平面之间提供旋转。您正在寻找的是从图像平面到相机平面的转换。这需要计算平面之间的单应性。您需要弄清楚从图像平面到相机平面的矩阵。使用此矩阵可以并行化图像。

此外, calibrateCamera 为您提供正向变换,以返回您需要反转矩阵的原始数据。

尝试阅读此内容 - Homography

提示:使用焦距&在图像和图像之间移动的主要点信息相机。