1.下载opencv
opencv官网:https://opencv.org/releases.html#,下载Win pack的opencv安装包
解压并安装到目标路径
2.配置系统环境变量
依次点击 此电脑-右键,选择属性
高级系统设置
点击下方环境变量
在系统变量中找到path,选择编辑
新建一个路径,根据之前opencv安装好的路径中寻找(大家的安装路径可能不同)
3.在vs2017中配置opencv
下载vs2017:https://visualstudio.microsoft.com/zh-hans/
下载Windos版 community 2017
新建一个工程
选择x64
选择视图->其他窗口->属性管理器
选择x64,右键选择属性
选择vc++目录中的包含目录,点击下拉箭头,选择编辑
添加这三条路径(还是根据自己的安装路径)
然后选择库目录,下拉箭头,选择编辑,添加如下路径
选择链接器->输入->附加依赖项
将opencv->build->x64->vc14->bin目录下的三个文件opencv_ffmpeg341_64.dll, opencv_world341.dll和opencv_world341d.dll复制到C:\Windows\System32文件夹中
4.测试代码
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <stdio.h>
int main()
{
// BGR
IplImage *testimage = cvCreateImage(cvSize(300, 300), IPL_DEPTH_8U, 3);
for (int i = 0; i < testimage->height; i++)
{
for (int j = 0; j < testimage->width; j++)
{
testimage->imageData[i*testimage->widthStep + j * testimage->nChannels + 0] = 255;
testimage->imageData[i*testimage->widthStep + j * testimage->nChannels + 1] = 0;
testimage->imageData[i*testimage->widthStep + j * testimage->nChannels + 2] = 0;
}
}
cvNamedWindow("BGR", 1);
cvShowImage("BGR", testimage);
cvWaitKey(0);
cvDestroyWindow("BGR");
cvReleaseImage(&testimage);
}