在win10下给vs2013配置opencv3.0
opencv这玩意是真难搞呀。
先吐槽下。。。。。
下面进入正文。
1准备工具:
opencv3.0+vs2013
这里面不提供链接下载,自行谷歌百度。
2配置环境:
a.打开下载好的opencv(解压过程)
记住你安装/解压的目录例如我的就是

b.打开环境变量设置
右击我的电脑-》属性-》高级系统设置-》环境变量

-》系统变量下的path

-》双击path/编辑path

-》添加opencv的路径G:\OpenCv3.0\opencv\build\x64\vc12\bin和$(OPENCV)\x86\vc12\lib(解释下后面为什么是美元符,由于前面加了G:\OpenCv3.0\的路径所以后面可以直接加上其相对路径)
确认好了后就配置成功了。
3建立配置文件模板:
a.首先打开vs2013-》新建项目-》新建win32控制台应用程序

这里取名为test

记得点上空项目-》完成
b.新建项目

-》添加项目-》添加c++文件

这里名称随便取
c然后点击视图-》其他窗口-》属性管理器

d右击Debug|Win32,添加新项目属性表

取名opencv_debug

添加后进行对文件的配置,双击新建的属性表-》点击VC++目录

点击包含目录在里面添加"G:\OpenCV3.0\opencv\build\include\opencv","G:\OpenCV3.0\opencv\build\include\opencv2"和"G:\OpenCV3.0\opencv\build\include"

点击库目录在里面添加"G:\OpenCV3.0\opencv\build\x64\vc12\lib","G:\OpenCV3.0\opencv\build\x86\vc12\lib","G:\OpenCV3.0\opencv\build\x64\vc12\staticlib"和"G:\OpenCV3.0\opencv\build\x86\vc12\staticlib"
ps:这里添加x86是为了提高程序的兼容性。

点击链接器-》输入-》附加依赖项,在依赖项中添加opencv_ts300d.lib和opencv_world300d.lib

Release的属性表的差异就在依赖项:在依赖项中添加opencv_ts300.lib和opencv_world300.lib

保存即可
4测试
测试代码:
#include <core/core.hpp>
#include <highgui/highgui.hpp>
#include <math.h>
#include<iostream>
using namespace cv;
using namespace std;
void expone(char *imagesrc){//Ip1Image的方式读取,课本源码
CvPoint center;
double scale = -3;
IplImage* image = cvLoadImage(imagesrc);
if (!image) return;
center = cvPoint(image->width / 2, image->height / 2);
for (int i = 0; i<image->height; i++)
for (int j = 0; j<image->width; j++) {
double dx = (double)(j - center.x) / center.x;
double dy = (double)(i - center.y) / center.y;
double weight = exp((dx*dx + dy*dy)*scale);
uchar* ptr = &CV_IMAGE_ELEM(image, uchar, i, j * 3);
ptr[0] = cvRound(ptr[0] * weight);
ptr[1] = cvRound(ptr[1] * weight);
ptr[2] = cvRound(ptr[2] * weight);
}
cvSaveImage("copy.png", image);
cvNamedWindow("test", 1);
cvShowImage("test", image);
cvWaitKey();
}
void exptwo(char *imagesrc){//Mat方式进行读取
Mat image = imread(imagesrc);
if (!image.data)return;
double scale = -3;
CvPoint center = cvPoint(image.rows / 2, image.cols / 2);
for (int i = 0; i < image.cols; i++){
for (int j = 0; j < image.rows; j++){
double dx = (double)(j - center.x) / center.x;
double dy = (double)(i - center.y) / center.y;
double weight = exp((dx*dx + dy*dy)*scale);
for (int k = 0; k < 3; k++){
image.at<Vec3b>(j, i)[k] *= weight;//特别注意要从每行开始读取否则会出现错误
}
}
}
imwrite("mate.png", image);
//namedWindow("boy", 1);*/
imshow("girl", image);
waitKey();
}
int main(){
char *imagesrc = "../test.png";//相对路径
int ch = 0;
///简陋菜单///
do{
cout << "1.IplImage方式显示" << endl;
cout << "2.Mat方式显示" << endl;
cout << "0.退出" << endl;
cin >> ch;
switch (ch)
{
case 1:expone(imagesrc); break;
case 2:exptwo(imagesrc); break;
}
} while (ch!=0);
return 0;
}

测试成功^.^
后面其他项目的话可以直接添加现有属性表进行配置
