Installation of higher version of opencv

Hi,

I want to run my custom object detector of darknet on jetson nano but iam facing the following error while i run my code for detection.

“”""
nvidia-jetson-sndk@nvidiajetsonsndk-desktop:~/Downloads/yolov3_darknet_python$ python3 yolov3_darknet.py --image station3.jpg
Weight Number: 40500
Traceback (most recent call last):
File “yolov3_darknet.py”, line 41, in
net = cv.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
AttributeError: module ‘cv2’ has no attribute ‘dnn’
“”""

Any help would be appreciated.

Hi,

You can install it by building it from the source.
Here is a script of OpenCV4.0 for your reference:
https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.0.0_Nano.sh

Thanks.

I installed opencv 4 but it is still taking opencv 3.2.0 could you help me to overcome this? please find the attachment.

Hi,

If the default opencv is not removed, you will need to update your Makefile to the correct header/lib.
Thanks.

Hi,

On the nano, I removed opencv-3.2.0 using:

sudo sudo apt-get purge *libopencv*

I confirmed removal with find and:

import cv2
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘cv2’

Then ran the script posted by AastaLLL (#2):

install_opencv4.0.0_Nano.sh

After running install_opencv4.0.0_Nano.sh there was confirmation of install:

Setting up libopencv-videostab3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-contrib3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up python3-opencv (3.2.0+dfsg-4ubuntu0.1) …
Setting up python-opencv (3.2.0+dfsg-4ubuntu0.1) …
Processing triggers for libc-bin (2.27-3ubuntu1) …
** Install opencv-4.0.0 successfully
** Bye :)
nvidia@nvidia-desktop:~$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import cv2
cv2.version
‘3.2.0’

It appears opencv-3.2.0 was installed, not opencv-4.0.0:

AastaLLL (#4) suggests:
“If the default opencv is not removed, you will need to update your Makefile to the correct header/lib.”

Apologies in advance if pedestrian for this forum:

  • What Makefile is AastaLLL referring to?
  • How do I find the correct header/lib and change Makefile accordingly?
  • Hi,

    Sorry about that there is a bug inside the install_opencv4.0.0_Nano.sh:

    sudo apt-get install -y python-opencv python3-opencv
    

    The command will install the package from apt which is v3.3.
    This is no needed since the script already build the version 4.0.

    I have removed the line from the install_opencv4.0.0_Nano.sh.

    After building OpenCV from source, the python package is located at {folder}/opencv-4.0.0/release/python_loader.
    Please update the library path like this:

    export PYTHONPATH=$PYTHONPATH:/path/to/your/folder/opencv-4.0.0/release/python_loader/
    

    Thanks.