OpenCV, CUDA, Python with Jetson Nano

Hello,

i made a stand-alone sky survey system using an astronomy camera and raspberry pi. I wrote software with Python language and OpenCV library (mainly).

I am considering purchasing Jetson Nano board in order to replace raspberry pi 3 B+ board. Raspberry board is a bit weak to perform real time video treatments (useful to manage noise, contrast, light pollution in the sky and so on).

My problem is that i would like to keep my software without changing all the code.

I have read things about GPU use. I am not really aware in GPU but it seems that :

  • Jetson Nano GPU does not support OpenCV acceleration (through opencl) with Python
  • i have to use PyCuda or Numba to use GPU acceleration, that is to say i can’t use opencv with Python
  • i must rewrite my software to be able to use Jetson Nano GPU capabilities

To resume, if i use Jetson Nano board, i can’t get an easy way to use my software (Python and opencv routines) with this board.

Am i correct ?

Many thanks for your highlights.

Alain

Does anyone have an idea how to install opencl? To host PC? opencl.torch?

Hi,

Replied your question inline:

Jetson Nano GPU does not support OpenCV acceleration (through opencl) with Python
Our default OpenCV do support GPU acceleration.
The common issue is there are some features havn’t be enabled.
(This feature often requires third-party library installed)

To overcome this, you can build it from source.
We also provide an automatically building script here:
https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.0.0_Nano.sh

i have to use PyCuda or Numba to use GPU acceleration, that is to say i can’t use opencv with Python
PyCuda and Numba is working on Jetson:
https://devtalk.nvidia.com/default/topic/1027116/jetson-tx2/installing-pycuda-on-jetson-tx2/
https://devtalk.nvidia.com/default/topic/1028001/jetson-tx1/numba-package-in-python-on-jetson-/

i must rewrite my software to be able to use Jetson Nano GPU capabilities
For C++ app, you will need to recompile it with Nano architecture(sm=53).
But since your source is python-based, it won’t be an issue for you.

The CUDA toolkit installed by JetPack already add the support for Nano.

Thanks.

and any idea on how to install opencl?

Hello,

many thanks for your reply.

So, Jetson supports opencv with GPU acceleration.

Do you provide such opencv for Python language ?

As i said, i am not aware at all with all those libraries but from what i understand, the opencv library you talk about can be use with C++ but won’t work with Python.

Sorry to bother you but it’s important for my final choice.

Alain

there were some “opencv for Python language” solution as per JetsonHacks ‘review’ that you can find at his website, as far as I remember. I did not try though.

Many thanks Andrey.

references:


https://devtalk.nvidia.com/default/topic/1049308/jetson-nano/how-do-i-capture-an-image-using-the-rp-v2-0-camera-in-opencv-on-the-nano-/

Hello Andrey,

thx for the link.

I have read some informations about Jetson Nano and i am a bit disappointed. It’s an interesting card if you use C++ and CUDA but as i only plan to use Python, Jetson Nano is not interesting at all.

I must admit that Python is not the best choice but for non professional, it’s a simple language and it allow to do very interesting things with small development time (and i have few time for coding).

Concerning my main purpose, that is to say making a stand alone sky survey system, i choose to use my time left to make tests with cameras/lens and try different kind of real time filters (like denoise, contrast, sharpen etc.) using very simple programming language like Python instead of spending many time with C++ and CUDA (opencv provides very useful routines and it’s a totally loss of time to rewrite them with CUDA).

In fact, i am amazed Nvidia is unable to use opencv with Python with hardware acceleration. We loose all the work provided by scientific open software. Trying to promote CUDA and only CUDA is a big mistake.

Anyway, Jetson Nano is not the good choice for me. I will look for an other board with at least a better CPU if i must forget GPU hardware acceleration.

Alain

There is a lot of misinformation in here.

1st is Opencl is pretty crappy performance wise. Your much better off with intel optimization or even better with cuda.

Opencv doesn’t come on the nano by default compiled with cuda optimization enabled. Just compile it. All you need to do is add swap and run the excellent script. Done.

If you really want to go fast use python with keras , tensorflow, and tensorrt.

Remember this is a $99 piece of hardware. It is pretty amazing. Of course you can always spend a couple of thousand to get Opencl to go pretty fast. I also want to point out this is only 10 Watt. Even mediocre hardware will easily be 500 Watt. It all depends on what you are trying to accomplish. I also can’t agree more with wanting to use python.

Hello,

i wonder why nvidia does not provide compiled opencv with cuda optimizations. Quite a mystery.

Anyway, my purpose is to make astronomy pictures treatment, not deep learning. OpenCV is useful for me.

Also my purpose is not to spend months trying to write program using C++ and trying to understand CUDA.

Reading your post, i realize i am stupid so i will try to find very easy solutions for stupid guy like me.

Jetson Nano is too complicated. It’s a tool for wise guys like you.

Have a nice day.

Alain

1 Like

Hi, easybob

Sorry for the late reply. I hope it is not too late.

The default OpenCV included in the JetPack does have CUDA optimization. (including python)
But some extra module depends on the third-party library we are not able to make them into the prebuilt.

If your use case is image-based rather than a live camera, you don’t need to update your openCV.
Thanks.

Many thanks for your reply.

For my specific use, i make real time treatments during camera acquisition.

I will continue to evaluate Jetson Nano for my use and i will choose my definitive board during September.

I will have time to understand better how Jetson Nano can be a good solution for me.

BR

Alain

Hi,

In case you don’t know:

We have an automatical script for installing OpenCV4.0 with GStreamer on Nano.
https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.0.0_Nano.sh

You can get the enhanced OpenCV installed with this command:

