Search code examples
pythonopencvpython-2.7edge-detectionhough-transform

Python OpenCv gives error 'cv2.cv.cvseq' object has no attribute 'total'


I was looking for some image edge detection code in Python on the web and found some interesting stuff that I wanted to take a look at. Unfortunately I keep getting this error: 'cv2.cv.cvseq' object has no attribute 'total'

The line of code at fault is

lines = HoughLines2( dst, storage, CV_HOUGH_STANDARD, 1, CV_PI/180, 100, 0, 0 );

The whole code has the option to toggle between Hough Standard and Hough Probabilistic, when I set it to use the probabilistic approach (and thus not requiring "lines.total" piece of code) it runs fine, so I'm fairly certain I have everything I need installed and imported.


Solution

  • I don't know why you use old 'cv' version, while new 'cv2' version is quite simple and all objects are returned either as python list or numpy array, which is easy to handle from user point of view.

    Output of HoughLines functions are numpy array of shapes (1,number of lines,2) and (1,number of lines,4). You can do whatever you want since you have all numpy functions at your hand.

    Here is a sample for detecting lines, which is same as you mentioned, ie toggling between hough standard and hough probabilistic: houghlines.py

    Below are the results i obtained using that code :

    Hough Standard :

    enter image description here

    Hough Probabilistic :

    enter image description here

    Of course the line detected depends on the parameter values you try. So change parameter values as you like and try.