Installing OpenCV 4.5 on NVIDIA Jetson Nano and Configuring Camera Setup

Posted by

How to Install OpenCV 4.5 on NVIDIA Jetson Nano and Set Up a Camera

How to Install OpenCV 4.5 on NVIDIA Jetson Nano and Set Up a Camera

If you have a NVIDIA Jetson Nano and want to use OpenCV 4.5 for computer vision projects, you’re in the right place. In this tutorial, we’ll show you how to install OpenCV 4.5 on your Jetson Nano and set up a camera for capturing images and videos.

Step 1: Install OpenCV 4.5 on NVIDIA Jetson Nano

To install OpenCV 4.5 on your Jetson Nano, you’ll need to follow these steps:

  1. Update your Jetson Nano’s package list: sudo apt update
  2. Install required packages: sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libswscale-dev libtbb2 libtbb-dev libjpeg-dev libtiff-dev libpng-dev libavcodec-dev libavformat-dev libv4l-dev libxvidcore-dev libx264-dev libxine2-dev libatlas-base-dev gfortran
  3. Clone OpenCV 4.5 GitHub repository: git clone https://github.com/opencv/opencv.git
  4. Go to the OpenCV directory: cd opencv
  5. Create a build directory: mkdir build
  6. Go to the build directory: cd build
  7. Run CMake to configure OpenCV: cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 ..
  8. Compile and install OpenCV: make -j4 and sudo make install

Step 2: Set Up a Camera for NVIDIA Jetson Nano

To set up a camera for your Jetson Nano, you can use a USB camera or a Raspberry Pi Camera Module. Here’s how to connect and configure a USB camera:

  1. Connect the USB camera to your Jetson Nano.
  2. Check if the camera is detected: ls /dev/video*
  3. If the camera is detected, you can use it with OpenCV in your Python scripts.

That’s it! You’ve successfully installed OpenCV 4.5 on your NVIDIA Jetson Nano and set up a camera for capturing images and videos. You’re now ready to start working on computer vision projects with your Jetson Nano.

0 0 votes
Article Rating
29 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@CodeWithAarohi
7 months ago

List of commands:

sudo apt-get install python3-pip

pip3 install virtualenv

python3 -m virtualenv -p python3 env –system-site-packages

source env/bin/activate

python -c 'import cv2; print(cv2.__version__)'

Create SwapFile:

sudo fallocate -l 4G /var/swapfile

sudo chmod 600 /var/swapfile

sudo mkswap /var/swapfile

sudo swapon /var/swapfile

sudo bash -c 'echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab’

Reboot your PC: sudo reboot

After rebooting check swap space by using this command: free -h

Install these Dependencies before installing OpenCV:

sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf“

sudo ldconfig

sudo apt-get install build-essential cmake git unzip pkg-config

sudo apt-get install libjpeg-dev libpng-dev libtiff-dev

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install libgtk2.0-dev libcanberra-gtk*

sudo apt-get install python3-dev python3-numpy python3-pip

sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev

sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev

sudo apt-get install libv4l-dev v4l-utils

sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

sudo apt-get install libavresample-dev libvorbis-dev libxine2-dev

sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev

sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev

sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev

sudo apt-get install liblapack-dev libeigen3-dev gfortran

sudo apt-get install libhdf5-dev protobuf-compiler

sudo apt-get install libprotobuf-dev libgoogle-glog-dev libgflags-dev

Download OpenCV:

cd ~

wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.1.zip

wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.1.zip

unzip opencv.zip

unzip opencv_contrib.zip

Now rename the directories. Type each command below, one after the other.

mv opencv-4.5.1 opencv

mv opencv_contrib-4.5.1 opencv_contrib

rm opencv.zip

rm opencv_contrib.zip

Lets build OpenCV now:

cd ~/opencv

mkdir build

cd build

copy and paste this entire block of commands below into your terminal.

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D EIGEN_INCLUDE_PATH=/usr/include/eigen3 -D WITH_OPENCL=OFF -D WITH_CUDA=ON -D CUDA_ARCH_BIN=5.3 -D CUDA_ARCH_PTX="" -D WITH_CUDNN=ON -D WITH_CUBLAS=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_NEON=ON -D WITH_QT=OFF -D WITH_OPENMP=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D WITH_TBB=ON -D BUILD_TBB=ON -D BUILD_TESTS=OFF -D WITH_EIGEN=ON -D WITH_V4L=ON -D WITH_LIBV4L=ON -D OPENCV_ENABLE_NONFREE=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_opencv_python3=TRUE -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_EXAMPLES=OFF ..

