视频讲解
OpenCV编译C++测试程序获取CUDA设备信息
测试代码
test-cv.cpp
#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <iostream>using namespace cv;
using namespace cv::cuda;
using namespace std;int main(int argc, char **argv) {cuda::printCudaDeviceInfo(cuda::getDevice());int cnt = getCudaEnabledDeviceCount();printf("Now get CUDA device count:%d \r\n", cnt);return 0;
}
手动编译的opencv的安装目录在/usr/lib下,可以看之前的cmake参数
-DCMAKE_INSTALL_PREFIX=/usr/local \
故使用g++编译的时候,需要加上-l指定头文件目录,否则就会报找不到opencv头文件
fatal error: opencv2/opencv.hpp: No such file or directory
再增加-L指定依赖动态库的位置,-lopencv_core为基础库
还有如下库可能会使用到
-lopencv_aruco -lopencv_barcode -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_dnn_objdetect -lopencv_dnn -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_freetype -lopencv_fuzzy -lopencv_gapi -lopencv_hfs -lopencv_highgui -lopencv_imgcodecs -lopencv_img_hash -lopencv_imgproc -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_phase_unwrapping -lopencv_photo -lopencv_plot -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stereo -lopencv_stitching -lopencv_structured_light -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_videoio -lopencv_video -lopencv_videostab -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto
g++ test-cv.cpp -o test-cv -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_core
运行得到如下结果
./test-cv
*** CUDA Device Query (Runtime API) version (CUDART static linking) *** Device count: 1Device 0: "Orin"CUDA Driver Version / Runtime Version 11.40 / 11.40CUDA Capability Major/Minor version number: 8.7Total amount of global memory: 7471 MBytes (7834177536 bytes)GPU Clock Speed: 0.62 GHzMax 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 2048Total amount of constant memory: 65536 bytesTotal amount of shared memory per block: 49152 bytesTotal number of registers available per block: 65536Warp size: 32Maximum number of threads per block: 1024Maximum sizes of each dimension of a block: 1024 x 1024 x 64Maximum sizes of each dimension of a grid: 2147483647 x 65535 x 65535Maximum memory pitch: 2147483647 bytesTexture alignment: 512 bytesConcurrent copy and execution: Yes with 2 copy engine(s)Run time limit on kernels: NoIntegrated GPU sharing Host Memory: YesSupport host page-locked memory mapping: YesConcurrent kernel execution: YesAlignment requirement for Surfaces: YesDevice has ECC support enabled: NoDevice is using TCC driver mode: NoDevice supports Unified Addressing (UVA): YesDevice PCI Bus ID / PCI location ID: 0 / 0Compute Mode:Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.40, CUDA Runtime Version = 11.40, NumDevs = 1Now get CUDA device count:1