OpenCV CUDA support?

Hi,

I’ve recently started using a Jetson AGX Xavier Dev Kit, I notice that the SDK Manager on the Host PC installs OpenCV on the Xavier. But when I run the command:

print(cv2.getBuildInformtion())

It confirms that it is the latest build of OpenCV 4.1.1 but does not confirm whether it is natively installed with CUDA support. I think it would be counter intuitive for it to not, considering. But I would like confirmation.

Hi mff745:
Our official OpenCV package(installed from sdkmanager ) does support CUDA. release in each JetPack does, you should try to rebuild the opencv + cuda from source.
try the script from https://github.com/AastaNV/JEP/tree/master/script to install

Thanks for your reply, I have now installed the latest openCV build with CUDA support on my Xavier.

Similar situation here I have installed JetPack 4.4 DP on Xavier AGX using the SDK manager. I’m missing cudawarping.hpp - which I assume should be found in /usr/include/opencv4/opencv2. Any idea why this is not install ? As you pointed out OpenCV comes with CUDA support - should than cudawarping.hpp not have been installed? Do I’m missing something?

I have resolved this issue. You do have to purge the OpenCV install that the SDK Manager installs as it is installs a version without CUDA enabled (which seems counter intuitive). You can do this via:

sudo apt-get -y purge libopencv-dev libopencv-python libopencv-samples libopencv*
sudo apt-get -y update

Then follow the usual steps to install OpenCV with CUDA enabled.

1 Like

I removed all versions of opencv on my system and than reinstalled opencv 4.1.1 using the SDK manager. I can confirm the header files for CUDA support in opencv don’t get installed. I also looked at which files are installed by SDK manager in the opencv dev package using dpkg -L libopencv-dev - opencv2/cudawarping.hpp is missing:

I’m sure that NVIDIA does not install opencv 4.1.1 with CUDA support enabled - as stated in the release notes for Jetpack 4.4 DP- this is a bug - hope this gets fixed in the final release of Jetpack 4.4. …

