How to install Opencv 4.0 on Jetson TX2 with jetpack 4.2

Hello,
I have successfully installed Jetpack 4.2 using the sdk on my jetson tx2. I was building the opecv 3.4 but it always stops at 47% giving the error as :

No rule to make target ‘/usr/lib/aarch64-linux-gnu/libGL.so’, needed by ‘lib/libopencv_cudev.so.3.4.1’. Stop. tx2

Can some one please help me solve this problem or help me build opecv 4.0

Thanks

sandeepkumarjangir0,

Did you see this libGL.so under that path?

Yes,the file exist under that path .!!

Please try to use these script.

1 Like

Hi sandeepkumarjangir07,

As WayneWWW proposed, I followed the link to the openCV installation files and have been able to install OpenCV 4.0.0 with the “install_opencv4.0.0_Nano.sh” on my Jetson TX2 by changing the architecture to 6.2. I had some issues with packages that were not too hard to fix so you should be able to do the same and have OpenCV 4.0.0 running on your TX2.

Bye :)

Thank you all for the reply. I re-flashed my TX2 with jetpack 4.2 and built the opencv 4 using the nano script. But my python 2 and 3 version of opencv has been downgraded from 3.3.0 to 3.2.0 instead upgrading it to 4.0. The binding for python in the script are ON but still couldn’t figure out how to update my opencv version of python 2 and 3 to 4.0. There were no errors during the build(some warning of course but nothing serious ). can you guys suggest something that might be wrong or something that could be done to make my python-opencv version to 4.0 ?

Hi Sandeep,

If I remember correctly, to install latest opencv-python, you should not use apt-get or any tools that can directly download the prebuilt library.

You will need to build it from opencv source by yourself. I think opencv forum or some external links should have such tutorial.

you are right WayneWWW but I am building the opencv from the source.
When I build opencv 3.4.0, I get the error No rule to make target ‘/usr/lib/aarch64-linux-gnu/libGL.so’, needed by ‘lib/libopencv_cudev.so.3.4.1’. Stop. tx2 and when i checked the libGL.so, the link is broken and there should be another libGL.so present in /usr/lib/aarch64-linux-gnu/tegra directory but its not there.

Then I started building the opencv 4.0, which does build properly without any errors but my python version shows the opencv version as 3.2.0.

I am trying to solve errors from either of the build but nothing is proving to be working. I have flashed my jetson once and do not want to do it again because flashing takes a lot of time and also building tensorflow and protobuf from source takes even more (not even including the opencv build :-p)

if you can help me with libGL.so file or give me a reason why build of opencv4.0 still shows version 3.2.0 that would be helpful.

regards

1 Like

When I build opencv 3.4.0, I get the error No rule to make target ‘/usr/lib/aarch64-linux-gnu/libGL.so’, needed by ‘lib/libopencv_cudev.so.3.4.1’. Stop. tx2 and when i checked the libGL.so, the link is broken and there should be another libGL.so present in /usr/lib/aarch64-linux-gnu/tegra directory but its not there.

Do you mean the default jetpack has a empty symlink for libGL.so? I will help check.

I don’t think opencv4.0 gives the 3.2 opencv-python. Are you sure you didn’t install it by using apt-get or something else?

Yes, there was no libGL.so so i re-flashed tx2 with 4.2 again and its present now. But instead of building Opencv 3.4.0 , i tried again to install opecv 4.0 and below is the log after the build and opencv version that it shows.

Setting up libdapclient6v5:arm64 (3.19.1-2build1) …
Setting up gdal-data (2.2.3+dfsg-2) …
Setting up libgeos-c1v5:arm64 (3.6.2-1build2) …
Setting up libpq5:arm64 (10.7-0ubuntu0.18.04.1) …
Processing triggers for libc-bin (2.27-3ubuntu1) …
Setting up libgdcm2.8:arm64 (2.8.4-1build2) …
Setting up libopencv-ml3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libarpack2:arm64 (3.5.0+real-2) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …
Setting up libopencv-imgproc3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-flann3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libtcl8.6:arm64 (8.6.8+dfsg-3) …
Setting up libhdf4-0-alt (4.2.13-2) …
Setting up libopencv-video3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libxerces-c3.2:arm64 (3.2.0+debian-2) …
Setting up liburiparser1:arm64 (0.8.4-1) …
Setting up libsz2:arm64 (0.3.2-2) …
Setting up proj-data (4.9.3-2) …
Setting up libgl2ps1.4 (1.4.0+dfsg1-1) …
Setting up libopencv-photo3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libproj12:arm64 (4.9.3-2) …
Setting up libhdf5-openmpi-100:arm64 (1.10.0-patch1+docs-4) …
Setting up libhdf5-100:arm64 (1.10.0-patch1+docs-4) …
Setting up libtk8.6:arm64 (8.6.8-4) …
Setting up libtesseract4 (4.00~git2288-10f4998a-2) …
Setting up libkmlbase1:arm64 (1.3.0-5) …
Setting up libarmadillo8 (1:8.400.0+dfsg-2) …
Setting up libogdi3.2 (3.2.0+ds-2) …
Setting up proj-bin (4.9.3-2) …
Setting up libgeotiff2:arm64 (1.4.2-2build1) …
Setting up libnetcdf13:arm64 (1:4.6.0-2build1) …
Setting up libopencv-shape3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libspatialite7:arm64 (4.3.0a-5build1) …
Setting up libkmldom1:arm64 (1.3.0-5) …
Setting up libnetcdf-c++4 (4.2-8) …
Setting up libkmlengine1:arm64 (1.3.0-5) …
Setting up odbcinst1debian2:arm64 (2.3.4-1.1ubuntu3) …
Setting up odbcinst (2.3.4-1.1ubuntu3) …
Setting up libgdal20 (2.2.3+dfsg-2) …
Setting up libopencv-imgcodecs3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libvtk6.3 (6.3.0+dfsg1-11build1) …
Setting up libopencv-videoio3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-viz3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-superres3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-highgui3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-objdetect3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-features2d3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-calib3d3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
Setting up libopencv-stitching3.2:arm64 (3.2.0+dfsg-4ubuntu0.1) …
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:~/JEP/script$ clear

nvidia@nvidia:~/JEP/script$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import cv2
cv2.version
‘3.2.0’

I think its not installing properly due memory limitations but i have approx 16 gb free on my tx2, so it might be ram issue but still not sure whats causing this !!

Setting up python3-opencv (3.2.0+dfsg-4ubuntu0.1) ...
Setting up python-opencv (3.2.0+dfsg-4ubuntu0.1) ..

Looks like it is installing 3.2.0

#!/bin/bash

Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.

NVIDIA Corporation and its licensors retain all intellectual property

and proprietary rights in and to this software, related documentation

and any modifications thereto. Any use, reproduction, disclosure or

distribution of this software and related documentation without an express

license agreement from NVIDIA Corporation is strictly prohibited.

if [ “$#” -ne 1 ]; then
echo “Usage: $0 ”
exit
fi
folder=“$1”
user=“nvidia”
passwd=“nvidia”

echo “** Install requirement”
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python3.6-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl
sudo apt-get update

echo “** Download opencv-4.0.0”
cd $folder
curl -L https://github.com/opencv/opencv/archive/4.0.0.zip -o opencv-4.0.0.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.0.0.zip -o opencv_contrib-4.0.0.zip
unzip opencv-4.0.0.zip
unzip opencv_contrib-4.0.0.zip
cd opencv-4.0.0/

echo “** Building…”
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN=“6.2” -D CUDA_ARCH_PTX=“” -D OPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib-4.0.0/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local …
make -j3
sudo make install
sudo apt-get install -y python-opencv python3-opencv

echo “** Install opencv-4.0.0 successfully”

This is the script from above used to build.

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

Please do not add these.

I’m working on multi-class object detection with tracking on Jetson Nano.

I’d like to use the tracking libraries in opencv.

I successfully installed opencv using WayneWWW’s script:
[url]https://github.com/AastaNV/JEP/tree/master/script[/url]

However no trackers (ex: cv2.TrackerMOSSE_create) were installed.

Could someone kindly help me install opencv’s object trackers or suggest a replacement object tracker for the Jetson Nano?

1 Like

Hi silasv38em,

Please file your issue into Jetson Nano forum: https://devtalk.nvidia.com/default/board/371/jetson-nano/

hello , i am trying to install opencv and opencv-contrib as i wanted to use the “xfeatures2d” from the contrib/modules but when i try to compile the opencv by using the command “make -j4” after 34% it stops and the jetson runs out of memory. I have 5 GB of free space in the jetson tx2 .
can anyone help me out ?

Thank you.

I cannot tell you what is the necessary disk size for installing opencv, but sometimes the makefile will create too much file simultaneously when you compile with -j option. You could try to use -j2 with slower build time or just some external storage(usb/sdcard).

Do i have to flash jetpack 4.2 if i want to install opencv 4.0?

.

.