Installing OpenCV 3.4 in Jetson nano

Hi

I can see that opencv comes pre installed with jetson nano but the installed version is 3.3. What if I want to upgrade it to 3.4 or may be the latest version 4.0.

Normally on my laptop if I do pip3 install opencv-python, it installs the latest version but thats not the case on jetson nano.

What steps to follow to install latest version.?

Thanks

For curiosity sake I am trying to build master from source right now. So far, so good. It’s gonna take a while and there were a lot of dependencies to track dow, but it’s building:

base build instructions

extra cmake flags (cmake -D SOMTHING=SOMEVAL) used to enable CUDA support:

WITH_CUDA=ON
CUDA_FAST_MATH=1

Gives (on my system, with the dependencies I have installed):

-- General configuration for OpenCV 4.1.0-dev =====================================
--   Version control:               4.1.0-86-g076ee65c8
-- 
--   Extra modules:
--     Location (extra):            /tmp/build_opencv/opencv_contrib/modules
--     Version control (extra):     4.1.0-24-g8049208c
-- 
--   Platform:
--     Timestamp:                   2019-04-30T20:12:45Z
--     Host:                        Linux 4.9.140-tegra aarch64
--     CMake:                       3.10.2
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:                    NEON FP16
--       required:                  NEON
--       disabled:                  VFPV3
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/c++  (ver 7.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections  
--     Linker flags (Debug):        -Wl,--gc-sections  
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cvv hdf java js matlab ovis sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
--     GTK+:                        NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0x020e)
--     PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.34)
--     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   YES (57.107.100)
--       avformat:                  YES (57.83.100)
--       avutil:                    YES (55.78.100)
--       swscale:                   YES (4.8.100)
--       avresample:                YES (3.7.0)
--     GStreamer:                   YES (1.14.1)
--     v4l/v4l2:                    YES (linux/videodev2.h)
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (built-in)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.3.4)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
-- 
--   NVIDIA CUDA:                   YES (ver 10.0, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             53
--     NVIDIA PTX archs:
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /tmp/build_opencv/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load

Just started the build. It’s going to take a while. I will update on success or failure.

Hi mdegans,

good luck, we are looking forward to your update. ;)

Hi Flaty,

It made it to 15% and then I cancelled it because I realised I forgot to update the install prefix. It’s going faster than I thought. This thing has more horsepower than a Pi for sure. It’s back up to 3% and chugging along.

Sounds good, do you use the barrel jack power supply, for the full power?

The barrel jack for sure. I couldn’t find a micro-usb that would power it and survive any stress testing. It would boot, install stuff, update, etc, but using the GPU would be too much.

Do you use face recognition with openCV?
On my Raspberry Pi3 both works fine, but with the Nano i have trouble to install face recognition with its dependencies dlib in particular.

I haven’t tried face recognition with opencv. Is some module failing to build? “face” is scheduled to be built for me but the build hasn’t gotten to that module yet. Right now it’s on modules/cudev.

So, I’ve written a small script to (hopefully) build opencv 4.1.0 on a barebones system. It should probably be tested on a newly flashed image (both so as not to risk your data, and to ensure it works from scratch). Volunteers are very much welcome. I will eventually test it but can’t now as my Nano is currently compiling.

edit: script is now located on github so you can clone it.

Hi mdegans,

Did you get it working on the nano. Which OpenCV version is installed now.? Is this the same script you followed for installation. How much time it took to complete.

Hi Flaty

On raspberry pi, face_recognition will work fine but overall performance will be low as it do not have good cpu/gpu. On jetson nano, I installed the face_recognition and dlib, but the library was only detecting faces and not recognizing them because of the issues with dlib library.
If you debug the code, you will see that dlib returns nan nan values of matrix which in actual should be some values of the enconding. This is why only detection works but not recognizing. Follow this thread:

https://devtalk.nvidia.com/default/topic/1049660/jetson-nano/issues-with-dlib-library/

99% complete. I haven’t run tests yet or anything.

The version I built from is master, however the script is pinned to 4.1.0. It took about 5-6 hours to complete**. If it complains about any missing dependencies or the script fails to execute to completion, please post the results here and I’ll modify it. Tomorrow I will do my own testings on a freshly flashed micro-sd.

** this assumes 99% is really 99% please keep tuned in to this thread

Edit: “make install” took nearly as long as the make, so installing a new version of opencv from source is probably an overnight kind of thing on the device itself.

Hi mdegans

Thanks for the update. You used the script you mentioned in your post #9.?

I remember I was following this script for OpenCV4.0 https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.0.0_Nano.sh

and at 99% it got stuck and jetson nano also got freezed for sometime and wasnt responding, probably because I was using microUSB. Is this the same for you.?

No, It’s hit 100 now. right this second it’s

[100%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o

I gave up after half an hour of trying to power the thing over micro-usb and ordered a 5v 4a barrel type power supply off Amazon. YMMV, the thing was 7$, but so far so good, (knock on laminated particleboard!)

Okay please keep us posted once you install it successfully. I will try your same script from post #9 and will update you.

Thanks

Ok. If it fails, it should’t take hours to fail. I will probably end it here for the day. Please post any results here.

[100%] Built target opencv_version
mdegans@jetson-nano-64gb-initial:/tmp/build_opencv/opencv/build$

woo hoo

Now doing “make install” and making sure that works, I’m personally doing a user install in ~/.local while the script installs opencv systemwide. It shouldn’t take much more time but I’m gonna check back on it tomorrow.

Hi mdegans

Did you tested the Opencv version.? Is it 4.0.?

Thanks

Hi mdegans

You scripts shows error for one package libjasper-dev. How did you installed it.?

Thanks