Visual2019 Libtorch和opencv环境配置
作者:互联网
1、Libtorch
版本:1.9.0(和torch版本一致)
步骤:
- 将下载好的libtorch解压,在系统环境变量的path中添加xxx\libtorch\lib
- 打开VisualStudio创建C++新项目:LibTorch,选择控制台应用,选择release和x64模式(libtorch都是x64)
- 点击项目>>LibTorch属性>>VC++目录,在包含目录中添加xxx\libtorch\include和xxx\libtorch\include\torch\csrc\api\include,在库目录中添加xxx\libtorch\lib
- 点击项目>>LibTorch属性>>连接器>>输入,在附加依赖项中添加xxx\libtorch\lib中的所有lib文件
调试代码:
#include "torch/torch.h" #include "torch/script.h" int main() { torch::Tensor output = torch::randn({ 3,2 }); std::cout << output; return 0; }
2、OpenCV
版本:4.5.3
步骤:
- 将下载好的opencv解压,在系统环境变量的path中添加xxx\OpenCV\build\x64\vc15\bin
- 将xxx\OpenCV\build\x64\vc15\bin文件夹中的opencv_world453.dll,opencv_world453d.dllopencv_ffmpeg453_64.dl文件复制到C:\Windows\System32
- 点击项目>>LibTorch属性>>VC++目录,在包含目录中添加xxx\opencv\build\include和\opencv\build\include\opencv2,在库目录中添加xxx\OpenCV\build\x64\vc15\lib
- 点击项目>>LibTorch属性>>连接器>>输入,在附加依赖项中添加opencv_world453.lib和opencv_world453d.lib
调试代码:
# include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main() { Mat src = imread("D:\\VS_C++\\mm.png"); // 修改为测试图片路径 namedWindow("input image", WINDOW_AUTOSIZE); imshow("input image", src); waitKey(0); }
标签:torch,lib,opencv,xxx,Visual2019,Libtorch,include,libtorch 来源: https://www.cnblogs.com/chang-yuan/p/15200972.html