2015-07-12 29 views
3

我正在玩模擬攝像機,試圖瞭解OpenCV的calib3d模塊如何工作和執行。爲什麼OpenCV認爲我使用的是非平面校準裝備?

我創建在三維空間中對應於z與9點的平格柵的人工組目標點= 50:

obj_pts = np.zeros((9, 3), dtype='float32') 
obj_pts[0] = np.array([40, 40, 50], dtype='float32') 
obj_pts[1] = np.array([50, 40, 50], dtype='float32') 
obj_pts[2] = np.array([60, 40, 50], dtype='float32') 
obj_pts[3] = np.array([40, 50, 50], dtype='float32') 
obj_pts[4] = np.array([50, 50, 50], dtype='float32') 
obj_pts[5] = np.array([60, 50, 50], dtype='float32') 
obj_pts[6] = np.array([40, 60, 50], dtype='float32') 
obj_pts[7] = np.array([50, 60, 50], dtype='float32') 
obj_pts[8] = np.array([60, 60, 50], dtype='float32') 

我所然後創建人工照相機後使用cv2.projectPoints()成像:

rvec = (0, 0, 0) # rotation relative to the frame 
tvec = (0, 0, 0) # translation relative to the frame 
distCoeffs = (0, 0, 0, 0) 
cameraMatrix = np.zeros((3, 3)) 
focalLength = 50 
cx = 0 
cy = 0 
setupCameraMatrix(cameraMatrix, focalLength, cx, cy) # my own routine 

img_pts, jacobian = cv2.projectPoints(obj_pts, rvec, tvec, cameraMatrix, distCoeffs) 

使用上面的參數投射到圖像平面,圖像點是這樣的(紅點只是指示方向左下角):

Plot of the artificial image points projected into image plane

最後我試圖找回原來的攝像機標定:

obj_pts_list = [obj_pts] 
img_pts_list = [img_pts] 
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_pts_list, img_pts_list, (200, 200), None, None) 

然而,這最後一步給出了這樣的錯誤:

OpenCV Error: Bad argument (For non-planar calibration rigs the initial intrinsic matrix must be specified) in cvCalibrateCamera2, file /tmp/opencv20150527-4924-hjrvz/opencv-2.4.11/modules/calib3d/src/calibration.cpp, line 1592 

我的問題不是如何修正這個錯誤本身 - 而是爲什麼它首先被拋出?爲什麼當所有對象點位於同一平面內時,此設置將構成非平面鑽機?我誤解了嗎?

回答

0

OpenCV預計z = 0平面校準目標的情況。

尋找到代碼,OpenCV檢查該值如下:

Scalar mean, sdv; 
meanStdDev(matM, mean, sdv); 
if(fabs(mean[2]) > 1e-5 || fabs(sdv[2]) > 1e-5) 
     CV_Error(CV_StsBadArg, 
"For non-planar calibration rigs the initial intrinsic matrix must be specified"); 

這意味着比0設置步驟Z其他觸發錯誤。除非使用非平面校準目標,否則必須使用z = 0