attributeError:模块' cv2.aruco'没有属性' drawframeaxes'

发布于 2025-02-09 20:31:59 字数 553 浏览 2 评论 0原文

我正在使用VSCODE 1.68.1,Ubuntu 20.04 我正在关注链接( https> https:// 。

​ Aruco.DrawFrameAxes(DST1,MTX,DIST,RVEC [i,:,:],tvec [i,:,:,:],0.03) attributeError:模块'cv2.aruco'没有属性'drawframeaxes'

  • 我尝试使用aruco.drawaxis,同样的错误
  • 还尝试卸载opencv-python,卸载opencv-contrib-python,然后卸载opencv-contrib-python,然后启用pip3安装opencv-python&amp& amp; amp; amp; amp; pip3安装opencv-contrib-python,同样的错误

I am working with VSCode 1.68.1, Ubuntu 20.04
I am following link (https://programming.vip/docs/3d-pose-estimation-using-aruco-tag-in-python.html) to achieve pose estimation for aruco marker

But I am getting below error:
aruco.drawFrameAxes(dst1, mtx, dist, rvec[i, :, :], tvec[i, :, :],0.03)
AttributeError: module 'cv2.aruco' has no attribute 'drawFrameAxes'

  • I tried using aruco.drawaxis as well, same error
  • Also tried uninstall opencv-python, uninstall opencv-contrib-python, then pip3 install opencv-python & pip3 install opencv-contrib-python, same error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

莫言歌 2025-02-16 20:31:59

drawframeaxes是OPENCV中可用的独立模块。它在aruco软件包中找不到。

命令:help(cv2.drawframeaxes)为您提供有关其用法和参数所需的所有详细信息。

在代码中尝试以下内容:

result_img = cv2.drawFrameAxes(dst1, mtx, dist, rvec[i, :, :], tvec[i, :, :],0.03)

drawFrameAxes is an independent module available in OpenCV. It isn't found within aruco package.

The command: help(cv2.drawFrameAxes) gives you all the details you need regarding its usage and parameters.

Try the following in your code:

result_img = cv2.drawFrameAxes(dst1, mtx, dist, rvec[i, :, :], tvec[i, :, :],0.03)

Documentation Link

笑咖 2025-02-16 20:31:59

您是否尝试过从源来编译OpenCV?我是出于绝望而做到的,此后的功能似乎起作用了。

我也无法使用替代性贡献 - opencv-python软件包。

Did you try compiling opencv from source? I did this out of desperation and the function seemed to work afterwards.

I was not able to get this working with the alternative contrib-opencv-python package either.

向日葵 2025-02-16 20:31:59
cv2.drawFrameAxes(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01) 

我在GitHub页面上将更新的代码上传到Python。
(github -ritabrata -chakraborty/aruco)

cv2.drawFrameAxes(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01) 

I have uploaded the updated code in python on my github page.
(GitHub - Ritabrata-Chakraborty/ArUco)

眼前雾蒙蒙 2025-02-16 20:31:59
"""hello.
this code is runing, 
versions:
Python==3.11.1
opencv-contrib-python==4.9.0.80
opencv-python==4.9.0.80
in this case we have this aruco of 7x7 "DICT_7X7_100" but you can change to "DICT_5X5_100", you must to change in 3 lines of this program"""

生成Aruco图像:
https://chev.me/arucogen/

import numpy as np
import cv2
import sys
import time

ARUCO_DICT = {
    "DICT_4X4_50": cv2.aruco.DICT_4X4_50,
    "DICT_4X4_100": cv2.aruco.DICT_4X4_100,
    "DICT_4X4_250": cv2.aruco.DICT_4X4_250,
    "DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
    "DICT_5X5_50": cv2.aruco.DICT_5X5_50,
    "DICT_5X5_100": cv2.aruco.DICT_5X5_100,
    "DICT_5X5_250": cv2.aruco.DICT_5X5_250,
    "DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
    "DICT_6X6_50": cv2.aruco.DICT_6X6_50,
    "DICT_6X6_100": cv2.aruco.DICT_6X6_100,
    "DICT_6X6_250": cv2.aruco.DICT_6X6_250,
    "DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
    "DICT_7X7_50": cv2.aruco.DICT_7X7_50,
    "DICT_7X7_100": cv2.aruco.DICT_7X7_100,
    "DICT_7X7_250": cv2.aruco.DICT_7X7_250,
    "DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
    "DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
    "DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
    "DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
    "DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
    "DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11
}

def aruco_display(corners, ids, rejected, image):    
    if len(corners) > 0:        
        ids = ids.flatten()     
        for (markerCorner, markerID) in zip(corners, ids):          
            corners = markerCorner.reshape((4, 2))
            (topLeft, topRight, bottomRight, bottomLeft) = corners
            
            topRight = (int(topRight[0]), int(topRight[1]))
            bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
            bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
            topLeft = (int(topLeft[0]), int(topLeft[1]))

            cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
            cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
            cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
            cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)
            
            cX = int((topLeft[0] + bottomRight[0]) / 2.0)
            cY = int((topLeft[1] + bottomRight[1]) / 2.0)
            cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)
            
            cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX,
                0.5, (0, 255, 0), 2)
            print("[Inference] ArUco marker ID: {}".format(markerID))           
    return image

