gpt4 book ai didi

python - OpenCV立体相机标定错误: Assertion failed

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:22 25 4
gpt4 key购买 nike

我知道这个问题被问过几次,但答案并没有解决我的问题。

我想校准一对相机以用作立体输入。但是当我运行代码时,我收到错误消息:

OpenCV(3.4.1) Error: Assertion failed (nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total())) in collectCalibrationData, file /tmp/opencv-20180529-49540-yj8rbk/opencv-3.4.1/modules/calib3d/src/calibration.cpp, line 3133
Traceback (most recent call last):
File "/Users/MyName/Pycharm/Project/calibration.py", line 342, in <module>
TERMINATION_CRITERIA )
cv2.error: OpenCV(3.4.1) /tmp/opencv-20180529-49540-yj8rbk/opencv-3.4.1/modules/calib3d/src/calibration.cpp:3133: error: (-215) nimages > 0 && nimages == (int)imagePoints1.total() && (!imgPtMat2 || nimages == (int)imagePoints2.total()) in function collectCalibrationData
我的代码是:

def distortion_matrix(path, objpoints, imgpoints):

for item in os.listdir(path):
if item.endswith(".jpg"):
cap = cv2.VideoCapture(path+item, cv2.CAP_IMAGES)

ret, img = cap.read() # Capture frame-by-frame

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

keypoints = blobDetector.detect(gray) # Detect blobs.

im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0, 255, 0),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
im_with_keypoints_gray = cv2.cvtColor(im_with_keypoints, cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findCirclesGrid(im_with_keypoints, (4, 11), None,
flags=cv2.CALIB_CB_ASYMMETRIC_GRID)

if ret == True:
objpoints.append(objp)

corners2 = cv2.cornerSubPix(im_with_keypoints_gray, corners, (11, 11), (-1, -1),
criteria)
imgpoints.append(corners2)


cap.release()

_, leftCameraMatrix, leftDistortionCoefficients, _, _ , objpoints0, imgpoints0 = distortion_matrix("./calibration/left/", objpoints0, imgpoints0)
_, rightCameraMatrix, rightDistortionCoefficients, _, _, objpoints1, imgpoints1 = distortion_matrix("./calibration/right/", objpoints1, imgpoints1)



(_, _, _, _, _, rotationMatrix, translationVector, _, _) = cv2.stereoCalibrate( objp, imgpoints0, imgpoints1,
leftCameraMatrix, leftDistortionCoefficients,
rightCameraMatrix, rightDistortionCoefficients,
imageSize, None, None, None, None,
cv2.CALIB_FIX_INTRINSIC, TERMINATION_CRITERIA )

大多数时候抛出这个问题时,消息似乎指的是空的或未均匀填充的数组(imgpoint 和 objpoint)。但最后两者的长度都是 20(我扫描了 20 张图像,所以这似乎是正确的)并且数组的每个单元格都存储了 44 个数组(我使用的圆形网格有 44 个点,所以这似乎也是正确的)。

**编辑:**我的 objp、imgpoint 和 objpoint 定义如下:

objp = np.zeros((np.prod(pattern_size), 3), np.float32)
objp[0] = (0, 0, 0)
objp[1] = (0, 2, 0)
objp[2] = (0, 4, 0)
objp[3] = (0, 6, 0)
...


objpoints0 = []
objpoints1 = []

imgpoints0 = []
imgpoints1 = []

** 编辑 2:**

如果 NUM_IMAGES 代表图像数量,我想我现在已经知道了。但只有当我在调用 distortion_matrix() 后添加新轴时.然后代码就可以完成了。我需要测试结果,但至少这个问题似乎已经解决了。

非常感谢

最佳答案

你说你在做立体校准,有没有其他相机看不到你网格上的一些点的情况?当您的其中一个 View 无法检测到校准图案上的所有点时,可能会出现此错误。需要考虑的三点是
1- 确保你的对象点是 3d
2- 确保您的左点、右点和对象点具有相同的大小( View 数)。
3-确保您的左点、右点和对象点在列表的每个索引处具有相同数量的点。

编辑:你的对象点 objp 必须包含 3d 点的列表/向量,目前它的形状类似于 (44, 3),它必须是 (NUM_IMAGES, 44, 3)。您可以使用 objp = np.repeat(objp[np.newaxis, :, :], NUM_IMAGES, axis=0)

关于python - OpenCV立体相机标定错误: Assertion failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52245570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com