./install_opencv4.0.0_Nano.sh [folder you want to install OpenCV]

Thanks.

I successfully added neon and the non-free options to the openCV make file like so

cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.0.0/modules -D WITH_GSTREAMER=ON -D ENABLE_NEON=ON -D OPENCV_ENABLE_NONFREE=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 ..

However, including this option

-D ENABLE_VFPV3=ON

fails. The errors are numerous so I wont include them here. I was just trying to optimize the opencv build as outlined here: https://www.theimpossiblecode.com/blog/build-faster-opencv-raspberry-pi3/ and here: https://www.pyimagesearch.com/2017/10/09/optimizing-opencv-on-the-raspberry-pi/

during make i am getting these warnings:

/home/stefan/opencv-4.0.0/3rdparty/carotene/src/resize.cpp: In function ‘bool carotene_o4t::isResizeLinearOpenCVSupported(const carotene_o4t::Size2D&, const carotene_o4t::Size2D&, carotene_o4t::u32)’:
/home/stefan/opencv-4.0.0/3rdparty/carotene/src/resize.cpp:104:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
         if (ssize.width >= 2
         ^~
/home/stefan/opencv-4.0.0/3rdparty/carotene/src/resize.cpp:112:5: note: here
     default:
     ^~~~~~~

and

[ 34%] Building CXX object modules/dpm/CMakeFiles/opencv_dpm_pch_dephelp.dir/opencv_dpm_pch_dephelp.cxx.o
In file included from /home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy.hpp:50:0,
                 from /home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/src/precomp.hpp:57,
                 from /home/stefan/opencv-4.0.0/build/modules/cudalegacy/opencv_cudalegacy_pch_dephelp.cxx:1:
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp: In member function ‘NCVStatus HaarFeature64::setRect(Ncv32u, Ncv32u, Ncv32u, Ncv32u, Ncv32u, Ncv32u)’:
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:87:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->x = (Ncv8u)rectX;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:88:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->y = (Ncv8u)rectY;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:89:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->width = (Ncv8u)rectWidth;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:90:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->height = (Ncv8u)rectHeight;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp: In member function ‘void HaarFeature64::getRect(Ncv32u*, Ncv32u*, Ncv32u*, Ncv32u*)’:
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:102:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         NcvRect8u tmpRect = *(NcvRect8u*)(&this->_ui2.x);
                                                        ^
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:102:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
In file included from /home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy.hpp:50:0,
                 from /home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/private.hpp:57,
                 from /home/stefan/opencv_contrib-4.0.0/modules/cudaobjdetect/src/precomp.hpp:59,
                 from /home/stefan/opencv-4.0.0/build/modules/cudaobjdetect/opencv_cudaobjdetect_pch_dephelp.cxx:1:
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp: In member function ‘NCVStatus HaarFeature64::setRect(Ncv32u, Ncv32u, Ncv32u, Ncv32u, Ncv32u, Ncv32u)’:
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:87:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->x = (Ncv8u)rectX;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:88:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->y = (Ncv8u)rectY;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:89:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->width = (Ncv8u)rectWidth;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:90:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         ((NcvRect8u*)&(this->_ui2.x))->height = (Ncv8u)rectHeight;
                                      ^~
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp: In member function ‘void HaarFeature64::getRect(Ncv32u*, Ncv32u*, Ncv32u*, Ncv32u*)’:
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:102:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
         NcvRect8u tmpRect = *(NcvRect8u*)(&this->_ui2.x);
                                                        ^
/home/stefan/opencv_contrib-4.0.0/modules/cudalegacy/include/opencv2/cudalegacy/NCVHaarObjectDetection.hpp:102:56: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

and several other locations with this last one as well

34%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab_pch_dephelp.dir/opencv_videostab_pch_dephelp.cxx.o

Also, cmake is not finding atlas and open blas

-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR)

but i did install it like so:

$sudo apt-get install libatlas-base-dev gfortran
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libatlas-base-dev is already the newest version (3.10.3-5).
gfortran is already the newest version (4:7.3.0-3ubuntu2.1).
The following package was automatically installed and is no longer required:
  libllvm6.0
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

as for openBLAS, I dont know if i should bother

Hi,

Please install openblas with this command:

sudo apt-get install libopenblas-dev

After installation, you can find the libopenblas.so in the /usr/lib/aarch64-linux-gnu/ folder:

nvidia@nano:~$ ll /usr/lib/aarch64-linux-gnu/libopenblas*
lrwxrwxrwx 1 root root       28  九  19  2017 /usr/lib/aarch64-linux-gnu/libopenblas.a -> libopenblas_armv8p-r0.2.20.a
-rw-r--r-- 1 root root 13547478  九  19  2017 /usr/lib/aarch64-linux-gnu/libopenblas_armv8p-r0.2.20.a
-rw-r--r-- 1 root root  6962424  九  19  2017 /usr/lib/aarch64-linux-gnu/libopenblas_armv8p-r0.2.20.so
lrwxrwxrwx 1 root root       29  九  19  2017 /usr/lib/aarch64-linux-gnu/libopenblas.so -> libopenblas_armv8p-r0.2.20.so
lrwxrwxrwx 1 root root       29  九  19  2017 /usr/lib/aarch64-linux-gnu/libopenblas.so.0 -> libopenblas_armv8p-r0.2.20.so

Thanks.

Hi, I just downloaded the installation script mentioned in the first posts, and ran it to the end successfully. But I’m not able to do run any imports from python3. Does these installation instructions include the compilation of the python bindings as well? If so, how do I reference them?

Thank you.
Eduardo

you may perform steps manually and use the most recent opencv version and you will have to check cmake … outputs to confirm they point to the python and numpy files.