Search code examples
python-3.xopencvhough-transform

Can't use OpenCV GeneralizedHoughTransform class with Python


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 https://github.com/opencv/opencv/blob/4.0.0/samples/gpu/generalized_hough.cpp 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 (https://github.com/opencv/opencv/blob/4.0.0/modules/imgproc/include/opencv2/imgproc.hpp) 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?


Solution

  • Apparently it's called just GeneralizedHoughBallard

    import cv2
    print([x for x in dir(cv2) if 'Hough' in x])
    print([x for x in dir(cv2) if x.startswith('create')])
    
    ['GeneralizedHough',
     'GeneralizedHoughBallard',
     'GeneralizedHoughGuil',
     'HoughCircles',
     'HoughLines',
     'HoughLinesP',
     'HoughLinesPointSet']
    ['createAffineTransformer',
     'createAlignMTB',
     'createBackgroundSubtractorKNN',
     'createBackgroundSubtractorMOG2',
     'createButton',
     'createCLAHE',
     'createCalibrateDebevec',
     'createCalibrateRobertson',
     'createChiHistogramCostExtractor',
     'createEMDHistogramCostExtractor',
     'createEMDL1HistogramCostExtractor',
     'createHanningWindow',
     'createHausdorffDistanceExtractor',
     'createLineSegmentDetector',
     'createMergeDebevec',
     'createMergeMertens',
     'createMergeRobertson',
     'createNormHistogramCostExtractor',
     'createShapeContextDistanceExtractor',
     'createThinPlateSplineShapeTransformer',
     'createTonemap',
     'createTonemapDrago',
     'createTonemapDurand',
     'createTonemapMantiuk',
     'createTonemapReinhard',
     'createTrackbar']