MonsterAuto.py OpenCV Issue
Forums:
Hi;
I have installed OpenCV 3.4.0 and would like to use MonsterAuto.py for line following however when I try and start the script I get the following error:
I have installed OpenCV 3.4.0. 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'
I believe this is due to changes between OpenCV 2 and OpenCV 3?
I have just raised this as an issue on GitHub.
Thanks
piborg
Thu, 03/22/2018 - 17:48
Permalink
Modifying the code for OpenCV 3
There are a few minor differences for OpenCV 3 vs OpenCv 2, it should be just a few minor changes to the code.
Try changing these lines:
to these ones:
JonnyAlpha
Fri, 03/23/2018 - 16:42
Permalink
Sorted thanks
Sorted thanks
rbn
Fri, 01/17/2020 - 14:27
Permalink
Similar problem with Buster install
I am trying to install this on Buster OS for Pi, runnning on a Pi3B+.
I found that there is no package libcv-dev in Buster although libopencv-dev and python-opencv are available and installed.( It says that libopencv-dev replaces it). I tried the changes listed above, but I still get the same error.
Any suggestions?
piborg
Fri, 01/17/2020 - 17:15
Permalink
libcv-dev no longer needed
The libcv-dev package is not required anymore, it can be removed from the install.
The command should be:
I will get the instructions updated once I am back in the office :)
rbn
Fri, 01/17/2020 - 18:31
Permalink
Ok on libcv-dev not required.
Ok on libcv-dev not required. I still have the same problem indicated in the thread even though I have for the three mods you suggest.
piborg
Fri, 01/17/2020 - 20:29
Permalink
What is your error message?
What is the actual error message you are seeing?
Please include all of the lines shown like the original poster.
rbn
Fri, 01/17/2020 - 22:44
Permalink
I get excatly the same error
I get exactly the same error as the original poster in this thread. ie in line 91
I followed your advice there and altered the lower case cv to uppercase CV but the eror persists.
I am using the latest Buster OS with sudo apt update and sudo apt upgrade applied.
I have installed the two extra packages specified in your answer libopencv-dev python-opencv
Running on a Pi 3B+ The Web control program works fine.
piborg
Fri, 01/17/2020 - 22:51
Permalink
Remove the cv term
The change was to remove
cv.
, not make it upper case. The lines should be three characters shorter.For comparison:
rbn
Sat, 01/18/2020 - 11:24
Permalink
Oops. My mistake....however I
Oops. My mistake....however I have removed the cv and I still get the same error.
For additional info the exact version of the packages installed by Buster are
libopencv-dev-3.2.0+dfsg-6
python-opencv-3.2.0+dfsg-6
piborg
Sat, 01/18/2020 - 11:41
Permalink
Confirm which OpenCV version Python is actually loading
If you run Python:
then use these lines to determine the exact version of OpenCV that Python is actually finding
It is probably the same as the packages, but it is possible that it is different.
piborg
Sat, 01/18/2020 - 11:46
Permalink
Might need to remove CV_ as well
It looks like you might need to remove the
CV_
part of the names as well:rbn
Sat, 01/18/2020 - 17:01
Permalink
Some progress..
checked and the cv2 version is 3.2.0
removing the CV_ for lines 19-21 solves that error. Now gives an error in ImageProcessor.py
for lineType = cv2.CV_AA no attribute CV_AA
I googled this and found https://bugsinmycodes.blogspot.com/2016/11/opencv3-no-attribute-name-cvaa.html which suggests changing it to LINE_AA which I did in the three lines with this attribute. That cured that error. Now it stopped with an exception.
I should say that I am trying it out disconnected to the thunderBorg at the moment, although connected to the camera, but I shall connect it all up and retry and let you now if that cures it.
In the meantime you may wish to upgrade the documentation for other users trying out the code on Buster.
piborg
Sat, 01/18/2020 - 18:36
Permalink
Updated numpy
The latest error is due to a newer version of the numpy library.
You can fix it by changing the line
to
rbn
Sun, 01/19/2020 - 07:45
Permalink
Sorted
Thanks. That final change has got it all working.
So to get it working under latest Buster OS:
A) change lines 91-93 in MonsterAuto.py to:
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);
B) change three references to LineType = cv2.CV_AA to LineType = cv2.LINE_AA
C in MonsterAuto.py change line if monsterView !=None: to
if monsterView is not None:
With these three changes the program works!