Ask Your Question

How to use OpenCV GeneralizedHoughTransform class with Python?

asked 2019-04-03 04:37:40 -0500

franjial gravatar image

I'm trying to code a basic example of use of GeneralizedHoughBallard class using OpenCV 4.0.0 and Python 3.6. I have found an example for C++ here but no for Python.

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".

I've seen in the OpenCV source ( that createGeneralizedHoughBallard is declared with CV_EXPORTS so I suppose it should be possible to use with Python. I've tried to use another similar function that is declared in the same file (improc.hpp) for example: cv2.createCLAHE() and works fine.

What could be the problem?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-03 04:44:31 -0500

berak gravatar image

updated 2019-04-03 04:46:28 -0500

no, sad as it is, it's not exposed to python.

createGeneralizedHoughBallard is declared with CV_EXPORTS

it would need CV_EXPORTS_W , see here

(ofc. you can try to change it, and rebuild (back to cmake !). if you try, please report back, maybe just the wrapper got overlooked, and it's all easy !)

edit flag offensive delete link more


i recompiled by CV_EXPORTS_W and tried

import cv2
alg = cv2.createGeneralizedHoughBallard()

it is OK (i did not try more)

sturkmen gravatar imagesturkmen ( 2019-04-03 06:02:00 -0500 )edit

Hi! I have edited the code and works fine now for Ballard algorithm but no for Guil. For make it works I think is necesary add CV_WRAP to all public methods in GeneralizedHoughGuil class. Thanks!

franjial gravatar imagefranjial ( 2019-04-09 06:19:43 -0500 )edit

could you add the python test code here. let me try it.

sturkmen gravatar imagesturkmen ( 2019-04-09 11:47:02 -0500 )edit


import cv2
alg = cv2.createGeneralizedHoughGuil()

And get the error: AttributeError: 'cv2.GeneralizedHoughGuil' object has no attribute 'setLevels'. After recompile with CV_WRAP works fine.

franjial gravatar imagefranjial ( 2019-04-09 13:22:03 -0500 )edit

I try to change the code in imgproc.hpp with adding CV_EXPORTS_W

CV_EXPORTS_W Ptr<GeneralizedHoughBallard> createGeneralizedHoughBallard();
CV_EXPORTS_W Ptr<GeneralizedHoughGuil> createGeneralizedHoughGuil();

But when I recompile OpenCV, I got something error when compiling. Do I need to change any other code?

Eko Rudiawan gravatar imageEko Rudiawan ( 2019-04-21 01:19:13 -0500 )edit
sturkmen gravatar imagesturkmen ( 2019-04-21 01:52:09 -0500 )edit

Question Tools

1 follower


Asked: 2019-04-03 04:37:40 -0500

Seen: 644 times

Last updated: Apr 03 '19