Build OpenCV. This command below will take a long time (around 2 hours), make -j4 # (make then space single dash and then j4)

Finish the install:

cd ~

sudo rm -r /usr/include/opencv4/opencv2

cd ~/opencv/build

sudo make install

sudo ldconfig

make clean

sudo apt-get update

Verify OpenCV Installation

#open python3 shell

python3

import cv2

cv2._version_

Install jtop, a system monitoring software for Jetson Nano.

cd ~

sudo -H pip3 install -U jetson-stats

sudo reboot

jtop

Test Your Camera on Jetson Nano:

Turn on your Jetson Nano.

Open a new terminal window, and type:

ls /dev/video0 #csi camera

ls /dev/video* # show you a list of cameras

Take a Photo:

nvgstcapture-1.0 –orientation=2 # for testing CSI camera

# V4L2 USB camera

nvgstcapture-1.0 –camsrc=0 –cap-dev-node=1

@rockatang2189
7 months ago

Hello, I met some problem when I tried to install dependencies. It showed a message said, "configuring incomplete, errors occurred!". How can I fix this issue?

@pifordtechnologiespvtltd5698
7 months ago

Lovely video content

@lazymusicc
7 months ago

Hello, on the file "info" of Jtop, i don't have the 4.5.1 version of OpenCV but the 4.1.1, and it's written "No" instead of "yes". Can you help me ? Maybe there is a step that i didn't do well, but which one ? Thanks

@arhamimran4999
7 months ago

This tutorial was very helpful and I was able to compile opencv. However the problem I am facing is that opencv is installed for python2 and not for python3. Any method to solve this?

@Aron-0-1
7 months ago

Hey @CodeWithAarohi, thank you for insightful video. I followed same steps. Unfortunately after it has completed i am getting an error of cv2 module being unavailable in my virtual ent. What fascinates me is that it was able to install the latest opencv for cuda. Do you have an idea how to go about this ?

@kailu8872
7 months ago

thank you very much!!!

@lazymusicc
7 months ago

Hello, I have some problem. On my jetson, it doesn't find packages (like python3-pip for exemple). Do you know why ?

@grantbarbone3789
7 months ago

Marry me, you saved me years of pain trying to download opencv correctly, fr fr all of the old tutorials were so un-updated that most of the lib files wouldn't install correctly, so opencv would never be fully operational. THANK YOU!!!!

@shashwatmahindroo
7 months ago

After reboot, the swapped memory gets reset and goes back to 1.9gb. I always need to run those 4 swap commands before starting. What's the solution to this?

@dakshayinialuri
7 months ago

Hello Mam, im getting an error cmake command the error is no cmake script
provided ,cmake error: problem processing arguments. aborting
what to do?
please help..

@abdullahmemon6908
7 months ago

I am following your video series, my task was to install archiconda and yolov5. I installed archiconda but in phase of yolov5. At the end , I need to make some project with jetson nano. Can you give me some ideas? And any flow that how to do it…

@strongwarrior0210
7 months ago

My pip is not installing what might be the error?

@abdullahmemon6908
7 months ago

Is this video in graphical mode or headless mode?

@vijaylaxmijain5717
7 months ago

HI Aarohi.. did all the steps you mentioned, but my jtop says openCV: 4.5.1 with CUDA: No, please suggest what to do

@user-hu6zr5ld1o
7 months ago

after i completed all the steps when i run jtop open cv : 4.5 with cuda : No. and also my cuda version is 11.4.315. what can i do for this?

@user-zp2rg6rw9p
7 months ago

hi mam ,
I installed python 3.8 and made it default for python

in python3.6 cv2 module in present of version 4.1.1

when i created virtual environment of python3.8 with –system-packages like as you are mention their cv2 module is not found
please guide me where i am doing wrong

@suryamohithmaddi2
7 months ago

how to reset the system mam please tell me, i want to reset everything and i wanna follow your videos…please help me out..

@user-is5vn8ie5v
7 months ago

Hi, I executed : sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf“

then the prompt became like this : >

is this correct ? or I did something wrong …. thank you for your hard work

@amanimurera
7 months ago

trying to increase swap file using your steps, now my Jetson Nano is not able to boot