前提是installatioin in windows
stepone:
打开opencv官网—
tutorials--------
Introduction to Opencv-----
How to build application with opencv inside the “Microsoft visual Studio”
设置的方法总共有两种
1.globally (so all your projects will get this information)
2.locally(so only for the current project)
The key point has two layers:
the compiler
: to tell the compiler how the OpenCV library looks. You do this by showing theheader files
.the linker
: to tell the linker from where to get the functions and implements of all used functions and data structrues to theexecutable file
.
对于解决方案中每个项目的每种build mode(debug and Release)都可以单独设置。
放在括号中的任何以美元符号开头的内容都将在运行时替换为当前环境变量值
steotwo :下面的方式是locally
这是举一个例子新建一个win32 console application
窗口右边就会出现下图:
选中你想要的的build mode ,对齐属性进行设置,如下图,我选择debug x64
1.
2.the linker
3. The you need to specify the libraries in which the linker should look into.
在这里添加你想要的模块,对于以前的opencv是分开的,你自己选择想要那个module,就引入哪一个就好,opencv_(The Name of the module)(The version Number of the library you use)d.lib
,但是对于现在的版本,都整合到同一个lib中了,所以
The letter d at the end just indictates that these are the libraries required for debug.
so for the Release build mode , make sure to omit d letters from the library name and to save the property sheets with the save icon abover them.
上面的这些设置可以新建一个属性表,操作上面的步骤,用于以后重复使用。
stepthree: forglobally(如果用了locally这一步就不用管了)
请参考官网
stepfour: 测试:
粘贴下面的代码:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: " << argv[0] << " ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (image.empty()) // 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;
}
右击目标项目,点击生成