不使用 cv2.findChessboardCorners Python 中的 OpenCV 相机校准
OpenCV camera calibration in Python without using cv2.findChessboardCorners
我正在尝试使用 openCV 进行相机校准。只要我使用 cv2.findChessBoardCorners 在图像中找到我的校准目标,我就没有问题,但是如果我使用我自己的函数找到这些点并用这些点构建一个数组,我会得到一个错误试图估计相机参数。这是一个将引发相同错误的示例。
import numpy as np
import cv2
pattern_size = (4, 3)
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2)
pattern_points *= 20
obj_points = []
img_points = []
for fn in range(5):
corners = np.asarray(pattern_points[:,1:], dtype=np.float32)
img_points.append(corners.reshape(-1, 2))
obj_points.append(pattern_points)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_points,
img_points,
(1088, 2048),
None,
None)
如果我改为使用通常的角数组
ret, corners = cv2.findChessboardCorners(gray, (4,3))
它工作正常。在这两种情况下,角的类型都是 ndarray 大小 (12,2),元素是 float32。
为什么会出现此错误:
OpenCV Error: Unsupported format or combination of formats (imagePoints1 should contain vector of vectors of points of type Point2f) in cv::collectCalibrationData, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\calib3d\src\calibration.cpp, line 2982
当我尝试从头开始构建 img_points 数组而不是使用 cv2.findChessboardCorners?
我也遇到了同样的问题。如文档所述,我通过使用向量的向量解决了它;对于每一帧,
imPts = [ [px0, py0, pz0],..., [pxn, pyn, pzn] ]
、和
obPts = [ [qx0, qy0],..., [qxn, qyn] ]
,然后执行:imPts.astype('float32')
和 obPts.astype('float32')
,当在函数内部使用它们时。如果使用多个帧,则对每个帧执行此操作。这就是诀窍。
我正在尝试使用 openCV 进行相机校准。只要我使用 cv2.findChessBoardCorners 在图像中找到我的校准目标,我就没有问题,但是如果我使用我自己的函数找到这些点并用这些点构建一个数组,我会得到一个错误试图估计相机参数。这是一个将引发相同错误的示例。
import numpy as np
import cv2
pattern_size = (4, 3)
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2)
pattern_points *= 20
obj_points = []
img_points = []
for fn in range(5):
corners = np.asarray(pattern_points[:,1:], dtype=np.float32)
img_points.append(corners.reshape(-1, 2))
obj_points.append(pattern_points)
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(obj_points,
img_points,
(1088, 2048),
None,
None)
如果我改为使用通常的角数组
ret, corners = cv2.findChessboardCorners(gray, (4,3))
它工作正常。在这两种情况下,角的类型都是 ndarray 大小 (12,2),元素是 float32。
为什么会出现此错误:
OpenCV Error: Unsupported format or combination of formats (imagePoints1 should contain vector of vectors of points of type Point2f) in cv::collectCalibrationData, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\calib3d\src\calibration.cpp, line 2982
当我尝试从头开始构建 img_points 数组而不是使用 cv2.findChessboardCorners?
我也遇到了同样的问题。如文档所述,我通过使用向量的向量解决了它;对于每一帧,
imPts = [ [px0, py0, pz0],..., [pxn, pyn, pzn] ]
、和
obPts = [ [qx0, qy0],..., [qxn, qyn] ]
,然后执行:imPts.astype('float32')
和 obPts.astype('float32')
,当在函数内部使用它们时。如果使用多个帧,则对每个帧执行此操作。这就是诀窍。