CSDL Opencv- Tutorial

  • View
    422

  • Download
    0

Embed Size (px)

Transcript

HNG DN TO C S D LIU CHO VIC NHN DIN I TNG BNG OPENCV Kiu 1: Ly ngun t mt nh th s to 10 nh vector ( -num 10 )

Kiu 2 : To vi nhiu nh th s khng to nhiu nh vector

Do qu trnh tip cn vi Opencv ngn nn mnh khng trnh khi nhiu sai st , mong nhn c phn hi , gp gi v jackauk@yahoo.com. Chc cc bn thnh cng !

Hng dn ci t OpenCV 2.0 trn Visual Studio 2008Nguyn Quang Yn - 2010 1. Ci t OpenCV 2.0 Cac bn ti OpenCV 2.0 v ti y (OpenCV-2.0.0a-win32.exe (25.7 MB)). Sau ci t vo mt th mc no , vd y mnh ci vo C:\OpenCV2.0 2. Buld OpenCV vi Cmake Ti CMake ti y. Cmake lm nhim v to file d n cho nhiu mi trng phat trin khac nhau s dng scripts. Chng ta s dng Cmake to solution trong Visual Sutido v dng VS build nhng file cn thit (.dll v .lib) cho OpenCV2.0 Ci t CMake, khi ng li my cp nht bin mi trng cho CMake. Khi ng CMake ln.

-

Ch Where is the source code cac bn tr vo th mc ci OpenCV2.0 khi ny. Ch Where to build the binaries cac bn tr vo mt th mc no y s ch solution c to ra. Nhn Configure v chn mt mi trng phat trin thich hp ( y mnh chn VS2008) Trong khung ca s chn, cac bn chn nhng phn cn to ra ( y chng ta cn to th vin nn chn OPENCV_BUILD_3RDPARTY_LIBS Nhn Generate v CMake s t chy sinh ra file cho bn. M th mc ni file c to ra, m Solution ln bng VS2008.

-

Chn nhng project nh trn build. Nhn chut phi chn Build Selection. Ngi i cho xong

3. Build file lib v th vin ng M vo th mc cha solution (nh ca mnh l E:\Laptrinh Softs\openCVlib) vo lib\Debug v lib\Release chep tt c file .lib vo th mc ci OpenCV\lib (ca mnh l C:\OpenCV2.0\lib). Ta c :

-

Vy l xong phn chep file .lib. Gi ta vo th mc E:\Laptrinh Softs\openCVlib vo bin\Debug v bin\Release s thy cac file .dll. Ta s chep chng vo nhng d n ca mnh sau.

4. Cu hnh VS2008 Ta m VS2008, vo ToolOptionsProjects and SolutionsC++ Directories

-

Ch Show directories for chn Include files: To 2 directory mi dn ti th mc ci OpenCV2.0 (ca mnh l C:\OpenCV2.0)

5. Cu hnh Project To mt project bt u code. Project kiu Win32 Console Application ngn ng C++. Gi s project tn l LearnOpenCV2.0 Nhn chut phi vo Project, chn Properties

-

Vo Configuration PropertiesLinkerInput Chn th Configuration l debug, g vo Additional Dependencies l : cv.lib cvaux.lib cxcore.lib cxts.lib cvhaartraining.lib highgui.lib ml.lib opencv_ffmpeg.lib Chn th Configuration l release, cng g tng t. Nhn OK. Vo th mc ca Solution ca project ny(LearnOpenCV2.0) bin. To 2 th mc l Debug v Release. Chep tt c cac file .dll t E:\Laptrinh Softs\openCVlib\bin\Debug v E:\Laptrinh Softs\openCVlib\bin\Release vo ln lt 2 th mc mi to trn. Trong source files, to mt file DisplayImageVideo.cpp v g vo nh sau :#include #include int main(int argc, char** argv) { //Load image into img IplImage* img = cvLoadImage("/images/dog.jpg"); //Create a window with name "Vidu coban" type autosize cvNamedWindow("Vidu coban", CV_WINDOW_AUTOSIZE); //Show the image into that window cvShowImage("Vidu coban", img); //Wait for a key pressed cvWaitKey(0); //Then release image and destroy window cvReleaseImage(&img); cvDestroyWindow("Vidu coban"); } return 0;

- Ch trong on code trn, ta phi c mt nh dog.jpg nm trong th mc images t ti th mc ca project ny.

- Nhn F5, nu kt qu nh di y tc l bn ci t v cu hnh thnh cng. Chuc mng.

- Nu hin li thng bo thiu file .dll, bn m li solution do CMake to ra build ng project b thiu, sau chep file vo 2 th mc Debug v Release.

Ci t th vin OpenCV 1.1vOpen CV l b th vin m ngun m v Computer Vision ca Intel. N cung cp mt b m ngun bao gm hng trm hm, lp m ng dng cc thut tan v x l nh cng nh Computer vision dng ngn ng C/C++. Trc khi bn s dng n ng nhin trn my phi c b cng c pht trin VS 6.0, VS.Net ca microsoft. Khi vit bi ny ti s dng vi Visual studio .Net 2005 cho cc d n ca mnh. Vui lng thc hin cc bc sau y ci t Open CV: 1. Download bn ci t Open CV ti y. Tt nht bn nn s dng bn mi nht. 2. Click vo file ci t ci Open CV vo my. Sau khi hon tt bn nn c biu tng Open CV trn start menu ca bn. 3. To lin kt trong system PATH ca Window ti OpenCV DLLs theo cc bc sau:

Click My Computer > Properties > Advanced > Environment Variables > Systems variable > highlight PATH > Edit. Thm C:\Program Files\OpenCV\bin vo PATH. ng dn ca OpenCV DLL files c th khc mt cht ty theo v tr bn ci n, nh phn bit vi cc ng dn khc bng du (;) Nu OpenCV ca bn ang c m, bn nn ng n sau m li PATH mi c th tc dng.

4. Sau khi ci t xong Open Cv n s t ng detect c b VS 2005 trn my tnh ca bn. Tip theo bn phi m VS ln cu hnh cc thng tin reference v ng dn file .h, library trong GLOBAL OPTIONS. Vic ny s gip bn ch cn lm mt ln m khng cn thc hin config cho mi d n c s dng OPEN CV. Vui lng theo di cc hnh sau c th tin hnh tng bc.

Sau khi han tt cc bc gi bn c th bt u pht trin vi Open CV. im xut pht tt nht cho mi ngi l hy th vi cc example trc :). V bn s khng khi thc mc ti sao chng trnh bin dch li bo li, h h ng lo lng hy vo trang property ca project v thc hin tip nhng g cn st li .

Nu vn cn li lin kt xy ra bn c th th thm vo mt s lib na ty theo cc hm m bn s dng: odbc32.lib odbccp32.lib cxcored.lib cvd.lib highguid.lib cv.lib cvaux.lib