1.打开vs2017,新建一个c++项目,【文件】【新建】【项目】【Windows控制台应用程序】,选好路径和起好文件名后,点击确定
2.在解决方案资源管理器中,【你的项目名称(右键)】【属性】
3.添加头文件路径
点击VC++目录,在【包含目录中】添加如下文件路径:
……\build\install\include\
……\build\install\include\opencv2
4.添加库文件路径
在【库目录】添加如下库文件路径:
........\build\install\x64\vc15\lib
5.添加具体依赖的库
【链接器】【输入】【附加依赖项】添加如下两个链接库,粘贴进去即可:
(Release版本): opencv_world400.lib
(Debug版本):opencv_world400d.lib
PS:这里不能搞错,否则会出现异常中断等情况
6.修改系统变量在path中添加路径……\build\install\x64\vc15\bin
至此完成系统配置,其实就是配置好头文件路径,库文件路径,要连接的库,并设置程序运行时需要的动态库的路径。
测试是否正确的程序,如果程序能够正确显示则表示配置正确。
PS:如果程序运行的时候出现找不到dll的问题,可以关闭VS后重新打开。
#include "pch.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat image;
image = imread("D:\\\\opencv.jpg", IMREAD_COLOR); // Read the file
if(!image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}