VS2010下编译OpenCV2.4.6静态库

VS2010下编译OpenCV2.4.6静态库

分类: OpenCV   412人阅读  评论(0)  收藏  举报

1、   从 http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.3/ 下载最新的OpenCV2.4.6;

2、   将OpenCV-2.4.6.0.exe存放到D:\Soft\OpenCV2.4.6文件夹下,解压到当前文件夹下,生成一个opencv文件夹;

3、   下载安装CMake:http://www.cmake.org/cmake/resources/software.html;

4、   运行CMake(cmake-gui),在Where is the source code中填入刚才步骤(2)解压缩后的文档路径D:/Soft/OpenCV2.4.6/opencv,在Where tobuild the binaries中填入编译时需要存放的路径如D:/Soft/OpenCV2.4.6/vs2010,此vs2010文件夹需自己创建;

5、   点击Configure,在弹出的对话框中选择Visual Studio 10,其它默认,点击Finish;

6、   找到BUILD_SHARED_LIBS选项,去掉勾选,为了减少编译时间,也可去掉一些其它不必要的勾选,点击Generate;

7、   上述步骤完成后,在vs2010文件夹中,就会看到有OpenCV.sln文件;

8、   使用vs2010打开OpenCV.sln文件,分别在Debug和Release下,选择Solution Explorer里的Solution OpenCV,点击右键,运行”Rebuild Solution”,点击CMake Targets下的INSTALL,运行”build”;会在D:/Soft/OpenCV2.4.6/vs2010/install文件夹下的lib文件夹中生成相应的静态库;

9、   打开vs2010,新建一个控制台应用程序TestOpenCV,选中工程-->Properties:(1)、VC++ Directories-->Include Directories:分别在Debug和Release模式下加入, D:/Soft/OpenCV2.4.6/vs2010/install/includeD:/Soft/OpenCV2.4.6/vs2010/install/include/opencv D:/Soft/OpenCV2.4.6/vs2010/install/include/opencv2  (2)、C/C++-->CodeGeneration-->Runtime Library:在Debug下,将其改为Multi-threaded Debug(/MTD),在Release下,将其改为Multi-threaded(/MT)。

stdafx.h文件代码为:

[cpp]  view plain copy
  1. #pragma once  
  2.   
  3. #include "targetver.h"  
  4.   
  5. #include <stdio.h>  
  6. #include <tchar.h>  
  7.   
  8. #include "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\include\\opencv2\\core\\core.hpp"  
  9. #include "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\include\\opencv2\\highgui\\highgui.hpp"  
  10. #include "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\include\\opencv2\\imgproc\\imgproc.hpp"  
  11.   
  12. using namespace cv;  

stdafx.cpp文件代码为:

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2.   
  3. #ifdef _DEBUG  
  4. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\zlibd.lib")  
  5. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libtiffd.lib")  
  6. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libpngd.lib")  
  7. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libjpegd.lib")  
  8. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libjasperd.lib")  
  9. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\IlmImfd.lib")  
  10.   
  11. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\lib\\opencv_core246d.lib")  
  12. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\lib\\opencv_highgui246d.lib")  
  13. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\lib\\opencv_imgproc246d.lib")  
  14.   
  15. #pragma comment(lib, "comctl32.lib")  
  16. #else  
  17. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\zlib.lib")  
  18. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libtiff.lib")  
  19. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libpng.lib")  
  20. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libjpeg.lib")  
  21. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\libjasper.lib")  
  22. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\share\\OpenCV\\3rdparty\\lib\\IlmImf.lib")  
  23.   
  24. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\lib\\opencv_core246.lib")  
  25. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\lib\\opencv_highgui246.lib")  
  26. #pragma comment(lib, "D:\\Soft\\OpenCV2.4.6\\vs2010\\install\\lib\\opencv_imgproc246.lib")  
  27.   
  28. #pragma comment(lib, "comctl32.lib")  
  29. #endif  

TestOpenCV.cpp文件代码为:

[cpp]  view plain copy
  1. #include "stdafx.h"  
  2.   
  3. int _tmain(int argc, _TCHAR* argv[])  
  4. {  
  5.     Mat image1, image2, imageResult;  
  6.   
  7.     image1 = cv::imread("1.jpg", 2 | 4);  
  8.     image2 = cv::imread("2.jpg", 2 | 4);  
  9.   
  10.     cv::subtract(image1, image2, imageResult);  
  11.   
  12.     cv::namedWindow("show image");  
  13.     cv::imshow("show image", imageResult);  
  14.     cv::waitKey(0);  
  15.     cv::destroyWindow("show image");  
  16.   
  17.     return 0;  
  18. }  

你可能感兴趣的:(opencv)