/usr
/usr/bin
/usr/bin/opencv_annotation
/usr/bin/opencv_interactive-calibration
/usr/bin/opencv_version
/usr/bin/opencv_visualisation
/usr/include
/usr/include/opencv4
/usr/include/opencv4/opencv2
/usr/include/opencv4/opencv2/calib3d
/usr/include/opencv4/opencv2/calib3d.hpp
/usr/include/opencv4/opencv2/calib3d/calib3d.hpp
/usr/include/opencv4/opencv2/calib3d/calib3d_c.h
/usr/include/opencv4/opencv2/core
/usr/include/opencv4/opencv2/core.hpp
/usr/include/opencv4/opencv2/core/affine.hpp
/usr/include/opencv4/opencv2/core/async.hpp
/usr/include/opencv4/opencv2/core/base.hpp
/usr/include/opencv4/opencv2/core/bindings_utils.hpp
/usr/include/opencv4/opencv2/core/bufferpool.hpp
/usr/include/opencv4/opencv2/core/check.hpp
/usr/include/opencv4/opencv2/core/core.hpp
/usr/include/opencv4/opencv2/core/core_c.h
/usr/include/opencv4/opencv2/core/cuda
/usr/include/opencv4/opencv2/core/cuda.hpp
/usr/include/opencv4/opencv2/core/cuda.inl.hpp
/usr/include/opencv4/opencv2/core/cuda/block.hpp
/usr/include/opencv4/opencv2/core/cuda/border_interpolate.hpp
/usr/include/opencv4/opencv2/core/cuda/color.hpp
/usr/include/opencv4/opencv2/core/cuda/common.hpp
/usr/include/opencv4/opencv2/core/cuda/datamov_utils.hpp
/usr/include/opencv4/opencv2/core/cuda/detail
/usr/include/opencv4/opencv2/core/cuda/detail/color_detail.hpp
/usr/include/opencv4/opencv2/core/cuda/detail/reduce.hpp
/usr/include/opencv4/opencv2/core/cuda/detail/reduce_key_val.hpp
/usr/include/opencv4/opencv2/core/cuda/detail/transform_detail.hpp
/usr/include/opencv4/opencv2/core/cuda/detail/type_traits_detail.hpp
/usr/include/opencv4/opencv2/core/cuda/detail/vec_distance_detail.hpp
/usr/include/opencv4/opencv2/core/cuda/dynamic_smem.hpp
/usr/include/opencv4/opencv2/core/cuda/emulation.hpp
/usr/include/opencv4/opencv2/core/cuda/filters.hpp
/usr/include/opencv4/opencv2/core/cuda/funcattrib.hpp
/usr/include/opencv4/opencv2/core/cuda/functional.hpp
/usr/include/opencv4/opencv2/core/cuda/limits.hpp
/usr/include/opencv4/opencv2/core/cuda/reduce.hpp
/usr/include/opencv4/opencv2/core/cuda/saturate_cast.hpp
/usr/include/opencv4/opencv2/core/cuda/scan.hpp
/usr/include/opencv4/opencv2/core/cuda/simd_functions.hpp
/usr/include/opencv4/opencv2/core/cuda/transform.hpp
/usr/include/opencv4/opencv2/core/cuda/type_traits.hpp
/usr/include/opencv4/opencv2/core/cuda/utility.hpp
/usr/include/opencv4/opencv2/core/cuda/vec_distance.hpp
/usr/include/opencv4/opencv2/core/cuda/vec_math.hpp
/usr/include/opencv4/opencv2/core/cuda/vec_traits.hpp
/usr/include/opencv4/opencv2/core/cuda/warp.hpp
/usr/include/opencv4/opencv2/core/cuda/warp_reduce.hpp
/usr/include/opencv4/opencv2/core/cuda/warp_shuffle.hpp
/usr/include/opencv4/opencv2/core/cuda_stream_accessor.hpp
/usr/include/opencv4/opencv2/core/cuda_types.hpp
/usr/include/opencv4/opencv2/core/cv_cpu_dispatch.h
/usr/include/opencv4/opencv2/core/cv_cpu_helper.h
/usr/include/opencv4/opencv2/core/cvdef.h
/usr/include/opencv4/opencv2/core/cvstd.hpp
/usr/include/opencv4/opencv2/core/cvstd.inl.hpp
/usr/include/opencv4/opencv2/core/cvstd_wrapper.hpp
/usr/include/opencv4/opencv2/core/detail
/usr/include/opencv4/opencv2/core/detail/async_promise.hpp
/usr/include/opencv4/opencv2/core/detail/exception_ptr.hpp
/usr/include/opencv4/opencv2/core/directx.hpp
/usr/include/opencv4/opencv2/core/eigen.hpp
/usr/include/opencv4/opencv2/core/fast_math.hpp
/usr/include/opencv4/opencv2/core/hal
/usr/include/opencv4/opencv2/core/hal/hal.hpp
/usr/include/opencv4/opencv2/core/hal/interface.h
/usr/include/opencv4/opencv2/core/hal/intrin.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_avx.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_avx512.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_cpp.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_forward.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_neon.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_sse.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_sse_em.hpp
/usr/include/opencv4/opencv2/core/hal/intrin_vsx.hpp
/usr/include/opencv4/opencv2/core/mat.hpp
/usr/include/opencv4/opencv2/core/mat.inl.hpp
/usr/include/opencv4/opencv2/core/matx.hpp
/usr/include/opencv4/opencv2/core/neon_utils.hpp
/usr/include/opencv4/opencv2/core/ocl.hpp
/usr/include/opencv4/opencv2/core/ocl_genbase.hpp
/usr/include/opencv4/opencv2/core/opencl
/usr/include/opencv4/opencv2/core/opencl/ocl_defs.hpp
/usr/include/opencv4/opencv2/core/opencl/opencl_info.hpp
/usr/include/opencv4/opencv2/core/opencl/opencl_svm.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdblas.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdfft.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_core.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_gl.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_20.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp
/usr/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp
/usr/include/opencv4/opencv2/core/opengl.hpp
/usr/include/opencv4/opencv2/core/operations.hpp
/usr/include/opencv4/opencv2/core/optim.hpp
/usr/include/opencv4/opencv2/core/ovx.hpp
/usr/include/opencv4/opencv2/core/persistence.hpp
/usr/include/opencv4/opencv2/core/saturate.hpp
/usr/include/opencv4/opencv2/core/simd_intrinsics.hpp
/usr/include/opencv4/opencv2/core/softfloat.hpp
/usr/include/opencv4/opencv2/core/sse_utils.hpp
/usr/include/opencv4/opencv2/core/traits.hpp
/usr/include/opencv4/opencv2/core/types.hpp
/usr/include/opencv4/opencv2/core/types_c.h
/usr/include/opencv4/opencv2/core/utility.hpp
/usr/include/opencv4/opencv2/core/utils
/usr/include/opencv4/opencv2/core/utils/allocator_stats.hpp
/usr/include/opencv4/opencv2/core/utils/allocator_stats.impl.hpp
/usr/include/opencv4/opencv2/core/utils/filesystem.hpp
/usr/include/opencv4/opencv2/core/utils/logger.defines.hpp
/usr/include/opencv4/opencv2/core/utils/logger.hpp
/usr/include/opencv4/opencv2/core/utils/logtag.hpp
/usr/include/opencv4/opencv2/core/utils/trace.hpp
/usr/include/opencv4/opencv2/core/va_intel.hpp
/usr/include/opencv4/opencv2/core/version.hpp
/usr/include/opencv4/opencv2/core/vsx_utils.hpp
/usr/include/opencv4/opencv2/cvconfig.h
/usr/include/opencv4/opencv2/dnn
/usr/include/opencv4/opencv2/dnn.hpp
/usr/include/opencv4/opencv2/dnn/all_layers.hpp
/usr/include/opencv4/opencv2/dnn/dict.hpp
/usr/include/opencv4/opencv2/dnn/dnn.hpp
/usr/include/opencv4/opencv2/dnn/dnn.inl.hpp
/usr/include/opencv4/opencv2/dnn/layer.details.hpp
/usr/include/opencv4/opencv2/dnn/layer.hpp
/usr/include/opencv4/opencv2/dnn/shape_utils.hpp
/usr/include/opencv4/opencv2/dnn/utils
/usr/include/opencv4/opencv2/dnn/utils/inference_engine.hpp
/usr/include/opencv4/opencv2/dnn/version.hpp
/usr/include/opencv4/opencv2/features2d
/usr/include/opencv4/opencv2/features2d.hpp
/usr/include/opencv4/opencv2/features2d/features2d.hpp
/usr/include/opencv4/opencv2/features2d/hal
/usr/include/opencv4/opencv2/features2d/hal/interface.h
/usr/include/opencv4/opencv2/flann
/usr/include/opencv4/opencv2/flann.hpp
/usr/include/opencv4/opencv2/flann/all_indices.h
/usr/include/opencv4/opencv2/flann/allocator.h
/usr/include/opencv4/opencv2/flann/any.h
/usr/include/opencv4/opencv2/flann/autotuned_index.h
/usr/include/opencv4/opencv2/flann/composite_index.h
/usr/include/opencv4/opencv2/flann/config.h
/usr/include/opencv4/opencv2/flann/defines.h
/usr/include/opencv4/opencv2/flann/dist.h
/usr/include/opencv4/opencv2/flann/dummy.h
/usr/include/opencv4/opencv2/flann/dynamic_bitset.h
/usr/include/opencv4/opencv2/flann/flann.hpp
/usr/include/opencv4/opencv2/flann/flann_base.hpp
/usr/include/opencv4/opencv2/flann/general.h
/usr/include/opencv4/opencv2/flann/ground_truth.h
/usr/include/opencv4/opencv2/flann/heap.h
/usr/include/opencv4/opencv2/flann/hierarchical_clustering_index.h
/usr/include/opencv4/opencv2/flann/index_testing.h
/usr/include/opencv4/opencv2/flann/kdtree_index.h
/usr/include/opencv4/opencv2/flann/kdtree_single_index.h
/usr/include/opencv4/opencv2/flann/kmeans_index.h
/usr/include/opencv4/opencv2/flann/linear_index.h
/usr/include/opencv4/opencv2/flann/logger.h
/usr/include/opencv4/opencv2/flann/lsh_index.h
/usr/include/opencv4/opencv2/flann/lsh_table.h
/usr/include/opencv4/opencv2/flann/matrix.h
/usr/include/opencv4/opencv2/flann/miniflann.hpp
/usr/include/opencv4/opencv2/flann/nn_index.h
/usr/include/opencv4/opencv2/flann/object_factory.h
/usr/include/opencv4/opencv2/flann/params.h
/usr/include/opencv4/opencv2/flann/random.h
/usr/include/opencv4/opencv2/flann/result_set.h
/usr/include/opencv4/opencv2/flann/sampling.h
/usr/include/opencv4/opencv2/flann/saving.h
/usr/include/opencv4/opencv2/flann/simplex_downhill.h
/usr/include/opencv4/opencv2/flann/timer.h
/usr/include/opencv4/opencv2/gapi
/usr/include/opencv4/opencv2/gapi.hpp
/usr/include/opencv4/opencv2/gapi/core.hpp
/usr/include/opencv4/opencv2/gapi/cpu
/usr/include/opencv4/opencv2/gapi/cpu/core.hpp
/usr/include/opencv4/opencv2/gapi/cpu/gcpukernel.hpp
/usr/include/opencv4/opencv2/gapi/cpu/imgproc.hpp
/usr/include/opencv4/opencv2/gapi/fluid
/usr/include/opencv4/opencv2/gapi/fluid/core.hpp
/usr/include/opencv4/opencv2/gapi/fluid/gfluidbuffer.hpp
/usr/include/opencv4/opencv2/gapi/fluid/gfluidkernel.hpp
/usr/include/opencv4/opencv2/gapi/fluid/imgproc.hpp
/usr/include/opencv4/opencv2/gapi/garg.hpp
/usr/include/opencv4/opencv2/gapi/garray.hpp
/usr/include/opencv4/opencv2/gapi/gasync_context.hpp
/usr/include/opencv4/opencv2/gapi/gcall.hpp
/usr/include/opencv4/opencv2/gapi/gcommon.hpp
/usr/include/opencv4/opencv2/gapi/gcompiled.hpp
/usr/include/opencv4/opencv2/gapi/gcompiled_async.hpp
/usr/include/opencv4/opencv2/gapi/gcompoundkernel.hpp
/usr/include/opencv4/opencv2/gapi/gcomputation.hpp
/usr/include/opencv4/opencv2/gapi/gcomputation_async.hpp
/usr/include/opencv4/opencv2/gapi/gkernel.hpp
/usr/include/opencv4/opencv2/gapi/gmat.hpp
/usr/include/opencv4/opencv2/gapi/gmetaarg.hpp
/usr/include/opencv4/opencv2/gapi/gproto.hpp
/usr/include/opencv4/opencv2/gapi/gpu
/usr/include/opencv4/opencv2/gapi/gpu/core.hpp
/usr/include/opencv4/opencv2/gapi/gpu/ggpukernel.hpp
/usr/include/opencv4/opencv2/gapi/gpu/imgproc.hpp
/usr/include/opencv4/opencv2/gapi/gscalar.hpp
/usr/include/opencv4/opencv2/gapi/gtransform.hpp
/usr/include/opencv4/opencv2/gapi/gtype_traits.hpp
/usr/include/opencv4/opencv2/gapi/gtyped.hpp
/usr/include/opencv4/opencv2/gapi/imgproc.hpp
/usr/include/opencv4/opencv2/gapi/ocl
/usr/include/opencv4/opencv2/gapi/ocl/core.hpp
/usr/include/opencv4/opencv2/gapi/ocl/goclkernel.hpp
/usr/include/opencv4/opencv2/gapi/ocl/imgproc.hpp
/usr/include/opencv4/opencv2/gapi/opencv_includes.hpp
/usr/include/opencv4/opencv2/gapi/operators.hpp
/usr/include/opencv4/opencv2/gapi/own
/usr/include/opencv4/opencv2/gapi/own/assert.hpp
/usr/include/opencv4/opencv2/gapi/own/convert.hpp
/usr/include/opencv4/opencv2/gapi/own/cvdefs.hpp
/usr/include/opencv4/opencv2/gapi/own/exports.hpp
/usr/include/opencv4/opencv2/gapi/own/mat.hpp
/usr/include/opencv4/opencv2/gapi/own/saturate.hpp
/usr/include/opencv4/opencv2/gapi/own/scalar.hpp
/usr/include/opencv4/opencv2/gapi/own/types.hpp
/usr/include/opencv4/opencv2/gapi/render.hpp
/usr/include/opencv4/opencv2/gapi/util
/usr/include/opencv4/opencv2/gapi/util/any.hpp
/usr/include/opencv4/opencv2/gapi/util/compiler_hints.hpp
/usr/include/opencv4/opencv2/gapi/util/optional.hpp
/usr/include/opencv4/opencv2/gapi/util/throw.hpp
/usr/include/opencv4/opencv2/gapi/util/util.hpp
/usr/include/opencv4/opencv2/gapi/util/variant.hpp
/usr/include/opencv4/opencv2/highgui
/usr/include/opencv4/opencv2/highgui.hpp
/usr/include/opencv4/opencv2/highgui/highgui.hpp
/usr/include/opencv4/opencv2/highgui/highgui_c.h
/usr/include/opencv4/opencv2/imgcodecs
/usr/include/opencv4/opencv2/imgcodecs.hpp
/usr/include/opencv4/opencv2/imgcodecs/imgcodecs.hpp
/usr/include/opencv4/opencv2/imgcodecs/imgcodecs_c.h
/usr/include/opencv4/opencv2/imgcodecs/ios.h
/usr/include/opencv4/opencv2/imgcodecs/legacy
/usr/include/opencv4/opencv2/imgcodecs/legacy/constants_c.h
/usr/include/opencv4/opencv2/imgproc
/usr/include/opencv4/opencv2/imgproc.hpp
/usr/include/opencv4/opencv2/imgproc/detail
/usr/include/opencv4/opencv2/imgproc/detail/gcgraph.hpp
/usr/include/opencv4/opencv2/imgproc/hal
/usr/include/opencv4/opencv2/imgproc/hal/hal.hpp
/usr/include/opencv4/opencv2/imgproc/hal/interface.h
/usr/include/opencv4/opencv2/imgproc/imgproc.hpp
/usr/include/opencv4/opencv2/imgproc/imgproc_c.h
/usr/include/opencv4/opencv2/imgproc/types_c.h
/usr/include/opencv4/opencv2/ml
/usr/include/opencv4/opencv2/ml.hpp
/usr/include/opencv4/opencv2/ml/ml.hpp
/usr/include/opencv4/opencv2/ml/ml.inl.hpp
/usr/include/opencv4/opencv2/objdetect
/usr/include/opencv4/opencv2/objdetect.hpp
/usr/include/opencv4/opencv2/objdetect/detection_based_tracker.hpp
/usr/include/opencv4/opencv2/objdetect/objdetect.hpp
/usr/include/opencv4/opencv2/opencv.hpp
/usr/include/opencv4/opencv2/opencv_modules.hpp
/usr/include/opencv4/opencv2/photo
/usr/include/opencv4/opencv2/photo.hpp
/usr/include/opencv4/opencv2/photo/cuda.hpp
/usr/include/opencv4/opencv2/photo/legacy
/usr/include/opencv4/opencv2/photo/legacy/constants_c.h
/usr/include/opencv4/opencv2/photo/photo.hpp
/usr/include/opencv4/opencv2/stitching
/usr/include/opencv4/opencv2/stitching.hpp
/usr/include/opencv4/opencv2/stitching/detail
/usr/include/opencv4/opencv2/stitching/detail/autocalib.hpp
/usr/include/opencv4/opencv2/stitching/detail/blenders.hpp
/usr/include/opencv4/opencv2/stitching/detail/camera.hpp
/usr/include/opencv4/opencv2/stitching/detail/exposure_compensate.hpp
/usr/include/opencv4/opencv2/stitching/detail/matchers.hpp
/usr/include/opencv4/opencv2/stitching/detail/motion_estimators.hpp
/usr/include/opencv4/opencv2/stitching/detail/seam_finders.hpp
/usr/include/opencv4/opencv2/stitching/detail/timelapsers.hpp
/usr/include/opencv4/opencv2/stitching/detail/util.hpp
/usr/include/opencv4/opencv2/stitching/detail/util_inl.hpp
/usr/include/opencv4/opencv2/stitching/detail/warpers.hpp
/usr/include/opencv4/opencv2/stitching/detail/warpers_inl.hpp
/usr/include/opencv4/opencv2/stitching/warpers.hpp
/usr/include/opencv4/opencv2/video
/usr/include/opencv4/opencv2/video.hpp
/usr/include/opencv4/opencv2/video/background_segm.hpp
/usr/include/opencv4/opencv2/video/legacy
/usr/include/opencv4/opencv2/video/legacy/constants_c.h
/usr/include/opencv4/opencv2/video/tracking.hpp
/usr/include/opencv4/opencv2/video/video.hpp
/usr/include/opencv4/opencv2/videoio
/usr/include/opencv4/opencv2/videoio.hpp
/usr/include/opencv4/opencv2/videoio/cap_ios.h
/usr/include/opencv4/opencv2/videoio/legacy
/usr/include/opencv4/opencv2/videoio/legacy/constants_c.h
/usr/include/opencv4/opencv2/videoio/registry.hpp
/usr/include/opencv4/opencv2/videoio/videoio.hpp
/usr/include/opencv4/opencv2/videoio/videoio_c.h

