星期日, 3月 03, 2013

[QT] QtCreator / OpenCV


在QtCreatror裡面使用OpenCV著實讓我弄了很久....
網路上的各方資料搜尋了不少,lib已連結,path也設定好了,能夠宣告但一旦碰到呼叫函數就會遇到以下問題...

undefined reference to `cvLoadImage’

好,這表示敝人的函數是個名存實亡.....

最後終於在某個角落找到解決的方法!!!




If you want to use Qt Creator with the default (and more standard) MinGW compiler not MSVC then you have just downloaded the wrong version of OpenCV since you will have to compile you own from source. You can get it at the same place you downloaded the the binaries from.

Useful guide here: http://opencv.willowgarage.com/wiki/MinGW#OpenCV2.2

Follow this guide to step 20, and dont forget to add the location of dll-s to your PATH after compiling OpenCV.

1. 照著上方網址內進行到第20步驟
2. Restart your Windows to let the PATH change take effect.
3. 打開QtCreator開新project,編輯.pro檔案加入...


LIBS += -LC:/OpenCV2.3MinGW/install/bin \
-llibopencv_core230 \
-llibopencv_highgui230

INCLUDEPATH += C:/OpenCV2.3MinGW/install/include \
C:/OpenCV2.3MinGW/install/include/opencv

Explanation: you have to insert the folder of your dll-s after -L and put the name of the desired dll-s after -l .

4. 寫程式:

main.cpp內
#include <opencv2/opencv.hpp>
....(以下省略)
IplImage *image = cvLoadImage("c://Users/cmlab/cloudour/image/img_0000.jpg");
cvShowImage("test",image);
cvWaitKey();
....(以下省略)

如果成功編譯了!!
就...
成功啦!!


參考資料 : 
1. http://fleshandmachines.wordpress.com/2011/07/23/opencv-and-qt-creator-marriage-on-windows-7/
2. http://www.barbato.us/2011/03/18/using-opencv2-within-qtcreator-in-windows-2/
3. http://stackoverflow.com/questions/12123479/setting-up-opencv-2-4-2-with-qt-creator




沒有留言:

張貼留言