Python 为什么OpenCV认为我在使用非平面校准设备?
我正在玩一个模拟摄影机装备,试图了解OpenCV的calib3d模块是如何工作和执行的 我在3D空间中创建了一组人工对象点,对应于z=50的九个点的平面网格:Python 为什么OpenCV认为我在使用非平面校准设备?,python,opencv,computer-vision,camera-calibration,Python,Opencv,Computer Vision,Camera Calibration,我正在玩一个模拟摄影机装备,试图了解OpenCV的calib3d模块是如何工作和执行的 我在3D空间中创建了一组人工对象点,对应于z=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.arra
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)
使用上述参数投影到图像平面中,图像点如下所示(红色点仅表示方向的左下角):
最后,我尝试检索原始摄像机校准:
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
我的问题不是如何修复这个错误本身,而是为什么首先抛出它?当所有对象点位于同一平面上时,为什么此设置构成非平面装配?我误解了吗?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" );
这意味着设置z而不是0会触发错误。然后必须使用z=0
,除非使用非平面校准目标