Skip to content

Instantly share code, notes, and snippets.

@theharshith
Created July 25, 2024 03:32
Show Gist options
  • Select an option

  • Save theharshith/8f02bcdd8422a1358f1e24e49a0fc078 to your computer and use it in GitHub Desktop.

Select an option

Save theharshith/8f02bcdd8422a1358f1e24e49a0fc078 to your computer and use it in GitHub Desktop.

To install OpenCV with CUDA support on your NVIDIA Jetson Nano, follow these steps:

Step 1: Update and Upgrade the System First, ensure that your system is updated:

sudo apt-get update sudo apt-get upgrade Step 2: Install Dependencies Install the required dependencies:

sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev

Step 3: Download OpenCV and OpenCV Contrib Download the OpenCV and OpenCV Contrib source code:

cd ~ git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git Step 4: Checkout to a Specific Version (Optional)

You can checkout to a specific version if needed:

cd ~/opencv git checkout 4.1.1 cd ~/opencv_contrib git checkout 4.1.1 Step 5: Create a Build Directory Create a directory for the build process:

cd ~/opencv mkdir build cd build Step 6: Configure the Build with CMake Configure the build to enable CUDA:

cmake -D CMAKE_BUILD_TYPE=Release
-D CMAKE_INSTALL_PREFIX=/usr/local
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules
-D WITH_CUDA=ON
-D ENABLE_FAST_MATH=1
-D CUDA_FAST_MATH=1
-D WITH_CUDNN=ON
-D OPENCV_DNN_CUDA=ON
-D WITH_CUBLAS=1
-D BUILD_opencv_cudacodec=OFF
.. Step 7: Build and Install OpenCV Start the build process. This can take several hours:

make -j4 # Use the number of cores you have, for Jetson Nano 2GB, use -j2 sudo make install sudo ldconfig Step 8: Verify the Installation To verify that OpenCV is installed with CUDA support, run the following Python script:

import cv2 print(cv2.getBuildInformation()) Look for the lines indicating CUDA support:

yaml Use CUDA: YES Use CUDNN: YES Troubleshooting Ensure you have the correct CUDA version installed: The installed version of CUDA should match the one compatible with your Jetson Nano. The above steps are tailored for CUDA 10.x. Check for any missing dependencies: Ensure all necessary libraries are installed. Review CMake output: During the CMake configuration step, ensure that CUDA is found and enabled in the configuration summary. If you encounter any errors, please share the specific error messages for further assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment