一、openCV环境配置步骤
1.下载opencv-2.4.10到任意文件夹,然后解压,配置环境变量PATH: F:\opencv\opencv\build\x86\vc12\bin(按你自己存放的地址)
2.建立一个工程配置opencv,可以建一个属性表,方便以后都不用再配置,也可以单独给一个工程配。如下图先配置包含目录:
3.库目录配置lib
4.在链接器的输入中,加入lib文件
opencv_ml2410d.lib
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_objdetect2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_nonfree2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_videostab2410d.lib
二、openCV测试代码
#include "stdafx.h" #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char **argv) { const char* filename = "G:\\点云\\vs2013\\project\\ConsoleApplication1\\dragon.jpg"; Mat srcImg = imread(filename, CV_LOAD_IMAGE_COLOR); if (srcImg.empty()) return -1; double timeSpent = (double)getTickCount(); Mat tmp1Img(srcImg.size(), CV_8UC1); Mat tmp3Img(srcImg.size(), CV_8UC3); cvtColor(srcImg, tmp1Img, CV_RGB2GRAY); cvtColor(tmp1Img, tmp3Img, CV_GRAY2RGB); Mat dstImg(srcImg.size(), CV_8UC3); double blender; for (int i = 0; i<100; i++) { blender = (double)i / 100.0; addWeighted(srcImg, 1 - blender, tmp3Img, blender, 0, dstImg); imshow("result", dstImg); waitKey(30); } timeSpent = ((double)getTickCount() - timeSpent) / getTickFrequency(); cout << "Time spent in milliseconds: " << timeSpent * 1000 << endl; waitKey(0); return 0; }
效果图如下:
注:vc8 = Visual Studio 2005,vc9 = Visual Studio 2008,vc10 = Visual Studio 2010,vc11 = Visual Studio 2012,vc12 = Visual Studio 2013。不管你是32位还是64位操作系统,只用管你用win32编译器还是X64 编译器。其实配置选择什么跟64位还是32位系统没有直接的关系,而是在于你在编译你的程序的时候是使用那个编译器。编译器是win32,就用x86编译器是X64,就用X64。不过一般情况下,都是用的win32的X86编译器。所以,无论32还是 64位操作系统,配置文件最好都选择x86版的。