Har*_*n M 9 python opencv aruco
AttributeError:模块“cv2.aruco”没有属性“Dictionary_get”
即使安装后
import numpy as np
import cv2, PIL
from cv2 import aruco
import matplotlib.pyplot as plt
import matplotlib as mpl
import pandas as pd
vid = cv2.VideoCapture(0)
while (True):
ret, frame = vid.read()
#cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
aruco_dict = aruco.Dictionary_get(aruco.DICT_6X6_250)
parameters = aruco.DetectorParameters()
corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
frame_markers = aruco.drawDetectedMarkers(frame.copy(), corners, ids)
plt.figure()
plt.imshow(frame_markers)
for i in range(len(ids)):
c = corners[i][0]
plt.plot([c[:, 0].mean()], [c[:, 1].mean()], "o", label = "id={0}".format(ids[i]))
plt.legend()
plt.show()
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
查找和标记 aruco 的正常示例
not*_*7CD 26
4.7.x 的 API 发生了变化,我更新了一个小片段。现在您需要实例化 ArucoDetector 对象。
import cv2 as cv
dictionary = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_250)
parameters = cv.aruco.DetectorParameters()
detector = cv.aruco.ArucoDetector(dictionary, parameters)
frame = cv.imread(...)
markerCorners, markerIds, rejectedCandidates = detector.detectMarkers(frame)
Run Code Online (Sandbox Code Playgroud)
从新版本安装旧版本的 opencv-contrib-python 后,它工作正常
pip install opencv-contrib-python==4.6.0.66
Run Code Online (Sandbox Code Playgroud)
https://pypi.org/project/opencv-contrib-python/4.6.0.66/
| 归档时间: |
|
| 查看次数: |
35111 次 |
| 最近记录: |