Ask Your Question
0

python sample script error : AttributeError: 'module' object has no attribute 'LINE_AA' (OpenCV 3.1, python 2.7.9)

asked 2016-09-15 07:13:55 -0600

DevelopB gravatar image

Hi, posting the content below. Executed, as python facedetect.py in sample scripts of opencv version 3.1:

face detection using haar cascades

USAGE: facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]

Traceback (most recent call last): File "facedetect.py", line 68, in <module> draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000)) File "/media/bhargav/Bhargav_WD1/temp_dir/home_bhargav/OpenCV/samples/python/common.py", line 83, in draw_str cv2.putText(dst, s, (x+1, y+1), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 0), thickness = 2, lineType=cv2.LINE_AA) AttributeError: 'module' object has no attribute 'LINE_AA'

Kindly help. Thanks in advance.

edit retag flag offensive close merge delete

Comments

please try a cv2.__version__

berak gravatar imageberak ( 2016-09-15 07:30:31 -0600 )edit

Thank you Berak. It outputs: '2.4.9.1'

But i have version 3.1 installed (checked library files as *.so.3.1). The sample program opencv_version.py also is showing 2.4.9.1 in output.

DevelopB gravatar imageDevelopB ( 2016-09-15 07:43:38 -0600 )edit
1

cv2.LINE_AA is only available in opencv3. and well, now you have to find out, why python prefers the wrong cv2.so ....

berak gravatar imageberak ( 2016-09-15 08:29:51 -0600 )edit

Used steps: clone source from https://github.com/opencv/opencv.git. sudo apt-get update sudo apt install python-pip sudo pip install --upgrade pip sudo apt-get upgrade libv4l-dev cd /usr/include/linux sudo ln -s ../libv4l1-videodev.h videodev.h // This didnt exist before.But videodev2.h exists in my folder. sudo apt-get install python-setuptools python-dev build-essential sudo apt-get install cmake sudo apt-get install python-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. sudo make sudo make install sudo apt-get install python-opencv

DevelopB gravatar imageDevelopB ( 2016-09-15 08:43:36 -0600 )edit

Sorry, not readable format as shrinked due to limit on length. That is the setup steps I followed. Using python 2.7 From OpenCV source git repository, did cmake and built make file. Used makefile to install OpenCV. The sample file is from the same source code, so it should work right? Or sample python files are not updated along with python versions?

I believe I have installed OpenCV 3.1 because of which 3.1 so files are installed. Not sure why __vesion__ is printing differently.

DevelopB gravatar imageDevelopB ( 2016-09-15 08:46:57 -0600 )edit

Oh sorry. I understand your answer now. I am checking why wrong cv2 got installed/picked. ie cv2.so corresponding to 2.4.x version rather than 3.1.

DevelopB gravatar imageDevelopB ( 2016-09-15 08:53:43 -0600 )edit

Hi, I got the lib file which one is picked up. the cv2.so is picked up as : /usr/lib/python2.7/dist-packages/cv2.x86_64-linux-gnu.so

This .so is getting created through the command: sudo apt-get install python-opencv

DevelopB gravatar imageDevelopB ( 2016-09-15 11:42:18 -0600 )edit

Can I get help on resolving this... how do I make sure the so file corresponds to openCV3.1 and not 2.4.x

DevelopB gravatar imageDevelopB ( 2016-09-15 11:43:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-17 22:18:47 -0600

DevelopB gravatar image

I could alternatively proceed by make LINE_AA to CV_AA. Could not resolve root cause, which is in apt-xenial config that lists 2.4.x only and not 3.1 for OpenCV corresponding to cv2 library. Thank you very much Berak.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-09-15 07:13:55 -0600

Seen: 16,187 times

Last updated: Sep 17 '16