Build OpenCV 4.6.4 with Cuda on Jetson Nano

Hi everybody!
jetson nano version : Jetpack 4.6.4
I am going to build opencv 4.1.1 with cuda on jetson nano 4G evaluation board.
and open cv version 4.1.1;
ı tyr this : GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano
The build was successful, but it appears as CUDA:No
please help

Hi,

Please try the below script but update the version to 4.1.1:

Thanks.

I got this error

Scanning dependencies of target opencv_videoio_plugins
[ 24%] Built target opencv_videoio_plugins
Scanning dependencies of target opencv_core_pch_dephelp
[ 24%] Building CXX object modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/util/internal/utility.cc.o
In file included from /home/tom07/Downloads/workspace/opencv-4.1.1/modules/core/src/precomp.hpp:55:0,
from /home/tom07/Downloads/workspace/opencv-4.1.1/release/modules/core/opencv_core_pch_dephelp.cxx:1:
/home/tom07/Downloads/workspace/opencv-4.1.1/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
# include <Eigen/Core>
^~~~~~~~~~~~
compilation terminated.
modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:2768: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/util/json_util.cc.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/separable_filter.cpp.o
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/util/message_differencer.cc.o
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/util/time_util.cc.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/sobel.cpp.o
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/util/type_resolver_util.cc.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/sub.cpp.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/sum.cpp.o
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/wire_format.cc.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/template_matching.cpp.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/threshold.cpp.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/warp_affine.cpp.o
[ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/wrappers.pb.cc.o
[ 24%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/warp_perspective.cpp.o
[ 24%] Built target carotene_objs
[ 24%] Linking CXX static library ../lib/liblibprotobuf.a
[ 24%] Built target libprotobuf
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
[sudo] password for tom07:
[ 0%] Built target gen-pkgconfig
[ 7%] Built target libwebp
[ 9%] Built target libjasper
[ 15%] Built target IlmImf
[ 19%] Built target libprotobuf
[ 19%] Built target quirc
[ 22%] Built target carotene_objs
Scanning dependencies of target tegra_hal
[ 23%] Linking CXX static library ../../lib/libtegra_hal.a
[ 23%] Built target tegra_hal
[ 24%] Built target ittnotify
[ 25%] Built target ade
[ 25%] Built target opencv_videoio_plugins
Scanning dependencies of target opencv_cudev
[ 25%] Building CXX object modules/cudev/CMakeFiles/opencv_cudev.dir/src/stub.cpp.o
[ 25%] Linking CXX shared library ../../lib/libopencv_cudev.so
[ 25%] Built target opencv_cudev
[ 25%] Building CXX object modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o
In file included from /home/tom07/Downloads/workspace/opencv-4.1.1/modules/core/src/precomp.hpp:55:0,
from /home/tom07/Downloads/workspace/opencv-4.1.1/release/modules/core/opencv_core_pch_dephelp.cxx:1:
/home/tom07/Downloads/workspace/opencv-4.1.1/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
# include <Eigen/Core>
^~~~~~~~~~~~
compilation terminated.
modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:2768: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
** Install opencv-4.1.1 successfully
** Bye :)

log
log.txt (56.5 KB)

I flashed Jetson, changed the file you suggested to 4.1.1 and ran it.

Hi,

Based on this error:

fatal error: Eigen/Core: No such file or directory

Please try to install the dependency.

    $ sudo apt install libeigen3-dev
    $ cd /usr/include
    $ sudo ln -sf eigen3/Eigen Eigen

Thanks.

hi i reset the sd card and applied the following file.

Log file is attached. But it shows as Cudnn:No.
And should I make a setting to run open cv on GPU. I am new to this code, thank you for your help.

--   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             53
--     NVIDIA PTX archs:
-- 
--   cuDNN:                         NO
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/tom07/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load

openCV_build.log (441.9 KB)

Hi,

cuDNN is used for neural network inference.
Based on your log, CUDA support is enabled.

--   NVIDIA CUDA:                   YES (ver 10.2, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             53
--     NVIDIA PTX archs:

Thanks.

That’s good to hear, it’s finally happened. But when I try to open the py file I attached, I get the following error.

net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
AttributeError: module 'cv2.dnn' has no attribute 'DNN_BACKEND_CUDA'

open cv version =4.1.1,
Python =3.6.9
weight file prepared and trained with custom dataset
real_time_yolo.py (2.5 KB)

I tried readNet and readNetFromDarknet the same error

You need OpenCV 4.2 or above to use “DNN_BACKEND_CUDA”.

https://github.com/AastaNV/JEP/blob/master/script/install_opencv4.5.0_Jetson.sh
I set it to 4.2.0 and built again, this time I get the attached error.

/Downloads/workspace/opencv-4.2.0/modules/dnn/src/dnn.cpp (1363) setUpNet DNN module was not built with CUDA backend; switching to CPU

General configuration for OpenCV 4.2.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /home/tom07/Downloads/workspace/opencv_contrib-4.2.0/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2023-09-12T08:52:21Z
    Host:                        Linux 4.9.253-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.5.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 -Wsuggest-override -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 -Wsuggest-override -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:         NO
    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 dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    python2 world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cvv hdf java js matlab ovis sfm ts viz
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI: 
    GTK+:                        YES (ver 3.22.30)
      GThread :                  YES (ver 2.56.4)
      GtkGlExt:                  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:                        build (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 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (57.107.100)
      avformat:                  YES (57.83.100)
      avutil:                    YES (55.78.100)
      swscale:                   YES (4.8.100)
      avresample:                NO
    GStreamer:                   YES (1.14.5)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            pthreads

  Trace:                         YES (with Intel ITT)

  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.2, CUFFT CUBLAS)
    NVIDIA GPU arch:             53 62 72
    NVIDIA PTX archs:

  cuDNN:                         NO

  OpenCL:                        YES (no extra features)
    Include path:                /home/tom07/Downloads/workspace/opencv-4.2.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.6.9)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.6m.so (ver 3.6.9)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.13.3)
    install path:                lib/python3.6/dist-packages/cv2/python-3.6

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /usr/local
-----------------------------------------------------------------

