Select the specific version of OpenCV

I have 2 versions of OpenCV on my Jetson Nano 4GB. I compiled version 4.5.4 following a tutorial from Jetsonhacks, but when I installed Mediapipe 0.8.9, it brought the installation of non-compiled OpenCV 4.8.1. Now, all programs are using OpenCV 4.8.1.

How do I configure my Jetson Nano to use only version 4.5.4?

Hi,
Please try the script to manually build specific-version OpenCV:
https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.6.0_Jetson.sh#L12

Hi, thanks for your quick reply!

What’s the difference in following these instructions?

After compiling and installing MediaPipe, will OpenCV 4.8.1 not be overwritten by its version?

Hi,
We are not sure how to dynamically switch between different OpenCV versions. This would need other users to share experience.

The script will cleanup installed OpenCV packages and build/install 4.6.0. You may modify to version="4.5.4"

I tried to use your script:

cd ~/Downloads
chmod +x install_opencv4.6.0_Jetson.sh
./install_opencv4.6.0_Jetson.sh

However, I received this message during the installation:

[ 23%] Linking CXX static library …/lib/liblibprotobuf.a
[ 23%] Built target libprotobuf
Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2
jv@jv-desktop:~/Downloads$

Can you help-me, please?

Hi,
Please check if there is enough freespace on storage. It requires certain amount of freespace when building OpenCV. And you may also try this script:
GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano

I solved this problem by changing "CUDA_ARCH_BIN=“7.2,8.7"”. I configured "CUDA_ARCH_BIN=“5.2"” and successfully installed it.

Now I’m encountering another issue:

I successfully installed OpenCV 4.6.0. In the jtop info, it shows:

OpenCV: 4.6.0 with CUDA: YES

However, when I tried to run a program:

pythonCopy code

import cv2
print(cv2.__version__)

# Webcam
cam = cv2.VideoCapture(0)
cam.set(3, 640)
cam.set(4, 480)

while True:
    ret, frame = cam.read()
    cv2.imshow('nanoCam', frame)
    if cv2.waitKey(1) == ord('q'):
        break

cam.release()
cv2.destroyAllWindows()

I received the following error message:

typescriptCopy code

jv@jv-desktop:~/Desktop/PyVWCO-DDAW23.10.04$ /usr/bin/python3.8 /home/jv/Desktop/PyVWCO-DDAW23.10.04/Oficial/test_CAM.py
Traceback (most recent call last):
  File "/home/jv/Desktop/PyVWCO-DDAW23.10.04/Oficial/test_CAM.py", line 1, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'

When I checked with pip3 list, I found:

opencv-python 4.8.1.78

And when I used print(cv2.getBuildInformation()), it showed:

mathematicaCopy code

General configuration for OpenCV 4.8.1 =====================================
  Version control:               unknown

Any ideas on how to solve this?

Hi,
Please try python 2.7 and see if it can run successfully. May also try this sample:
V4l2src using OpenCV Gstreamer is not working in Jetson Xavier NX - #3 by DaneLLL

Hi,

Is there multiple python3 in your environment?
Could you double-check if you have built the OpenCV corresponding to Python 3.8 rather than 3.6?

Thanks.

Using Python 2.7 works, but in Python 3.6, the OpenCV version is 4.8.1.

I want to use OpenCV 4.6 with Python 3.6. How can I do this?

I think it was built in Python 2.7.

At which step should I configure it to build in Python 3.6?

Hi,

Both scripts have enabled Python2 and Python3 support.
Based on the log you shared on Oct 5, it seems you are using Python 3.8.

> jv@jv-desktop:~/Desktop/PyVWCO-DDAW23.10.04$ /usr/bin/python3.8 /home/jv/Desktop/PyVWCO-DDAW23.10.04/Oficial/test_CAM.py
...

But when you build the OpenCV from the source, it should use the default Python3.6.
Could you check the OpenCV version of Python 3.6 first?
What do you get if you run the following command?

$ python3
$ import cv2
$ print(cv2.getBuildInformation())

Thanks.

Unfortunately, when I run this command, OpenCV 4.8.1 comes up without CUDA support.

jv@jv-desktop:~$ python3
Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.getBuildInformation())

General configuration for OpenCV 4.8.1 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2023-10-01T19:50:02Z
    Host:                        Linux 4.9.337-tegra aarch64
    CMake:                       3.27.6
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

I asked the creator of the tutorial (how to install media pipe on jetson nano) about this issue, and he responded as follows:

You mentioned that your ‘OpenCV 4.5.4’ is compiled with CUDA support. There is a common misconception that compiling OpenCV with CUDA automatically makes all operations faster by running them on the GPU. To actually utilize the GPU, you would need to modify your code and transfer data to and from the GPU, as explained in this tutorial. So, unless your code is adapted to do that, you are not gaining any benefit by installing a new non-CUDA version of OpenCV.

Does it make sense to you?
Please note that the provided link does not work

Can’t you just pip uninstall opencv 4.8 then? Would that not solve the issue? (not sure)

I had a kind of similar issue a few days back, I had two opencv (both from source), 4.5 with no cuda and 4.6 with cuda.

My c++ code would always try to link the libraries with opencv 4.5 so I just removed it and now it works.

Your case might be different but still, just try uninstalling it.

I tried to do this, but it only downgraded OpenCV to version 4.5.4 without CUDA support in Python 3.6. In my system OpenCV with CUDA is only available in Python 2.7.
:-/

I solved this problem by following this script: https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.5.0_Jetson.sh#L42

Perhaps the issue was related to the path. I encountered difficulties installing version 4.8.0, but I managed to successfully build version 4.6.0.build version 4.6.0

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.