如何使用GPU版OpenCV?

您好,我已经通过 SdkManager 安装了 Cuda12.2,并且勾选了 OpenCV Runtime 4.8,在使用Python情况下,如何直接使用cuda版OpenCV,执行 cv2.cuda.getCudaEnabledDeviceCount() 后,返回:0。

Hi,

The OpenCV from JetPack doesn’t build with CUDA support.
Please build it from the source.

Below is an auto-build script for your reference:

Thanks.

感谢您的指导,但是运行脚本直接提示:./install_opencv4.6.0_Jetson.sh: 17: Syntax error: Bad for loop variable

看错误的代码行为:

set -e

for (( ; ; ))
do
echo “Do you want to remove the default OpenCV (yes/no)?”
read rm_old

其中 for (( ; ; )) 出错了,如何修复?

Hi,

Here is the script for JetPack 6.0.
install_opencv4.9.0_Jetson.sh (2.7 KB)

$ ./install_opencv4.9.0_Jetson.sh
...
-- General configuration for OpenCV 4.9.0 =====================================
...
--   NVIDIA CUDA:                   YES (ver 12.2, CUFFT CUBLAS)
--     NVIDIA GPU arch:             87
--     NVIDIA PTX archs:
-- 
--   cuDNN:                         YES (ver 8.9.4)
...
** Install opencv 4.9.0 successfully
** Bye :)

Test:

$ python3
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.9.0'
>>> print(cv2.cuda.printCudaDeviceInfo(0))
*** CUDA Device Query (Runtime API) version (CUDART static linking) *** 

Device count: 1

Device 0: "Orin"
  CUDA Driver Version / Runtime Version          12.20 / 12.20
  CUDA Capability Major/Minor version number:    8.7
  Total amount of global memory:                 62841 MBytes (65893920768 bytes)
  GPU Clock Speed:                               1.30 GHz
  Max Texture Dimension Size (x,y,z)             1D=(131072), 2D=(131072,65536), 3D=(16384,16384,16384)
  Max Layered Texture Size (dim) x layers        1D=(32768) x 2048, 2D=(32768,32768) x 2048
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     2147483647 x 65535 x 65535
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and execution:                 Yes with 2 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            Yes
  Support host page-locked memory mapping:       Yes
  Concurrent kernel execution:                   Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support enabled:                No
  Device is using TCC driver mode:               No
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           0 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) 

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 12.20, CUDA Runtime Version = 12.20, NumDevs = 1

None
>>> 

Thanks.

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