简体   繁体   中英

How to use OpenCV GeneralizedHoughTransform class with Python?

I'm trying to code a basic example of use of GeneralizedHoughBallard class using OpenCV 3.4.1 and Python 3.7.1

When I try to create a new instance of GeneralizedHoughBallard class:

import cv2
alg = cv2.createGeneralizedHoughBallard()

I get the error:

AttributeError: module 'cv2.cv2' has no attribute 'createGeneralizedHoughBallard'

Also I've tried to show all the Hough-methods:

print([x for x in dir(cv2) if 'Hough' in x])

And the result: ['HoughCircles', 'HoughLines', 'HoughLinesP', 'HoughLinesPointSet']
So I haven't the basic functions. How can I import it? Is it possible?

It seems OpenCV 3.4.1 does not have it. In OpenCV v4.0.X its called GeneralizedHoughBallard . You may want to update your OpenCV version.

python -m pip install --upgrade opencv-python

Checking the Hough-methods:

import cv2
print(cv2.__version__)
print([x for x in dir(cv2) if 'Hough' in x])

4.0.0.21

['GeneralizedHough', 'GeneralizedHoughBallard', 'GeneralizedHoughGuil', 'HoughCircles', 'HoughLines', 'HoughLinesP', 'HoughLinesPointSet']

It might not be totally supported in Python, please check it here opencv forum link

But somehow possible to do it by rebuilding opencv and dealing with CV_EXPORTS_W

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM