英文:
how to estimate pose of single marker in opencv-python 4.8.0?
问题
根据这个问题中显示的内容,aruco包的API发生了变化。
我按照被接受的答案成功地检测到了标记并使用drawDetectedMarkers进行了绘制,但是我在cv2.aruco和cv2.aruco.detector属性中找不到'estimatePoseSingleMarkers'。
仍然收到错误消息:
module 'cv2.aruco' has no attribute 'estimatePoseSingleMarkers'
或者
'cv2.aruco.ArucoDetector' object has no attribute 'estimatePoseSingleMarkers'
英文:
As shown in this Question There are API change for aruco package.
I managed to detect the markers and drawDetectedMarkers by following accepted answer but I can't find 'estimatePoseSingleMarkers' in both cv2.aruco and cv2.aruco.detector attributes.
still got error message
module 'cv2.aruco' has no attribute 'estimatePoseSingleMarkers'
or
'cv2.aruco.ArucoDetector' object has no attribute 'estimatePoseSingleMarkers'
答案1
得分: 0
根据Christoph Rackwitz的评论,当我在搜索使用aruco标记解决solvePnP问题时,我找到了这个答案。
estimatePoseSingleMarkers在版本4.7中已经不存在了。在这里,我使用SolvePnP函数替换了这个函数:
def my_estimatePoseSingleMarkers(corners, marker_size, mtx, distortion):
'''
This will estimate the rvec and tvec for each of the marker corners detected by:
corners, ids, rejectedImgPoints = detector.detectMarkers(image)
corners - is an array of detected corners for each detected marker in the image
marker_size - is the size of the detected markers
mtx - is the camera matrix
distortion - is the camera distortion matrix
RETURN list of rvecs, tvecs, and trash (so that it corresponds to the old estimatePoseSingleMarkers())
'''
marker_points = np.array([[-marker_size / 2, marker_size / 2, 0],
[marker_size / 2, marker_size / 2, 0],
[marker_size / 2, -marker_size / 2, 0],
[-marker_size / 2, -marker_size / 2, 0]], dtype=np.float32)
trash = []
rvecs = []
tvecs = []
for c in corners:
nada, R, t = cv2.solvePnP(marker_points, c, mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
rvecs.append(R)
tvecs.append(t)
trash.append(nada)
return rvecs, tvecs, trash
如果有人遇到这个问题,我在我的GitHub上编写了一个示例脚本。
https://github.com/Menginventor/aruco_example_cv_4.8.0
英文:
Based on Christoph Rackwitz comment as i searching for solvePnP with aruco tag, I found this Answer
estimatePoseSingleMarkers no longer exists as of version 4.7. Here, I replaced the function for you using SolvePnP:
def my_estimatePoseSingleMarkers(corners, marker_size, mtx, distortion):
'''
This will estimate the rvec and tvec for each of the marker corners detected by:
corners, ids, rejectedImgPoints = detector.detectMarkers(image)
corners - is an array of detected corners for each detected marker in the image
marker_size - is the size of the detected markers
mtx - is the camera matrix
distortion - is the camera distortion matrix
RETURN list of rvecs, tvecs, and trash (so that it corresponds to the old estimatePoseSingleMarkers())
'''
marker_points = np.array([[-marker_size / 2, marker_size / 2, 0],
[marker_size / 2, marker_size / 2, 0],
[marker_size / 2, -marker_size / 2, 0],
[-marker_size / 2, -marker_size / 2, 0]], dtype=np.float32)
trash = []
rvecs = []
tvecs = []
for c in corners:
nada, R, t = cv2.solvePnP(marker_points, c, mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
rvecs.append(R)
tvecs.append(t)
trash.append(nada)
return rvecs, tvecs, trash
if anyone have this problem,I've wrote example script in my github.
https://github.com/Menginventor/aruco_example_cv_4.8.0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论