What steps are you doing for installation? dpkg or cmake?

sudo apt purge libopencv-dev libopencv-python libopencv-samples libopencv*
sudo apt update
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout $cvVersion
cd …
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout $cvVersion
cd …/opencv
mkdir build
gedit CMakeLists.txt

Add following lines to CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(OpenCV_Home_Dir /usr/local)

save and exit

cd build

Begin compiling

cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX = /usr/local
-D WITH_GSTREAMER=ON
-D OPENCV_ENABLE_NONFREE=ON
-D BUILD_TESTS=OFF
-D BUILD_PERF_TESTS=OFF
-D INSTALL_C_EXAMPLES=OFF
-D INSTALL_PYTHON_EXAMPLES=ON
-D PYTHON_EXECUTABLE=(which python3) \ -D BUILD_opencv_python2=OFF \ -D PYTHON3_EXECUTABLE=(which python3)
-D PYTHON3_INCLUDE_DIR=(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ -D PYTHON3_PACKAGES_PATH=(python3 -c “from distutils.sysconfig import get_python_lib; print(get_python_lib())”)
-D WITH_TBB=ON
-D WITH_V4L=ON
-D WITH_QT=ON
-D WITH_OPENGL=ON
-D WITH_CUDA=ON
-D OPENCV_DNN_CUDA=ON
-D ENABLE_FAST_MATH=1
-D CUDA_FAST_MATH=1
-D CUDA_ARCH_BIN=7.2
-D WITH_CUBLAS=1
-D OPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib/modules
-D BUILD_EXAMPLES=ON
-D OPENCV_GENERATE_PKGCONFIG=YES …
make -j8
sudo make install

This is what I did, provided you have the correct dependencies installed it should work.

1 Like

Thanks mff745 - I managed to build and install OpenCV now with CUDA support

Hi, I have flowed these steps and I manage up to the “Begin compiling section” , where I get the next error:
cmake -D CMAKE_BUILD_TYPE=RELEASE
CMake Error: The source directory “/home/marko/opencv/build/CMAKE_BUILD_TYPE=RELEASE” does not exist.

Any advice on where I made a mistake?

Here is a build script with cuda and all the fun non-free trimmings enabled.

Here are pre-built docker images for JetPack 4.3 and 4.4 of the latest OpenCV. The Dockerfile and build scripts are here if you wish to build it yourself.

Note: I build and provide these but I recommend you use Nvidia specific options as the performance from OpenCV may not be very good.

For some reason the code block removes the backslash character a the end of each line. All of the lines with a “-D” should also end with a \ as all -D should be passed with the cmake command. You can also type it all out on one line too:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX = /usr/local -D WITH_GSTREAMER=ON -D OPENCV_ENABLE_NONFREE=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D PYTHON_EXECUTABLE=(which python3) \ -D BUILD_opencv_python2=OFF \ -D PYTHON3_EXECUTABLE=(which python3) -D PYTHON3_INCLUDE_DIR=(python3 -c “from distutils.sysconfig import get_python_inc; print(get_python_inc())”) \ -D PYTHON3_PACKAGES_PATH=(python3 -c “from distutils.sysconfig import get_python_lib; print(get_python_lib())”) -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUDA=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_ARCH_BIN=7.2 -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib/modules -D BUILD_EXAMPLES=ON -D OPENCV_GENERATE_PKGCONFIG=YES …

But it’s a bit of a handful to type out.

EDIT: the ellipses in the codeblock are also supposed to be double period, but the autoformatting changes them. Thanks to Honey_Patouceul for pointing this error out

CUDA enabled OpenCV must be included to default JetPack releases, this situation persists on each JetPack version, i don’t understand why NVIDIA users should build opencv again to enable CUDA support.

Could an Nvidia guru please explain to me why they always include opencv, but without CUDA support for the Jetson line. I did hear on another forum, that opencv had almost no gains from the use of CUDA support, due to its architecture. Is this why? I want to reinstall OpenCV on my Jetson Nano and Xavier NX but im not really sure if i should include CUDA support. My guess is that the NVidia minds have concluded it to either be a waste or a hinderance. I would like to know the answer. Anyone from NVidia?

If I remember correctly there are some licence issues that prevent Nvidia from including CUDA support for OpenCV in their JetPack distribution.

The usual image processing does not gain much performance as OpenCV is already highly optimized and you have the overhead of copying data to/from GPU memory.

Some OpenCV modules show improved performance when using CUDA, e.g. CascadeClassifier / DNN, but you will have to modify your code base for this - there is no magic switch that you can flip and everything runs on GPU instead of CPU.

Thanks that explains a lot

I don’t know about licensing issues but I know the issue is in part but that OpenCV’s cuda module does have some issues relating to the performance and stability. If you ever run the test suite when building OpenCV, you’ll see that there are quite a few things that are broken. It’s a lot to ask Nvidia to maintain something that’s not really their product, especially one that even working perfectly does not perform as well as solutions designed explicitly for Nvidia hardware, and Tegra specifically.

I would like to think they would take market share from Intel and others (OpenCV is an Intel project), but what might be just as likely to happen is people will use the plain old CPU based cv2 module and blame Nvidia when it’s slow. Code has to be rewritten to use the cuda module, and if you’re going to rewrite it, it might not make any sense to use OpenCV at all.

@rick.minicucci

It’s only worth it to build in cuda support if you’re going to use the cuda module. Code has to be rewritten with the GPU in mind before it’ll become fast, and even then, as mentioned above, there are performance and stability issues.

Probably I mixed up the licencing issue with another project, but anyway @mdegans is spot on - Nvidia does not want to support an incomplete or instable product.