如何解决OpenCV立体声使用ChArUco校准两个摄像机
我想使用charuco board的多个帧来计算两个摄像机之间的相对转换([R | t]矩阵)。我的想法是从所有帧中获取图像对象点对,然后使用一个函数,该函数获取所有检测到的点对并输出相机之间的相对变换(例如stereoCalibrate)。
做到这一点的最佳方法是什么?我无法使stereoCalibrate工作,因为它总是会引发断言错误-> bugreport。
当前实施(无效)
imagePointsA = []
imagePointsB = []
objectPoints = []
for frameA,frameB in color_framesets(...):
try:
# Find corners
cornersA,idsA,rejected = cv2.aruco.detectMarkers(frameA,charucoDict)
cornersB,idsB,rejected = cv2.aruco.detectMarkers(frameB,charucoDict)
if not cornersA or not cornersB: raise Exception("No markers detected")
retA,cornersA,idsA = cv2.aruco.interpolateCornersCharuco(cornersA,frameA,charucoBoard)
retB,cornersB,idsB = cv2.aruco.interpolateCornersCharuco(cornersB,frameB,charucoBoard)
if not retA or not retB: raise Exception("Can't interpolate corners")
# Find common points in both frames (is there a nicer way?)
objPtsA,imgPtsA = cv2.aruco.getBoardobjectAndImagePoints(charucoBoard,idsA)
objPtsB,imgPtsB = cv2.aruco.getBoardobjectAndImagePoints(charucoBoard,idsB)
# Create dictionary for each frame objectPoint:imagePoint
ptsA = {tuple(a):tuple(b) for a,b in zip(objPtsA[:,0],imgPtsA[:,0])}
ptsB = {tuple(a):tuple(b) for a,b in zip(objPtsB[:,imgPtsB[:,0])}
common = set(ptsA.keys()) & set(ptsB.keys()) # intersection between obj points
for objP in common:
objectPoints.append(np.reshape(objP,(1,3)))
imagePointsA.append(np.reshape(ptsA[objP],2)))
imagePointsB.append(np.reshape(ptsB[objP],2)))
except Exception as e:
print(f"Skipped frame: {e}")
continue
result = cv2.stereoCalibrateExtended(objectPoints,imagePointsA,imagePointsB,intrA,distA,intrB,distB,(848,480),flags=cv2.CALIB_FIX_INTRINSIC+cv2.CALIB_USE_EXTRINSIC_GUESS)
解决方法
我今天早些时候刚刚做了类似的事情。我假设您至少解决了部分问题,因为您关闭了提到的错误。无论如何,在我看来,问题在于您正在传递一个点数组,而它应该是一个点数组数组(具有足够数据的每一帧的点数组)。
在相关说明中,cv2.aruco.getBoardObjectAndImagePoints
可能不是您要找的,cornersA
和 cornersB
已经是图像点(棋盘图案角)和对象点(位置棋盘图案角)可从 aruco 标记 id 计算,而 getBoardObjectAndImagePoints
是关于 aruco 标记角,据我所知。
在内部,cv2.aruco.calibrateCameraCharuco
只是简单地调用 cv2.calibrateCamera
,将传递的角点作为图像点,对象点为 computed from the passed aruco IDs。不幸的是,从 aruco ID 获取对象点并未在 API 中公开,但计算起来非常容易:https://github.com/opencv/opencv_contrib/blob/master/modules/aruco/src/charuco.cpp#L157-L166
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。