当前位置:   article > 正文

Ubuntu20.04下Qt配置OpenCV和libtorch_在ubuntu20.4中安装qt-opensource-linux-x64-5.12.12.run和

在ubuntu20.4中安装qt-opensource-linux-x64-5.12.12.run和opencv什么版本合适?

Ubuntu20.04下Qt配置OpenCV和libtorch

Qt版本:5.14.2
OpenCV:4.5.1
libtorch:1.2.1

1.OpenCV配置

在.pro项目文件中添加如下内容

INCLUDEPATH += /usr/local/include \
               /usr/local/include/opencv4 \
               /usr/local/include/opencv4/opencv2

LIBS += /usr/local/lib/libopencv*
  • 1
  • 2
  • 3
  • 4
  • 5

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);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

在这里插入图片描述

2.libtorch配置

在.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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

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;
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/433690
推荐阅读
相关标签
  

闽ICP备14008679号