# Build opencv with cuda not working

**URL:** <https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979>\
**Category:** Python\
**Tags:** dnn, windows, build, cuda\
**Created:** [December 27, 2023, 11:05am UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979 "2023-12-27T11:05:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anya/32/9404_2.png) [@anya](https://forum.opencv.org/u/anya)\
**Post date:** [December 27, 2023, 11:05am UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/1 "2023-12-27T11:05:50Z")

</div>

I am following a tutorial to build opencv with cuda [https://haroonshakeel.medium.com/build-opencv-4-4-0-with-cuda-gpu-support-on-windows-10-without-tears-aa85d470bcd0](https://haroonshakeel.medium.com/build-opencv-4-4-0-with-cuda-gpu-support-on-windows-10-without-tears-aa85d470bcd0)  
everything worked well no errors found  
but when I tried to check if it’s enabeled  
typing this command

```auto
print(cv2.cuda.getCudaEnabledDeviceCount())

```

it shows 0  
I installed cude toolkit 12.3 and CuDNN I set up paths  
any suggestions

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [December 27, 2023, 11:26am UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/2 "2023-12-27T11:26:06Z")

</div>

> [@anya](#):
>
> I am following a tutorial to build opencv with cuda [Build OpenCV 4.4.0 with CUDA (GPU) Support on Windows 10 (Without Tears) | by M. Haroon Shakeel | Medium](https://haroonshakeel.medium.com/build-opencv-4-4-0-with-cuda-gpu-support-on-windows-10-without-tears-aa85d470bcd0)

I’d say the title is probably misleading!

What does  
print(cv2.getBuildInformation())  
output?

---

<div class="post-metadata">

**Author:** ![anya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anya/32/9404_2.png) [@anya](https://forum.opencv.org/u/anya)\
**Post date:** [December 28, 2023, 1:16pm UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/3 "2023-12-28T13:16:05Z")

</div>

> [@cudawarped](#):
>
> print(cv2.getBuildInformation())

this is the output that I got

`General configuration for OpenCV 4.6.0 =====================================  
Version control: unknown

Extra modules:  
Location (extra): C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/work/opencv\_contrib-4.6.0/modules  
Version control (extra): unknown

Platform:  
Timestamp: 2023-08-10T01:27:56Z  
Host: Windows 10.0.17763 AMD64  
CMake: 3.26.4  
CMake generator: Ninja  
CMake build tool: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_build\_env/Library/bin/ninja.exe  
MSVC: 1916  
Configuration: Release

CPU/HW features:  
Baseline: SSE SSE2 SSE3  
requested: SSE3  
Dispatched code generation: SSE4\_1 SSE4\_2 FP16 AVX AVX2 AVX512\_SKX  
requested: SSE4\_1 SSE4\_2 AVX FP16 AVX2 AVX512\_SKX  
SSE4\_1 (16 files): + SSSE3 SSE4\_1  
SSE4\_2 (1 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2  
FP16 (0 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 AVX  
AVX (4 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 AVX  
AVX2 (31 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 FMA3 AVX AVX2  
AVX512\_SKX (5 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 FMA3 AVX AVX2 AVX\_512F AVX512\_COMMON AVX512\_SKX

C/C++:  
Built as dynamic libs?: YES  
C++ standard: 11  
C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe (ver 19.16.27050.0)  
C++ flags (Release): /DWIN32 /D\_WINDOWS /W4 /GR /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MD /O2 /Ob2 /DNDEBUG  
C++ flags (Debug): /DWIN32 /D\_WINDOWS /W4 /GR /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MDd /Zi /Ob0 /Od /RTC1  
C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe  
C flags (Release): /DWIN32 /D\_WINDOWS /W3 /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /MD /O2 /Ob2 /DNDEBUG  
C flags (Debug): /DWIN32 /D\_WINDOWS /W3 /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /FS /MDd /Zi /Ob0 /Od /RTC1  
Linker flags (Release): /machine:x64 /INCREMENTAL:NO  
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL  
ccache: NO  
Precompiled headers: NO  
Extra dependencies:  
3rdparty dependencies:

OpenCV modules:  
To be built: alphamat aruco barcode bgsegm calib3d ccalib core datasets dnn dnn\_objdetect dnn\_superres dpm face features2d flann fuzzy gapi hdf hfs highgui img\_hash imgcodecs imgproc intensity\_transform line\_descriptor mcc ml objdetect optflow phase\_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured\_light superres surface\_matching text tracking video videoio videostab wechat\_qrcode xfeatures2d ximgproc xobjdetect xphoto  
Disabled: bioinspired world  
Disabled by dependency: -  
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype java julia matlab ovis python2 sfm ts viz  
Applications: apps  
Documentation: NO  
Non-free algorithms: NO

Windows RT support: NO

GUI: NONE

Media I/O:  
ZLib: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library/lib/z.lib (ver 1.2.13)  
JPEG: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library/lib/jpeg.lib (ver 90)  
WEBP: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library/lib/libwebp.lib (ver encoder: 0x020f)  
PNG: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library/lib/libpng.lib (ver 1.6.37)  
TIFF: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library/lib/tiff.lib (ver 42 / 4.1.0)  
OpenEXR: build (ver 2.3.0)  
HDR: YES  
SUNRASTER: YES  
PXM: YES  
PFM: YES

Video I/O:  
GStreamer: YES (1.18.5)  
DirectShow: YES  
Media Foundation: YES  
DXVA: NO

Parallel framework: Concurrency

Trace: YES (with Intel ITT)

Other third-party libraries:  
Intel IPP: 2020.0.0 Gold [2020.0.0]  
at: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/work/build/3rdparty/ippicv/ippicv\_win/icv  
Intel IPP IW: NO  
Eigen: YES (ver 3.3.7)  
Custom HAL: NO  
Protobuf: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library/lib/libprotobuf.lib (3.20.3)

Python 3:  
Interpreter: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/python.exe (ver 3.11.4)  
Libraries: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/libs/python311.lib (ver 3.11.4)  
numpy: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Lib/site-packages/numpy/core/include (ver 1.23.5)  
install path: C:\b\abs\_f8n1j3l9l0\croot\opencv-suite\_1691622637237\_h\_env\Lib\site-packages

Python (for build): C:\b\abs\_f8n1j3l9l0\croot\opencv-suite\_1691622637237\_h\_env/python.exe

Install to: C:/b/abs\_f8n1j3l9l0/croot/opencv-suite\_1691622637237/\_h\_env/Library  
-----------------------------------------------------------------`

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [December 28, 2023, 6:02pm UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/4 "2023-12-28T18:02:26Z")

</div>

You haven’t built with CUDA you should get output similar to the following

```auto
-- NVIDIA CUDA: YES (ver 12.3, CUFFT CUBLAS NVCUVID NVCUVENC)
-- NVIDIA GPU arch: 50 52 60 61 70 75 80 86 89 90
-- NVIDIA PTX archs: 90
--
-- cuDNN: YES (ver 8.9.5)

```

I recommend following the original guide I wrote which M. Haroon Shakeel (and probably every one else I have seen) took his “instructions” from

> **[Build OpenCV (including Python) with CUDA on Windows: Comprehensive Guide...](https://www.jamesbowley.co.uk/qmd/opencv_cuda_python_windows.html)**
>
> Guide to building OpenCV (including Python bindings) with CUDA (optionally the Nvidia Video Codec SDK and cuDNN) from within Visual Studio or from the command line using the Ninja build system.

Whilst I can’t guarnatee the amount of tears you will encouner whilst reading it I can guarnatee I have at least tested the instructions in it multiple times to make sure they are accurate.

If you have any problems with the instructions or anything is unclear please let me know.

---

<div class="post-metadata">

**Author:** ![anya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anya/32/9404_2.png) [@anya](https://forum.opencv.org/u/anya)\
**Post date:** [January 2, 2024, 11:58am UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/5 "2024-01-02T11:58:23Z")

</div>

I think I am doing something wrong, I have everything installed in my computer  
-visual studio 17 2022 with desktop developement with c++

- opencv 4.8.0 and opencv contrib 4.8.0
- cmake 3.28.1 for windows  
-cuda 12.3 and cudnn 8.9.2  
I copied like this

`set CMAKE_BUILD_PARALLEL_LEVEL=8 "C:\Users\github\cmake-3.28.1-windows-x86_64\cmake-3.28.1-windows-x86_64\bin\cmake-gui.exe" -H"C:\Users\github\opencv-4.8.0\opencv-4.8.0" -DOPENCV_EXTRA_MODULES_PATH="C:\Users\github\opencv_contrib-4.8.0\opencv_contrib-4.8.0\modules" -B"C:\Users\github\build_" -G"Visual Studio 17 2022" -DINSTALL_TESTS=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DBUILD_opencv_world=ON -DWITH_CUDA=ON -DCUDA_GENERATION=Auto -DBUILD_opencv_python3=ON -DPYTHON3_INCLUDE_DIR=C:\Users\anaconda3\include -DPYTHON3_LIBRARY=C:\Users\anaconda3\libs\python311.lib -DPYTHON3_EXECUTABLE="C:\Users\anaconda3\python.exe" -DPYTHON3_NUMPY_INCLUDE_DIRS="C:\Users\anaconda3\Lib\site-packages\numpy\core\include" -DPYTHON3_PACKAGES_PATH= "C:\Users\anaconda3\Lib\site-packages/"`

I am executing it from the anaconda prompt when I hit enter nothing happened

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [January 2, 2024, 1:13pm UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/6 "2024-01-02T13:13:33Z")

</div>

You are trying to use the GUI (_cmake-gui.exe_), the guide uses _cmake.exe_.

---

<div class="post-metadata">

**Author:** ![anya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anya/32/9404_2.png) [@anya](https://forum.opencv.org/u/anya)\
**Post date:** [January 3, 2024, 11:16am UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/7 "2024-01-03T11:16:25Z")

</div>

I am sorry for bothering you but for some reason I think I am doing something wrong  
because I am working with python via anaconda  
I created a new environment with anaconda after building the opencv with cmake I tried to see if its successfully installed with spyder but it says opencv is not installed.Any suggestions  
how can I build it with cuda enabeled inside the environment I am working on ?

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [January 3, 2024, 1:32pm UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/8 "2024-01-03T13:32:30Z")

</div>

OpenCV will be installed to the environment you gave it at CMake configuration time. From your previous settings

> [@anya](#):
>
> -DBUILD\_opencv\_python3=ON -DPYTHON3\_INCLUDE\_DIR=C:\Users\anaconda3\include -DPYTHON3\_LIBRARY=C:\Users\anaconda3\libs\python311.lib -DPYTHON3\_EXECUTABLE=“C:\Users\anaconda3\python.exe” -DPYTHON3\_NUMPY\_INCLUDE\_DIRS=“C:\Users\anaconda3\Lib\site-packages\numpy\core\include” -DPYTHON3\_PACKAGES\_PATH= “C:\Users\anaconda3\Lib\site-packages/”

this will be to your main environment not the new one you created after configuring it.

Additionaly OpenCV it won’t show as installed in pip , conda etc. as the bindings have been installed by CMake. The bindings in the case of your previous commands will be inside \*C:\Users\anaconda3\Lib\site-packages\cv2\* and as long as you built a Release version you will be able to access OpenCV by calling `import cv2` from that environment.

---

<div class="post-metadata">

**Author:** ![anya](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/anya/32/9404_2.png) [@anya](https://forum.opencv.org/u/anya)\
**Post date:** [January 9, 2024, 9:01am UTC](https://forum.opencv.org/t/build-opencv-with-cuda-not-working/15979/9 "2024-01-09T09:01:07Z")

</div>

I got it now thank you
