这次安装OpenCV算是对windows下的系统路径设置有了更深的了解,还用CMake编译了OpenCV源码。OpenCV官方的系统路径设置方法:
Set the OpenCV enviroment variable and add it to the systems path
First we set an enviroment variable to make easier our work. This will hold the build directory of our OpenCV library
that we use in our projects. Start up a command window and enter:
setx -m OPENCV_DIR D:\OpenCV\Build\x86\vc10 (suggested for Visual Studio 2010 - 32 bit Windows)
setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc10 (suggested for Visual Studio 2010 - 64 bit Windows)
setx -m OPENCV_DIR D:\OpenCV\Build\x86\vc11 (suggested for Visual Studio 2012 - 32 bit Windows)
setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc11 (suggested for Visual Studio 2012 - 64 bit Windows)
Here the directory is where you have your OpenCV binaries (extracted or built). You can have different platform (e.g.
x64 instead of x86) or compiler type, so substitute appropriate value. Inside this you should have two folders called
lib and bin. The -m should be added if you wish to make the settings computer wise, instead of user wise.
If you built static libraries then you are done. Otherwise, you need to add the bin folders path to the systems path. This
is cause you will use the OpenCV library in form of “Dynamic-link libraries” (also known as DLL). Inside these are
stored all the algorithms and information the OpenCV library contains. The operating system will load them only on
demand, during runtime. However, to do this he needs to know where they are. The systems PATH contains a list of
folders where DLLs can be found. Add the OpenCV library path to this and the OS will know where to look if he ever
needs the OpenCV binaries. Otherwise, you will need to copy the used DLLs right beside the applications executable
file (exe) for the OS to find it, which is highly unpleasent if you work on many projects. To do this start up again the
Path Editor and add the following new entry (right click in the application to bring up the menu):
%OPENCV_DIR%\bin
Save it to the registry and you are done. If you ever change the location of your build directories or want to try out your
applicaton with a different build all you will need to do is to update the OPENCV_DIR variable via the setx command
inside a command window.
这样比打开windows管理-》高级系统设置-》环境变量 再设置方便不到哪去,但是这样直接写到注册表,不用再重启电脑了是不是很爽啊。里面还推荐了一个软件,Path Editor,http://patheditor2.codeplex.com/
附加依赖项:
在VS2010中建立一个新项目fitting,在项目上右键属性,配置项目属性。
(1)Debug/Win32
配置属性-->VC++目录 需要编辑增加路径如下(先新建路径,再找到相应目录,点击应用)
可执行文件目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\bin
包含目录:D:\Program Files\opencv-2.4.8\install\include;
D:\Program Files\opencv-2.4.8\install\include\opencv;
D:\Program Files\opencv-2.4.8\install\include;
引用目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\lib
配置属性-->链接器-->输入:(输入一项就添加回车做间隔)
附加依赖项:
opencv_calib3d248d.lib
opencv_contrib248d.lib
opencv_core248d.lib
opencv_features2d248d.lib
opencv_flann248d.lib
opencv_gpu248d.lib
opencv_highgui248d.lib
opencv_imgproc248d.lib
opencv_legacy248d.lib
opencv_ml248d.lib
opencv_nonfree248d.lib
opencv_objdetect248d.lib
opencv_photo248d.lib
opencv_stitching248d.lib
opencv_ts248d.lib
opencv_video248d.lib
opencv_videostab248d.lib
(2)Release/Win32
配置属性-->VC++目录 需要编辑增加路径如下(先新建路径,再找到相应目录,点击应用)
可执行文件目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\bin
包含目录:D:\Program Files\opencv-2.4.8\install\include;
D:\Program Files\opencv-2.4.8\install\include\opencv;
D:\Program Files\opencv-2.4.8\install\include;
引用目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\lib
配置属性-->链接器-->输入:(输入一项就添加回车做间隔)
附加依赖项:
opencv_calib3d248.lib
opencv_contrib248.lib
opencv_core248.lib
opencv_features2d248.lib
opencv_flann248.lib
opencv_gpu248.lib
opencv_highgui248.lib
opencv_imgproc248.lib
opencv_legacy248.lib
opencv_ml248.lib
opencv_nonfree248.lib
opencv_objdetect248.lib
opencv_photo248.lib
opencv_stitching248.lib
opencv_video248.lib
opencv_video248.lib
opencv_videostab248.lib
参考:
http://blog.csdn.net/wlq19910603/article/details/19824655
http://www.cnblogs.com/jhzhu/p/3216840.html
Release模式添加:opencv_contrib242d.libopencv_core242d.libopencv_features2d242d.libopencv_flann242d.libopencv_gpu242d.libopencv_haartraining_engined.libopencv_highgui242d.libopencv_imgproc242d.libopencv_legacy242d.libopencv_ml242d.libopencv_objdetect242d.libopencv_ts242d.libopencv_video242d.lib
8. 编码运行opencv_contrib242.libopencv_core242.libopencv_features2d242.libopencv_flann242.libopencv_gpu242.libopencv_haartraining_engine.libopencv_highgui242.libopencv_imgproc242.libopencv_legacy242.libopencv_ml242.libopencv_objdetect242.libopencv_ts242.libopencv_video242.lib
- #include "stdafx.h"
- #include "highgui.h"
- //using namespace cv;
- int _tmain(int argc, _TCHAR* argv[])
- { const char* imagename = "D:/Images/jc.jpg";
- cv::Mat img = cv::imread(imagename);
- if(img.empty())
- { fprintf(stderr, "Can not load image %s\n", imagename);
- return -1;
- }
- if( !img.data )
- return -1;
- cv::namedWindow("image", CV_WINDOW_AUTOSIZE);
- cv::imshow("image", img);
- cv::waitKey();
- return 0;
- } //(代码来自http://blog.sina.com.cn/s/blog_68ed8b21010163uc.html)