下载安装文件
下载地址
https://opencv.org/releases.html
下载位置
双击解压安装到电脑
配置环境变量
C:\opencv\opencv\build\x64\vc14\bin
把当前目录添加到系统环境变量中
关机重启以激活环境变量的修改项
新建VS的空白控制台工程
在此处右键属性打开VS的全局配置
在全局配置中包含目录
在全局配置中包含库
在全局配置中添加链接库
DEBUG(opencv_world341d.lib),RELEASE(opencv_world341.lib)
编写测试程序
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main()
{
const char* imageName = "1.jpg";
//读取图片//
cv::Mat img = cv::imread(imageName);
//如果读取图像失败//
if (img.empty())
{
printf("读取图像失败...\n");
return 0;
}
//显示图片//
cv::imshow("name", img);
//等待按键响应自动关闭//
cv::waitKey();
return 0;
}