2021-05-12 14:32:11
VS2010平台下OpenCV編譯和安裝
2020-06-16 17:29:12
要點:
1) XP+ Visual Stuio 2010 + OpenCV-2.4.2.exe + cmake-2.8.8-win32-x86.exe
2) 如何CMake OpenCV原始碼得到可編譯的VS2010專案
3) 如何使用VS2010編譯OpenCV原始碼
4) 如何設定OpenCV工程
1. 下載OpenCV 安裝包
OpenCV-2.4.2.exe (http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/)
2. 解壓安裝包
雙擊OpenCV-2.4.2.exe 解壓,比如解壓安裝到C:openCV_extract
【這裡面是OpenCV自帶的dll庫,無法用來在VS中偵錯OpenCV,所以需要使用CMake重新編譯】
3. 安裝CMake
cmake-2.8.8-win32-x86.exe (http://www.cmake.org/cmake/resources/software.html)
4. CMake OpenCV
原始碼選擇OpenCV安裝目錄C:/openCV_extract/opencv
Build目錄可以設定為C:/openCV-extract/opencv_build
點選Configure
完成後,出現紅色背景,
勾選BUILD_SHARED_LIBS,BUILD_TESTS,OPENCV_BUILD_3DPARTY_LIBS,以及下面的WITH_JASPER,WITH_JPEG,WITH_PNG,WITH_TBB(一般這個沒預設選上),和WITH_TIFF選項
點選Generate
5. 編譯CMake出來的工程
(1)開啟C:/openCV-extract/opencv_build目錄下的VS2010工程檔案OpenV.sln
(2)分別使用Debug和Release模式,編譯生成。
(3)複製opencv_build目錄下的bin和lib資料夾,到C:openCV_extractopencv目錄下
複製opencvbuildinclude 目錄下的兩個資料夾,到opencvinclude 下,覆蓋。
這樣得到的庫檔案,就可以被VS2010呼叫了。
6. 設定系統環境變數
在PATH變數中新增:
C:openCV_extractopencvbuildx86vc10bin;C: openCV_extract opencvbinDebug;C: openCV_extract opencvbinRelease
7. 新建Win32工程,設定工程屬性
(1)VC++ Directories 下的Include Directories
(bindebug可以不用加)
(2)VC++ Directories 下的Library Directories
Debug模式為:libDebug
Release模式為:libRelease
(3)新增庫檔案 Linker --> Input --> Additional Dependencies (注意:lib檔名根據不同的opencv版本而定)
Debug模式新增:
opencv_calib3d242d.lib
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
Release模式新增:
opencv_calib3d242.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 %sn", 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)
執行效果如下
OpenCV官方教學中文版(For Python) PDF http://www.linuxidc.com/Linux/2015-08/121400.htm
Ubuntu Linux下安裝OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm
Ubuntu 16.04上用CMake圖形介面交叉編譯樹莓派的OpenCV3.0 http://www.linuxidc.com/Linux/2016-10/135914.htm
Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm
Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm
基於QT和OpenCV的臉部辨識系統 http://www.linuxidc.com/Linux/2011-11/47806.htm
相關文章