1、工具
下载并安装这几个工具:CMake2.8(http://www.cmake.org/cmake/resources/software.html)、OpenCV2.4.9、VS2010
2、用CMake生成OpenCV2.4.9 的VS2010解决方案
新建文件夹OpenCVProject:D:\Program Files\OpenCVProject(用于存放自己的OpenCV编译工程)。
打开CMake,"Browse Source..."选择Opencv的目录D:/Program Files/opencv(内有CMake的组态档"CMakeLists.txt"),"Browse Build..."选择刚才自己新建的工程存放路径"D:\Program Files\OpenCVProject"。点击Configure按钮,在出现的对话框中选择Visual Studio 10,默认Use default native compilers,点击Configure 直到没有红色栏后,点击Generate 生成项目工程即可。
3、打开opencv工程并编译源代码,生成我们所需要的动态链接库
这里注意:
(1)应该选择ALL_BUILD项目,右键进行“生成”,而不是 INSTALL。
(2)分别在Debug模式和Release模式下对项目进行生成。
(3)如果生成过程中出现 LINK : fatal error LNK1181: 无法打开输入文件“..\..\lib\Release\opencv_ocl249.lib” ,则说明该lib生成不成功,具体解决办法估计大同小异
4、配置Opencv环境变量
环境变量path应该添加以下两个路径:
D:\Program Files\opencv2.4.9\vc10solution\bin\Debug 和 D:\Program Files\opencv2.4.9\vc10solution\bin\Release
5、创建测试工程
5.1 添加新项目属性表
新建测试工程TestOpenCV,并在属性管理器中,选择Debug | Win32,右键点击 “添加新项目属性表”,并命名为opencv249x86.Debug ,同理在Release | Win32 处新建一个项目属性表,并命名为opencv249x86.Release (可将这两个项目属性表保存起来,当需要创建新工程时,直接复制到项目工程下,并添加进去就好。)
5.2 配置包含目录和库目录
双击新建的项目属性表opencv249x86.Debug,在 VC++ 目录 -> 包含目录, VC++ 目录 -> 库目录进行设置:
VC++ 目录 ->
包含目录:
D:\Program Files\opencv2.4.9\vc10solution\install\include
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv2
VC++ 目录 ->
库目录:
D:\Program Files\opencv2.4.9\vc10solution\lib\Debug
5.3添加附加依赖项
在 链接器->输入->附加依赖项处添加:
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_nonfree249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_videostab249d.lib
同理,在opencv249x86.Release 中也是类似的设置:
VC++ 目录 ->
包含目录:
D:\Program Files\opencv2.4.9\vc10solution\install\include
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv2
VC++ 目录 ->
库目录:
D:\Program Files\opencv2.4.9\vc10solution\lib\Release
链接器->输入->附加依赖项处添加:
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_objdetect249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_nonfree249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_videostab249.lib
5.4添加测试代码
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("E:\\lena.jpg");
if(img.empty())
{
cout<<"error";
return -1;
}
imshow("test",img);
waitKey();
return 0;
}
下载并安装这几个工具:CMake2.8(http://www.cmake.org/cmake/resources/software.html)、OpenCV2.4.9、VS2010
2、用CMake生成OpenCV2.4.9 的VS2010解决方案
新建文件夹OpenCVProject:D:\Program Files\OpenCVProject(用于存放自己的OpenCV编译工程)。
打开CMake,"Browse Source..."选择Opencv的目录D:/Program Files/opencv(内有CMake的组态档"CMakeLists.txt"),"Browse Build..."选择刚才自己新建的工程存放路径"D:\Program Files\OpenCVProject"。点击Configure按钮,在出现的对话框中选择Visual Studio 10,默认Use default native compilers,点击Configure 直到没有红色栏后,点击Generate 生成项目工程即可。
3、打开opencv工程并编译源代码,生成我们所需要的动态链接库
这里注意:
(1)应该选择ALL_BUILD项目,右键进行“生成”,而不是 INSTALL。
(2)分别在Debug模式和Release模式下对项目进行生成。
(3)如果生成过程中出现 LINK : fatal error LNK1181: 无法打开输入文件“..\..\lib\Release\opencv_ocl249.lib” ,则说明该lib生成不成功,具体解决办法估计大同小异
4、配置Opencv环境变量
环境变量path应该添加以下两个路径:
D:\Program Files\opencv2.4.9\vc10solution\bin\Debug 和 D:\Program Files\opencv2.4.9\vc10solution\bin\Release
5、创建测试工程
5.1 添加新项目属性表
新建测试工程TestOpenCV,并在属性管理器中,选择Debug | Win32,右键点击 “添加新项目属性表”,并命名为opencv249x86.Debug ,同理在Release | Win32 处新建一个项目属性表,并命名为opencv249x86.Release (可将这两个项目属性表保存起来,当需要创建新工程时,直接复制到项目工程下,并添加进去就好。)
5.2 配置包含目录和库目录
双击新建的项目属性表opencv249x86.Debug,在 VC++ 目录 -> 包含目录, VC++ 目录 -> 库目录进行设置:
VC++ 目录 ->
包含目录:
D:\Program Files\opencv2.4.9\vc10solution\install\include
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv2
VC++ 目录 ->
库目录:
D:\Program Files\opencv2.4.9\vc10solution\lib\Debug
5.3添加附加依赖项
在 链接器->输入->附加依赖项处添加:
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_nonfree249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_videostab249d.lib
同理,在opencv249x86.Release 中也是类似的设置:
VC++ 目录 ->
包含目录:
D:\Program Files\opencv2.4.9\vc10solution\install\include
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv
D:\Program Files\opencv2.4.9\vc10solution\install\include\opencv2
VC++ 目录 ->
库目录:
D:\Program Files\opencv2.4.9\vc10solution\lib\Release
链接器->输入->附加依赖项处添加:
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_objdetect249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_nonfree249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_videostab249.lib
5.4添加测试代码
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("E:\\lena.jpg");
if(img.empty())
{
cout<<"error";
return -1;
}
imshow("test",img);
waitKey();
return 0;
}