Eclipseã§OpenCV
OpenCVã®ããã°ã©ã ãçµ±åéçºç°å¢Eclipseã¨C/C++ã³ã³ãã¤ã©MinGWã§éçºããããã®ã»ããã¢ããæ¹æ³ãã¾ã¨ãã¦ããã¾ããWindowsç°å¢ã§Visual Studioãã¤ã³ã¹ãã¼ã«ããªãã¦ãOpenCVããã°ã©ã ãéçºã§ãã¾ãã
1. MinGWã®ã¤ã³ã¹ãã¼ã«
ここããMinGW-5.1.6.exeï¼2009/10/15ç¾å¨ï¼ããã¦ã³ãã¼ããã¤ã³ã¹ãã¼ã«éä¸ã§g++ compilerã¨MinGW Makeãªãã·ã§ã³ããã§ãã¯ã
2. Eclipseã®ã¤ã³ã¹ãã¼ã«
ここããEclipse IDE for C/C++ Developersï¼Eclipse CDTï¼ããã¦ã³ãã¼ãã解åããã¨eclipseãã©ã«ããã§ããã®ã§C:\eclipseãªã©ã«ç§»åã
3. OpenCVã®ã¤ã³ã¹ãã¼ã«
ここããOpenCV-2.0.0a-win32.exeï¼2009/10/15ç¾å¨ï¼ããã¦ã³ãã¼ããããã©ã«ãã§ã¯ãC:\OpenCV2.0ã«ã¤ã³ã¹ãã¼ã«ããã¾ãã
4. ç°å¢å¤æ°ã®è¨å®
ç°å¢å¤æ°ã®PATHã«C:\MinGW\bin;C:\OpenCV2.0\bin;ã追å ãOpenCVã®binã追å ããªãã¨dllããªã³ã¯ã§ããOpenCVããã°ã©ã ãã¯ã©ãã·ã¥ããã®ã§æ³¨æã
5. æ°è¦ããã¸ã§ã¯ããä½æ
Eclipseã§æ°è¦C++ããã¸ã§ã¯ããä½æãããã¸ã§ã¯ãåï¼ããã§ã¯testï¼ãå ¥åãProject typeã§Empty ProjectãToolchainsã§MinGW GCCãé¸æã
6. includeã¨libãã©ã«ãã®è¨å®
ã³ã³ãã¤ã©ã«OpenCVã®ããããã¡ã¤ã«ï¼includeï¼ã¨ã©ã¤ãã©ãªãã¡ã¤ã«ï¼libï¼ã®å ´æãæãã¾ããProject Explorerã®testããã¸ã§ã¯ããå³ã¯ãªãã¯ãã¦Propertiesã«ã¦C/C++ General > Paths and Symbolsãé¸æãConfigurationã§[All configurations]ãé¸æãIncludes > C++ Source Fileãé¸æãã¦C:\OpenCV2.0\include\opencvãAddãLibrary Pathsãé¸æãã¦C:\OpenCV2.0\libãAddã
ï¼æ³¨ï¼Cã¨C++ã®è¨å®ã¯å¥ã ãªã®ã§æ³¨æããããæ¡å¼µåã.cã®Cããã°ã©ã ã追å ãããªãIncludes > C Source Fileã«ãåæ§ã«C:\OpenCV2.0\include\opencvã追å ããå¿ è¦ãããã¾ãã
7. ãªã³ã¯ããã©ã¤ãã©ãªã®è¨å®
C/C++ Build > Settingsãé¸æãConfigurationã§[All configurations]ãé¸æãMinGW C++ Linker > Librariesã®Librariesã«
- cv200
- highgui200
- cxcore200
- ml200
ããããã追å ã
ï¼æ³¨ï¼Cã¨C++ã®è¨å®ã¯å¥ã ãªã®ã§æ³¨æããããæ¡å¼µåã.cã®Cããã°ã©ã ã追å ãããªãC Source Fileã«ã追å ããå¿ è¦ãããã
ï¼æ³¨ï¼5ãã7ã®è¨å®ã¯ããã¸ã§ã¯ããä½æãããã³ã«è¡ãã¾ããé¢åã§ããã»ã»ã»
8. ã½ã¼ã¹ãã¡ã¤ã«ãä½æ
ããã¸ã§ã¯ãã«ã½ã¼ã¹ãã¡ã¤ã«ã追å ãã¦ã³ã¼ããæ¸ãã¾ãããã¨ãã°ãmain.cppï¼C++ããã°ã©ã ã§ãï¼ã追å ãã¦ä»¥ä¸ã®ã³ã¼ããå ¥åãã¾ããEclipseã¯å ¥åè£å®ããããå å®ãã¦ã¾ãããã¨ãã°ãcvã¨æã¡è¾¼ãã ç¶æ ã§Ctrl+Spaceãæ¼ãã¨é¢æ°åè£ãå¼æ°ã®èª¬æä»ãã§ããã£ã¨ä¸¦ã¶ã®ã§ââç¢å°ã§é¸æãã¦Enterãæ¼ãã¨ãã£ã¦ã«å ¥åãã¦ããã¾ãã
#include <cv.h> #include <highgui.h> int main(int argc, char **argv) { // ç»åããã¼ã IplImage *img = cvLoadImage("C:/OpenCV2.0/samples/c/lena.jpg", CV_LOAD_IMAGE_COLOR); // ã¦ã£ã³ãã¦ãä½æ cvNamedWindow("image", CV_WINDOW_AUTOSIZE); // ã¦ã£ã³ãã¦ã«ç»åã表示 cvShowImage("image", img); // ãã¼å ¥åå¾ æ© cvWaitKey(0); // å¾å¦ç cvReleaseImage(&img); cvDestroyWindow("image"); return 0; }
9. ãã«ã
ã¡ãã¥ã¼ã®Project > Build AllãCtrl+Bã§ãã«ããæåããã°Project Explorerã«Binaries/test.exeãã§ãã¾ãããã失æãããã½ã¼ã¹ã³ã¼ãä¸ã«è¦åãã¨ã©ã¼ä½ç½®ã¨å 容ã表示ãããã®ã§ä¿®æ£ãã¹ãç®æãä¸ç®ã§ãããã¾ãã
ï¼æ³¨ï¼__exchange_and_addã«é¢é£ããã³ã³ãã¤ã«ã¨ã©ã¼ãåºãå ´åã¯ä»¥ä¸ã®ä¿®æ£ãå ãã¾ãï¼OpenCV InstallGuideããï¼ã
(1) C:\OpenCV2.0\include\opencv\cxoperations.hppãã¨ãã£ã¿ã§éããæ¹è¡ã³ã¼ãã®é¢ä¿ã§ã¡ã¢å¸³ã§ã¯å´©ãã¾ããEclipseã§éãã¦ãã ããã
(2) 66ãã68è¡ç®ï¼OpenCV2.0.0ã®å ´åï¼ãããã®
#else #include <bits/atomicity.h> #if __GNUC__ >= 4
ã®é¨åã
#else #include <bits/atomicity.h> #if __GNUC__ >= 4 || __MINGW__
ã«ä¿®æ£ããã__MINGW__ã¯MINGWã®åã¨å¾ã«ã¢ã³ãã¼ã¹ã³ã¢ã2ã¤ãã¤ããã¾ãã
(3) Eclipseã§testããã¸ã§ã¯ããå³ã¯ãªãã¯ãã¦Propertiesãéãã¾ããC/C++ General > Paths and Symbols > Symbolsãéãã¦Configurationã§[All Configuration]ãLanguagesã§C++ Source Fileãé¸æãNameã«__MINGW__ãValueã¯ç©ºã®ã¨ã³ããªã追å ã
10. å®è¡
Ctrl+F11ã§ããã°ã©ã ãå®è¡ã§ããã¬ãããã表示ãããã°å¤§æåï¼