Skip to content

Instantly share code, notes, and snippets.

@ozooxo
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozooxo/aa52bf11ebcdb55cf3e4 to your computer and use it in GitHub Desktop.
Save ozooxo/aa52bf11ebcdb55cf3e4 to your computer and use it in GitHub Desktop.
openCV miscellaneous

linux這邊就沒有事先被compile好的版本,具體compile可以follow這個link

cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

前面CMAKE_INSTALL_PREFIX是設置裝在哪裡,make會在release/下面放一堆臨時文件,然後make install會把需要的文件裝去/usr/local

裝上的文件:/usr/local/include下面一坨.h,/usr/local/lib下面一坨.so。

設置Code::Blocks的library,這個blog很好用。(1)去project > build options ...linker settings下面加所有的.so,(2)search directories > compiler下面加所有的.h位置,就是

/usr/local/include/opencv
/usr/local/include/opencv2

然後(3)search directories > linker下面加usr/local/lib。大功告成hello world。

######P.S

不推薦在windows下面setup Code::Blocks,因為需要重新compile,所有cmake之類都要在windows上裝一遍。

######PS.PS

Remember to right click the project and "save project", otherwise the path setting will be lost.

openCV的windows版的一個特別之處,是有對visual studio一些版本的pre-compile(比如2.4.10有支持vc10/11/12的x86和x64)。exe幾乎只是被extract到指定位置(不確定為什麼,但需要admin運行)。

如果只是打算用vc,用這個link最後一段設全局path。在我完全不知道怎麼用的繁體中文windows 7上,可以在search那裡輸path,然後出現的『編輯系統環境變數』就是了。它的效果和

setx -m OPENCV_DIR C:\OpenCV\Build\x86\vc12

是一樣的。需要確認一下vc的版本,比如我是visual studio community 2013 == vc12。

之後設library可以基本follow這個link。唯一的差別是,global library在2010之後變得很難設,比如按說得,consoleApp的話其實就是新開個project。所以就新開個project,按照上面那個link的說法把library設好。

基本這邊重要的是三個folder,

lib/一群.lib bin/一群.dll include/一群.h

前兩個是compile得的,這邊偷懶不compile,就在C:\OpenCV\Build\x86\vc12下面。對於這邊的情形,照著之前那個link把library位置一一填入該進的空。注意debug和release的project property是獨立的,

要分別填入。對於release版,具體說(1)Property > Configuration Properties > C/C++ > General > Additional Include Dictionaries下填入$(OPENCV_DIR)\..\..\include,(2)Property > Configuration Properties > Linker > General > Additional Library Dictionaries下填入$(OPENCV_DIR)\lib,(3)Property > Configuration Properties > Linker > Input > Additional Dependencies下填入

opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib

然後就應該能run hello world了。唯一要注意的是,add .lib file的時候,要記得把版本號and whether it is the debugging version *d改對。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment