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

By : DamianJ
Source: Stackoverflow.com
Question!

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.

By : DamianJ


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



They have discontinued cvseq in cv2. There's no module cv2.cv.cvseq in opencv 2.3.1

You should use

lines = cv2.HoughLines(dst, 1, CV_PI/180, 100, 0)

http://opencv.itseez.com/modules/imgproc/doc/feature_detection.html?highlight=houghlines#cv2.HoughLines

cv2 library is much more user friendly, fast and effective. You should move on to OpenCV 2.3.1 or 2.4.0. If you have any problems installing OpenCV 2.3.1 - http://jayrambhia.wordpress.com/2012/05/02/install-opencv-2-3-1-and-simplecv-in-ubuntu-12-04-precise-pangolin-arch-linux/

By : Froyo


This video can help you solving your question :)
By: admin