1. 從http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.3/下載OpenCV2.4.3;
2. 將OpenCV-2.4.3.exe放到D:\soft\OpenCV2.4.3檔案夾下,解壓到當前檔案夾下,產生一個opencv檔案夾;
3. 下載並安裝CMake:http://www.cmake.org/cmake/resources/software.html
4. 從http://www.python.org/
下載python-2.7.3.msi安裝到D:\Python27目錄下,
5. 從http://www.python.org/ 下載Python-2.7.3.tar放到D:\soft\Python檔案夾下,解壓縮到當前檔案夾下,產生一個Python-2.7.3檔案夾;
6. 用vs2008開啟D:\soft\Python\Python-2.7.3\PCbuild檔案夾下的pcbuild.sln工程,選中Solutionpcbuild,點擊右鍵,選擇Properties,分別在Release和Debug下設定,Common
Properties-->Startup Project-->選中Singlestartup project下的python;接著選中Configuration Properties-->Configuration,僅勾選python和pythoncore;
7. 分別在Debug和Release下依次進行,選中make_buildinfo工程,rebuild,接著選中make_versioninfo工程,rebuild,選中Solution
pcbuild,rebuild,會在D:\soft\Python\Python-2.7.3\PCbuild檔案夾下產生python27.lib、python27_d.lib、python27.dll、python27_d.dll;
8. 將python27_d.lib複製到D:\Python27\libs檔案夾下(這樣OpenCV在Debug下可以正常編譯,否則會提吃找不到python27_d.lib);
9. 運行CMake(cmake-gui),在whereis the source code中填入剛才(2)中解壓縮後的檔案路徑如D:\soft\OpenCV2.4.3\opencv,在where
to build the binaries中填入編譯時間需要存放的路徑如D:\soft\OpenCV2.4.3\vs2008,此vs2008檔案夾需要自己建立;
10. 點擊Configure,在彈出的對話方塊中選擇Visual Studio 9 2008,點擊Finish;
11. 如果有紅色框顯示,繼續點擊Configure;
12. 點擊Generate,如果機子本身不支援cuda,仍然會有紅色提示,暫不用理會即可;
13. 上述步驟完成後,在vs2008檔案夾中,就會看到有OpenCV.sln檔案;
14. 使用vs2008開啟OpenCV.sln檔案,分別在Debug和Release下,選擇Solution
Explorer裡的Solution OpenCV,點右鍵,運行”Rebuild Solution”,點擊CMakeTargets下的INSTALL,build;會在D:\soft\OpenCV2.4.3\vs2008\install檔案夾下的bin檔案夾中存放相應的動態庫,在lib檔案夾下存放相應的靜態庫;
15. 開啟vs2008,建立一個控制台應用程式,為vs2008配置OpenCV環境:選擇菜單Tools-->Options-->Project
and Solutions-->VC++ Directories,Show directories for
選擇include files,加入目錄D:\soft\OpenCV2.4.3\vs2008\install\include D:\soft\OpenCV2.4.3\vs2008\install\include\opencvD:\soft\OpenCV2.4.3\vs2008\install\include\opencv2;Showdirectories
for選擇library files,加入目錄D:\soft\OpenCV2.4.3\vs2008\install\lib
;
16. 將D:\soft\OpenCV2.4.3\vs2008\install\bin加入windows系統內容變數Path中,重啟;
17. 將相應的.lib庫添加到依賴庫中。
#include
"stdafx.h"
#include
<opencv2/opencv.hpp>
using
namespace cv;
int
_tmain(int
argc, _TCHAR*
argv[])
{
Mat mat =
imread("1.jpg");
namedWindow("showimage");
imshow("showimage",
mat);
waitKey(0);
return 0;
}
參考文獻:
1. http://www.cnblogs.com/tornadomeet/archive/2012/11/07/2759476.html
2. http://code.opencv.org/projects/opencv/wiki/ChangeLoghttp://code.opencv.org/projects/opencv/wiki/ChangeLog
3. http://www.cnblogs.com/pzxbc/archive/2012/01/12/2320736.html
4. http://www.cnblogs.com/heshizhu/archive/2012/08/09/2630346.html