Ask Your Question

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 -0500

DevelopB gravatar image

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

face detection using haar cascades

USAGE: [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]

Traceback (most recent call last): File "", 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/", 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


please try a cv2.__version__

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

Thank you Berak. It outputs: ''

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

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

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

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

Used steps: clone source from 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 -0500 )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 -0500 )edit

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

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

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

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

DevelopB gravatar imageDevelopB ( 2016-09-15 11:42:18 -0500 )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 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

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

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


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

Seen: 15,133 times

Last updated: Sep 17 '16