I have jetson orin nano, jetpack 6.2 cuda 12.6, i cant install opencv with cuda ,im struggling right now on how to do it , there’s a lot of tutorial on how to do it but its showing no cuda, Please can help me on how to install it properly
*** Please note that this reply is generated by LLM automatically ***
Installing OpenCV with CUDA support on Jetson Orin Nano can be a bit tricky, but I’ll guide you through the process.
Prerequisites:
- You have JetPack 6.2 installed on your Jetson Orin Nano, which includes CUDA 12.6.
- You have a basic understanding of Linux and command-line interfaces.
Step 1: Update and Upgrade
Before installing OpenCV, make sure your system is up-to-date:
sudo apt update
sudo apt upgrade
Step 2: Install dependencies
You’ll need to install some dependencies required by OpenCV:
sudo apt install -y build-essential cmake git libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev
Step 3: Install CUDA Toolkit
Although you have CUDA 12.6 installed with JetPack 6.2, you need to install the CUDA Toolkit to get the necessary development files:
sudo apt install -y cuda-toolkit-12-6
Step 4: Download and build OpenCV
Download the OpenCV source code from the official GitHub repository:
git clone https://github.com/opencv/opencv.git
cd opencv
Create a build directory and navigate into it:
mkdir build
cd build
Run the CMake command to configure the build process:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D CUDA_ARCH_BIN=8.7 ..
The CUDA_ARCH_BIN flag is set to 8.7, which is the architecture of the Jetson Orin Nano’s GPU.
Build and install OpenCV:
make -j$(nproc)
sudo make install
Step 5: Verify OpenCV installation
After installation, verify that OpenCV is working correctly:
python -c "import cv2; print(cv2.__version__)"
This should print the OpenCV version.
Troubleshooting
If you encounter issues during the installation process, you can try the following:
- Make sure you have the correct CUDA version installed (CUDA 12.6).
- Check that the
CUDA_ARCH_BINflag is set correctly (8.7 for Jetson Orin Nano). - If you’re using a virtual environment, ensure that it’s activated before installing OpenCV.
Comparison with other tutorials
Some tutorials might suggest using apt-get to install OpenCV, but this method may not provide the latest version or CUDA support. Building OpenCV from source ensures that you get the latest version and CUDA support.
Additionally, some tutorials might recommend using cmake with different flags or options. The flags used in this tutorial are specific to the Jetson Orin Nano and CUDA 12.6.
By following these steps, you should be able to install OpenCV with CUDA support on your Jetson Orin Nano.
*** Please give the thumbs up if you get answers you like. Or provide feedback to help us improve the answer. ***
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_CUDA=ON -D CUDA_ARCH_BIN=8.6 -D CUDA_ARCH_PTX=8.6 ..
– Detected processor: aarch64
– Looking for ccache - not found
– Could NOT find AVIF (missing: AVIF_LIBRARY AVIF_INCLUDE_DIR)
Cleaning INTERNAL cached variable: WEBP_LIBRARY
Cleaning INTERNAL cached variable: WEBP_INCLUDE_DIR
– Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
– OpenJPEG: VERSION = 2.5.3, BUILD = opencv-4.13.0-dev-openjp2-2.5.3
– OpenJPEG libraries will be built from sources: libopenjp2 (version “2.5.3”)
– NVCUVID: Header not found, WITH_NVCUVID requires Nvidia decoding library header /usr/local/cuda;/usr/local/cuda/include/nvcuvid.h
– NVCUVENC: Header not found, WITH_NVCUVENC requires Nvidia encoding library header /usr/local/cuda;/usr/local/cuda/include/nvEncodeAPI.h
– CUDA detected: 12.6
– CUDA: Using CUDA_ARCH_BIN=8.6
– CUDA: NVCC target flags -gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES;-gencode;arch=compute_86,code=compute_86
– Found OpenBLAS using environment hint
– OpenBLAS_LIBRARIES=/usr/lib/aarch64-linux-gnu/libopenblas.so
– OpenBLAS_INCLUDE_DIRS=/usr/include/aarch64-linux-gnu
– LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/aarch64-linux-gnu/libopenblas.so
CMake Warning at cmake/OpenCVFindLAPACK.cmake:60 (message):
LAPACK(OpenBLAS): CBLAS/LAPACK headers are not found in
‘/usr/include/aarch64-linux-gnu’
Call Stack (most recent call first):
cmake/OpenCVFindLAPACK.cmake:190 (ocv_lapack_check)
CMakeLists.txt:818 (include)
– Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR)
– Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE)
– Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
– VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
– Checking for module ‘libavdevice’
– No package ‘libavdevice’ found
– Allocator metrics storage type: ‘int’
CMake Error at modules/core/CMakeLists.txt:165 (message):
CUDA: OpenCV requires enabled ‘cudev’ module from ‘opencv_contrib’
repository: GitHub - opencv/opencv_contrib: Repository for OpenCV's extra modules
– Configuring incomplete, errors occurred!
See also “/home/droif/opencv/build/CMakeFiles/CMakeOutput.log”.
See also “/home/droif/opencv/build/CMakeFiles/CMakeError.log”.
droif@droif-desktop:~/opencv/build$
im getting this error
Actually before this I tried using the JEP opencv builder jetpack 6.1 and when i run jtop it shows yes cuda , but when i try to print show cuda in terminal it saying no cuda
Hi,
You can find the Python package in the URL below:
For the C++ library, you can build it from the source with the script below:
Thanks.
i already tried script/install_opencv4.10.0_Jetpack6.1.sh this, it shows in jtop that theres a cuda , but when trying to run in terminal it wont , even i cant import torch
Hi,
Could you print out the version to validate if you are loading the expected library?
Thanks.