赞
踩
Qt版本:5.14.2
OpenCV:4.5.1
libtorch:1.2.1
在.pro项目文件中添加如下内容
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv4 \
/usr/local/include/opencv4/opencv2
LIBS += /usr/local/lib/libopencv*
OpenCV测试代码及结果
void opencvandlibtorch_test::opencv_test(){ cout <<"opencv test" << endl; cout <<"opencv version: " << CV_VERSION << endl; Mat src = imread("/home/zxm/图片/opencv.png"); if(src.empty()){ cout << "could not load image" << endl; return; } namedWindow("src",WINDOW_NORMAL); imshow("src",src); waitKey(0); }
在.pro项目文件中添加如下内容
INCLUDEPATH += /home/zxm/libtorch/include INCLUDEPATH += /home/zxm/libtorch/include/torch/csrc/api/include #.so LIBS += -L/home/zxm/libtorch/lib\ -lc10\ -lshm\ -lc10d_cuda_test\ -ltorchbind_test\ -lnnapi_backend\ -lc10_cuda\ -ltorch_python\ -ltorch_global_deps\ -ljitbackend_test\ -ltorch_cuda\ -lcaffe2_nvrtc\ -lbackend_with_compiler\ -ltorch\ -ltorch_cuda_linalg\ -ltorch_cuda_cpp\ -ltorch_cuda_cu\ -ltorch_cpu\ -INCLUDE:?warp_size@cuda@at@@YAHXZ\ -Wl,--no-as-needed -ltorch_cuda #force to link torch_cuda QMAKE_LFLAGS += -INCLUDE:?searchsorted_cuda@native@at@@YA?AVTensor@2@AEBV32@0_N1@Z CONFIG += c++14
libtorch测试代码及结果
void opencvandlibtorch_test::libtorch_test(){ cout << "libtorch test " << endl; cout << "LibTorch version : " << TORCH_VERSION_MAJOR << "." << TORCH_VERSION_MINOR << "." << TORCH_VERSION_PATCH << endl; cout << "PyTorch version: " << TORCH_VERSION <<endl; torch::Tensor tensor = torch::rand({2, 3}); std::cout << tensor << std::endl; //测试是否能使用GPU if(torch::cuda::is_available()){ cout << "can use GPU" << endl; } else{ cout << "can not use GPU" << endl; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。