AttributeError: 'module' object has no attribute 'cv'

I just installed OpenCV (libopencv-dev python-opencv) and monster_self_drive. When running MonsterAuto.py I get the following error:

pi@raspberrypi:~/monster-self-drive $ ./MonsterAuto.py
Libraries loaded
Running script in directory "."
TEST MODE: Skipping board setup
Setup camera input
Traceback (most recent call last):
File "./MonsterAuto.py", line 91, in
Settings.capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, Settings.imageWidth);
AttributeError: 'module' object has no attribute 'cv'

Change the code in doesn't help:
Settings.capture.set(cv2.CV_CAP_PROP_FRAME_WIDTH, Settings.imageWidth);

or
Settings.capture.set(cv2.CAP_PROP_FRAME_WIDTH, Settings.imageWidth);

What can I do?

Images: 
piborg's picture

Recent versions of Raspbian have updated versions of OpenCV and numpy. The MonsterAuto.py script is based on older versions that were slightly different. There are a few changes you will need to make to get the script to work properly.

AttributeError: 'module' object has no attribute 'cv'

This can be fixed by changing these lines:

Settings.capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, Settings.imageWidth);
Settings.capture.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, Settings.imageHeight);
Settings.capture.set(cv2.cv.CV_CAP_PROP_FPS, Settings.frameRate);

to these ones:

Settings.capture.set(cv2.CAP_PROP_FRAME_WIDTH, Settings.imageWidth);
Settings.capture.set(cv2.CAP_PROP_FRAME_HEIGHT, Settings.imageHeight);
Settings.capture.set(cv2.CAP_PROP_FPS, Settings.frameRate);

on lines 91-93 in MonsterAuto.py.

Use a.any() or a.all() error

You can fix this by changing the line

if monsterView != None:

to

if monsterView is not None:

on line 122 in MonsterAuto.py.

AttributeError: 'module' object has no attribute 'CV_AA'

You can fix this by changing the three instances of

LineType = cv2.CV_AA

to

LineType = cv2.LINE_AA

on lines 278, 281, and 283 in ImageProcessor.py.

Thanks.
It's working.

Subscribe to Comments for "AttributeError: 'module' object has no attribute 'cv' "