Hi,

As Mt.Hiker mentioned, if you want to use the OpenCV DNN function, you will need to build it with some extra flags.
For more details, please check below topic:

Thanks.

Why I am getting this errors:

Scanning dependencies of target tegra_hal
[ 27%] Linking CXX static library ../../lib/libtegra_hal.a
[ 27%] Built target tegra_hal
Scanning dependencies of target opencv_cudev
[ 27%] Building CXX object modules/cudev/CMakeFiles/opencv_cudev.dir/src/stub.cpp.o
[ 27%] Linking CXX shared library ../../lib/libopencv_cudev.so
/usr/bin/ld: cannot find -laarch64-linux-gnu
collect2: error: ld returned 1 exit status
modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:95: recipe for target 'lib/libopencv_cudev.so.4.2.0' failed
make[2]: *** [lib/libopencv_cudev.so.4.2.0] Error 1
CMakeFiles/Makefile2:2599: recipe for target 'modules/cudev/CMakeFiles/opencv_cudev.dir/all' failed
make[1]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 27%] Linking CXX static library ../lib/liblibprotobuf.a
[ 27%] Built target libprotobuf
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

real	4m29,689s
user	15m58,480s
sys	1m0,916s
Make did not build 
Retrying ... 
[  8%] Built target libwebp
[ 11%] Built target libjasper
[ 18%] Built target IlmImf
[ 22%] Built target libprotobuf
[ 22%] Built target quirc
[ 25%] Built target carotene_objs
[ 26%] Built target tegra_hal
[ 26%] Built target ittnotify
[ 27%] Built target ade
[ 27%] Built target opencv_videoio_plugins
[ 27%] Linking CXX shared library ../../lib/libopencv_cudev.so
/usr/bin/ld: cannot find -laarch64-linux-gnu
collect2: error: ld returned 1 exit status
modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:95: recipe for target 'lib/libopencv_cudev.so.4.2.0' failed
make[2]: *** [lib/libopencv_cudev.so.4.2.0] Error 1
CMakeFiles/Makefile2:2599: recipe for target 'modules/cudev/CMakeFiles/opencv_cudev.dir/all' failed
make[1]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
Make did not successfully build
Please fix issues and retry build

finaly Cmake:

time cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CUDNN_LIBRARY=/usr/lib/aarch64-linux-gnu/ \
      -D CUDNN_INCLUDE_DIR=/usr/include/ \
      -D CUDNN_VERSION=8.2 \
      -D WITH_CUDNN=ON \
      -D OPENCV_DNN_CUDA=ON \
      -D CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} \
      -D WITH_CUDA=ON \
      -D CUDA_ARCH_BIN=${ARCH_BIN} \
      -D CUDA_ARCH_PTX="" \
      -D CUDA_FAST_MATH=ON \
      -D WITH_CUBLAS=1 \
      -D WITH_LIBV4L=ON \
      -D WITH_V4L=ON \
      -D WITH_GSTREAMER=ON \
      -D WITH_GSTREAMER_0_10=OFF \
      -D WITH_QT=ON \
      -D BUILD_opencv_python2=OFF \
      -D BUILD_opencv_python3=ON \
      -D BUILD_TESTS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      $"PACKAGE_OPENCV" \
      ../

full sh file:
buildOpenCV.sh (7.3 KB)

Hi,

Do you run it on the Jetson platform?

 cannot find -laarch64-linux-gnu

The error indicates it cannot find the compiling tool.
Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.