print(cv2.cuda.getCudaEnabledDeviceCount()) show 0 on jetson nano after compiling opencv-4.1.2 from source

I have compiled opencv-4.1.2 from source using the following commands :
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE
-D WITH_CUDA=ON
-D CUDA_ARCH_PTX=“”
-D CUDA_ARCH_BIN=“5.3,6.2,7.2”
-D WITH_CUBLAS=ON
-D OPENCV_DNN_CUDA=ON
-D ENABLE_FAST_MATH=1
-D CUDA_FAST_MATH=1
-D WITH_LIBV4L=ON
-D BUILD_opencv_python3=ON
-D BUILD_opencv_python2=OFF
-D BUILD_opencv_java=OFF
-D WITH_GSTREAMER=ON
-D WITH_GTK=ON
-D BUILD_TESTS=OFF
-D BUILD_PERF_TESTS=OFF
-D BUILD_EXAMPLES=OFF
-D OPENCV_ENABLE_NONFREE=ON
-D OPENCV_EXTRA_MODULES_PATH=/home/whoami/opencv_contrib/modules …

after installation when I run, print(cv2.cuda.getCudaEnabledDeviceCount()) in python3 I get the output 0, that is quite unusual. As the expected output is 1 to show the 1 cuda enabled device on the nano.

You may try to configure as here :
Compiling OpenCV from Source | OpenCV | RidgeRun.

You may try:

cd <your-opencv-build-directory>

# This would update your current config in CMakeCache.txt and re-generate build files if any
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python2) \
-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())") \
.

make -j3

sudo make install

Also check if /usr/local/cuda/lib64 is in :

echo $LD_LIBRARY_PATH

if not add it.

Hi, I don’t know much about compilation, but will this solution work if I have installed it already. As in I’ve already ran these commands.

make -j3
sudo make install

also, why make -j3 and not kame -j4… since Jetson has 4 cores, are there any benefits of it.

The complete tutorial helped me solve the problem, thank you so much. Ridge Run’s fork was really working it.

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