AttributeError: module ‘cv2.aruco‘ has no attribute ‘GridBoard_create‘报错解决

AttributeError: module 'cv2.aruco' has no attribute 'GridBoard_create'报错解决

问题描述

使用Opencv的Python版本,运行:

ARUCO_PARAMETERS = aruco.DetectorParameters_create()
ARUCO_DICT = aruco.Dictionary_get(aruco.DICT_ARUCO_ORIGINAL)
corners, ids, rejectedImgPoints = aruco.detectMarkers(frame, ARUCO_DICT, parameters=ARUCO_PARAMETERS)

报错:

AttributeError: module 'cv2.aruco' has no attribute 'DetectorParameters_create'

原因

网上查了很多,说是把opencv版本降低。其实这就是版本的问题,pip show opencv-python发现:

Name: opencv-python
Version: 4.7.0.68
Summary: Wrapper package for OpenCV python bindings.
Home-page: https://github.com/opencv/opencv-python
Author: 
Author-email: 
License: MIT
Location: /home/anaconda3/envs/xxx/lib/python3.9/site-packages
Requires: numpy, numpy, numpy
Required-by: 

上述函数接口在4.7.x版本之后有一些变化,改变接口函数即可,无需降低版本等操作。

解决

改变函数即可,不需变化版本:

from cv2 import aruco

ARUCO_PARAMETERS = aruco.DetectorParameters()
ARUCO_DICT = aruco.getPredefinedDictionary(aruco.DICT_ARUCO_ORIGINAL)
detector = aruco.ArucoDetector(ARUCO_DICT,ARUCO_PARAMETERS)
    corners, ids, rejectedImgPoints = detector.detectMarkers(frame)

其中,frame为之前的imread读入,即frame = cv2.imread(...)

猜你喜欢

转载自blog.csdn.net/weixin_43789096/article/details/129346433