所有,
我有一个使用OpenCV校准相机的python脚本。现在,它可以从stackoverflow帮助中获得很多帮助。但是,我在失真常数方面遇到了问题。我似乎无法控制常数适合的数量。我只需要4个distoriton常数,而不是5个。在文档中它声明“也就是说,如果 vector 包含四个元素,则意味着K3 = 0”,这就是我想要的。因此,我启动了dist_const = np.zeros(4),并将其传递给cv2.calibrateCamera,但是返回的dist_const有5个常量返回。我也尝试过标志CV_CALIB_FIX_K3,但始终收到“必须分配iteger”错误。有没有人看过这种行为,将不胜感激。
import cv2
from cv2 import cv
import numpy as np
obj_points = [[-9.7,3.0,4.5],[-11.1,0.5,3.1],[-8.5,0.9,2.4],[-5.8,4.4,2.7],[-4.8,1.5,0.2],[-6.7,-1.6,-0.4],[-8.7,-3.3,-0.6],[-4.3,-1.2,-2.4],[-12.4,-2.3,0.9],[-14.1,-3.8,-0.6],[-18.9,2.9,2.9],[-14.6,2.3,4.6],[-16.0,0.8,3.0],[-18.9,-0.1,0.3],[-16.3,-1.7,0.5],[-18.6,-2.7,-2.2]]
img_points = [[993.0,623.0],[942.0,705.0],[1023.0,720.0],[1116.0,645.0],[1136.0,764.0],[1071.0,847.0],[1003.0,885.0],[1142.0,887.0],[886.0,816.0],[827.0,883.0],[710.0,636.0],[837.0,621.0],[789.0,688.0],[699.0,759.0],[768.0,800.0],[697.0,873.0]]
obj_points = np.array(obj_points,'float32')
img_points = np.array(img_points,'float32')
w = 1680
h = 1050
size = (w,h)
camera_matrix = np.zeros((3,3),'float32')
camera_matrix[0,0]= 2200.0
camera_matrix[1,1]= 2200.0
camera_matrix[2,2]=1.0
camera_matrix[0,2]=750.0
camera_matrix[1,2]=750.0
dist_coefs = np.zeros(4,'float32')
retval,camera_matrix,dist_coefs,rvecs,tvecs = cv2.calibrateCamera([obj_points],[img_points],size,camera_matrix,dist_coefs,flags=cv.CV_CALIB_USE_INTRINSIC_GUESS)
print camera_matrix
print dist_coefs
我试图用python / opencv替换的caltech matlab代码链接到我的另一个问题,得到了dist_coefs的结果。
约翰
最佳答案
将您的calibrateCamera调用更改为:
retval,camera_matrix,dist_coefs,rvecs,tvecs = cv2.calibrateCamera([obj_points],[img_points],size,camera_matrix,dist_coefs,flags=cv2.CALIB_USE_INTRINSIC_GUESS + cv2.CALIB_FIX_K3)
您不希望我像在示例中那样混合使用cv2和cv namespace 。
关于python - OpenCV摄像机校准,无法控制失真常数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10144522/