開啟新專案
專案名稱: VS2012ConsoleOpenCV248
按下<Next>按鈕
點選Console Application後, 按下<Finish>按鈕
Click <Property Mananger> tab, and focus on Release|Win32, click mouse's right button
Add New Property Sheet
設定屬性管理專案名稱例如OpenCV248VS2012以及儲存路徑(Location),按下<Add>按鈕
滑鼠雙擊開啟專案屬性管理:OpenCV248VS2012
C/C++ –> Additional Include Directories-> Edit
加入
C:\OpenCV-2.4.8\opencv\build\include\
C:\OpenCV-2.4.8\opencv\build\include\opencv
設定其他程式庫目錄
加入
C:\OpenCV-2.4.8\opencv\build\x64\vc11\lib
滑鼠點選<Input>, 接著點擊Additional Dependencies下拉選單, 選擇<Edit>
加入下列全部*.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_ocl248.lib
opencv_photo248.lib
opencv_stitching248.lib
opencv_superres248.lib
opencv_ts248.lib
opencv_video248.lib
opencv_videostab248.lib
按下<Local Windows Debugger>發生錯誤訊息!!!
Cannot open include file ‘opencv2\core\core.hpp’
怎麼會這樣呢? 編輯程式還會即時自動跳出提示字, 怎麼編譯反而找不到?
解決方式:不曉得為什麼先前定義的Property Mananger未能發揮作用,
乾脆直接手動定義include & library路徑在VS2012ConsoleOpenCV248專案內
編譯錯誤解決了, 不過執行階段發生找不到opencv_core248.dll
請新增系統環境變數, 滑鼠點選<環境變數>
找尋Path, 加入
C:\OpenCV-2.4.8\opencv\build\x64\vc11\bin
測試OpenCV2.4.8
1: #include "stdafx.h"
2: #include <opencv2\core\core.hpp>
3: #include <opencv2\highgui\highgui.hpp>
4: #include <iostream>
5: int _tmain(int argc, _TCHAR* argv[])
6: {
7: cv::Mat img = cv::imread("sample.jpg");
8: cv::namedWindow("sample image");
9: cv::imshow("sample image", img);
10: cv::waitKey(0);
11: return 0;
12: }
執行結果
範例程式: VS2012ConsoleOpenCV248
操作展示:2014 01 06 VS2012ConsoleOpenCV248
2013/01/06 今天重新再製作一次本範例, 發現要先更改專案屬性x64, 再載入property manager才會編譯OK,
先前遇到的問題, 應該是順序顛倒:先載入property manager再設定X64導致編譯錯誤
留言列表