如何在OpenCV-Python 4.8.0中估计单个标记的姿态?

huangapple go评论142阅读模式
英文:

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函数替换了这个函数:

  1. def my_estimatePoseSingleMarkers(corners, marker_size, mtx, distortion):
  2. '''
  3. This will estimate the rvec and tvec for each of the marker corners detected by:
  4. corners, ids, rejectedImgPoints = detector.detectMarkers(image)
  5. corners - is an array of detected corners for each detected marker in the image
  6. marker_size - is the size of the detected markers
  7. mtx - is the camera matrix
  8. distortion - is the camera distortion matrix
  9. RETURN list of rvecs, tvecs, and trash (so that it corresponds to the old estimatePoseSingleMarkers())
  10. '''
  11. marker_points = np.array([[-marker_size / 2, marker_size / 2, 0],
  12. [marker_size / 2, marker_size / 2, 0],
  13. [marker_size / 2, -marker_size / 2, 0],
  14. [-marker_size / 2, -marker_size / 2, 0]], dtype=np.float32)
  15. trash = []
  16. rvecs = []
  17. tvecs = []
  18. for c in corners:
  19. nada, R, t = cv2.solvePnP(marker_points, c, mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
  20. rvecs.append(R)
  21. tvecs.append(t)
  22. trash.append(nada)
  23. 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:

  1. def my_estimatePoseSingleMarkers(corners, marker_size, mtx, distortion):
  2. '''
  3. This will estimate the rvec and tvec for each of the marker corners detected by:
  4. corners, ids, rejectedImgPoints = detector.detectMarkers(image)
  5. corners - is an array of detected corners for each detected marker in the image
  6. marker_size - is the size of the detected markers
  7. mtx - is the camera matrix
  8. distortion - is the camera distortion matrix
  9. RETURN list of rvecs, tvecs, and trash (so that it corresponds to the old estimatePoseSingleMarkers())
  10. '''
  11. marker_points = np.array([[-marker_size / 2, marker_size / 2, 0],
  12. [marker_size / 2, marker_size / 2, 0],
  13. [marker_size / 2, -marker_size / 2, 0],
  14. [-marker_size / 2, -marker_size / 2, 0]], dtype=np.float32)
  15. trash = []
  16. rvecs = []
  17. tvecs = []
  18. for c in corners:
  19. nada, R, t = cv2.solvePnP(marker_points, c, mtx, distortion, False, cv2.SOLVEPNP_IPPE_SQUARE)
  20. rvecs.append(R)
  21. tvecs.append(t)
  22. trash.append(nada)
  23. 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

huangapple
  • 本文由 发表于 2023年7月31日 18:06:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76802576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定