def pose_estimation(frame, aruco_dict_type, matrix_coefficients, distortion_coefficients):
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow("gray", gray)
    dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_7X7_100) # cv2.aruco.DICT_4X4_250 seleccion del modelo Aruco
    parameters =  cv2.aruco.DetectorParameters()
    detector = cv2.aruco.ArucoDetector(dictionary, parameters)
    corners, ids, rejected_img_points = detector.detectMarkers(gray)
        
    if len(corners) > 0:
        for i in range(0, len(ids)):           
            rvec, tvec, markerPoints = cv2.aruco.estimatePoseSingleMarkers(corners[i], 0.02, matrix_coefficients, distortion_coefficients)
            cv2.aruco.drawDetectedMarkers(frame, corners) 
            cv2.drawFrameAxes(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01)  
    return frame

aruco_type = "DICT_7X7_100"
arucoDict = cv2.aruco.DICT_7X7_100
arucoParams = cv2.aruco.DetectorParameters()

intrinsic_camera = np.array(((933.15867, 0, 657.59),(0,933.1586, 400.36993),(0,0,1)))
distortion = np.array((-0.43948,0.18514,0,0))

cap = cv2.VideoCapture(0)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while cap.isOpened():    
    ret, img = cap.read()    
    output = pose_estimation(img, ARUCO_DICT[aruco_type], intrinsic_camera, distortion)
    cv2.imshow('Estimated Pose', output)

    key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
        break

cap.release()

cv2.destroyAllWindows()
"""hello.
this code is runing, 
versions:
Python==3.11.1
opencv-contrib-python==4.9.0.80
opencv-python==4.9.0.80
in this case we have this aruco of 7x7 "DICT_7X7_100" but you can change to "DICT_5X5_100", you must to change in 3 lines of this program"""

to generate Aruco images:
https://chev.me/arucogen/

import numpy as np
import cv2
import sys
import time

ARUCO_DICT = {
    "DICT_4X4_50": cv2.aruco.DICT_4X4_50,
    "DICT_4X4_100": cv2.aruco.DICT_4X4_100,
    "DICT_4X4_250": cv2.aruco.DICT_4X4_250,
    "DICT_4X4_1000": cv2.aruco.DICT_4X4_1000,
    "DICT_5X5_50": cv2.aruco.DICT_5X5_50,
    "DICT_5X5_100": cv2.aruco.DICT_5X5_100,
    "DICT_5X5_250": cv2.aruco.DICT_5X5_250,
    "DICT_5X5_1000": cv2.aruco.DICT_5X5_1000,
    "DICT_6X6_50": cv2.aruco.DICT_6X6_50,
    "DICT_6X6_100": cv2.aruco.DICT_6X6_100,
    "DICT_6X6_250": cv2.aruco.DICT_6X6_250,
    "DICT_6X6_1000": cv2.aruco.DICT_6X6_1000,
    "DICT_7X7_50": cv2.aruco.DICT_7X7_50,
    "DICT_7X7_100": cv2.aruco.DICT_7X7_100,
    "DICT_7X7_250": cv2.aruco.DICT_7X7_250,
    "DICT_7X7_1000": cv2.aruco.DICT_7X7_1000,
    "DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL,
    "DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5,
    "DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9,
    "DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10,
    "DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11
}

def aruco_display(corners, ids, rejected, image):    
    if len(corners) > 0:        
        ids = ids.flatten()     
        for (markerCorner, markerID) in zip(corners, ids):          
            corners = markerCorner.reshape((4, 2))
            (topLeft, topRight, bottomRight, bottomLeft) = corners
            
            topRight = (int(topRight[0]), int(topRight[1]))
            bottomRight = (int(bottomRight[0]), int(bottomRight[1]))
            bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1]))
            topLeft = (int(topLeft[0]), int(topLeft[1]))

            cv2.line(image, topLeft, topRight, (0, 255, 0), 2)
            cv2.line(image, topRight, bottomRight, (0, 255, 0), 2)
            cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2)
            cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2)
            
            cX = int((topLeft[0] + bottomRight[0]) / 2.0)
            cY = int((topLeft[1] + bottomRight[1]) / 2.0)
            cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1)
            
            cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX,
                0.5, (0, 255, 0), 2)
            print("[Inference] ArUco marker ID: {}".format(markerID))           
    return image

def pose_estimation(frame, aruco_dict_type, matrix_coefficients, distortion_coefficients):
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow("gray", gray)
    dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_7X7_100) # cv2.aruco.DICT_4X4_250 seleccion del modelo Aruco
    parameters =  cv2.aruco.DetectorParameters()
    detector = cv2.aruco.ArucoDetector(dictionary, parameters)
    corners, ids, rejected_img_points = detector.detectMarkers(gray)
        
    if len(corners) > 0:
        for i in range(0, len(ids)):           
            rvec, tvec, markerPoints = cv2.aruco.estimatePoseSingleMarkers(corners[i], 0.02, matrix_coefficients, distortion_coefficients)
            cv2.aruco.drawDetectedMarkers(frame, corners) 
            cv2.drawFrameAxes(frame, matrix_coefficients, distortion_coefficients, rvec, tvec, 0.01)  
    return frame

aruco_type = "DICT_7X7_100"
arucoDict = cv2.aruco.DICT_7X7_100
arucoParams = cv2.aruco.DetectorParameters()

intrinsic_camera = np.array(((933.15867, 0, 657.59),(0,933.1586, 400.36993),(0,0,1)))
distortion = np.array((-0.43948,0.18514,0,0))

cap = cv2.VideoCapture(0)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while cap.isOpened():    
    ret, img = cap.read()    
    output = pose_estimation(img, ARUCO_DICT[aruco_type], intrinsic_camera, distortion)
    cv2.imshow('Estimated Pose', output)

    key = cv2.waitKey(1) & 0xFF
if key == ord('q'):
        break

cap.release()

cv2.destroyAllWindows()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文