2013-04-24 73 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