Professional Documents
Culture Documents
http://cs377s.stanford.edu
Reminders R i d
Pick Pi k up A i Assignment # if you h t #1 havent already t l d Assignment #2 due next Tuesday g y Fill out the interim course evaluation form
31 January 2008
Lecture 8: OpenCV
Todays Goals T d G l
Explore the capabilities of the O E l th biliti f th OpenCV CV library Learn the basics of programming with OpenCV Build a few working OpenCV examples Study other examples to learn more
31 January 2008
Lecture 8: OpenCV
Outline O tli
General i t d ti G l introduction Basic video capture and display p p y Image processing examples Optical flow example l fl l Video writing Look at more examples (time permitting)
31 January 2008
Lecture 8: OpenCV
OpenCV F t O CV Features
Image data manipulation Image and video I/O Matrix and vector manipulation Dynamic data structures Image Processing Structural analysis Camera calibration Motion analysis Object recognition j g Basic GUI g Basic drawing
31 January 2008 Lecture 8: OpenCV 6
Help H l on O OpenCV CV
Reference Manuals
OpenCV\docs
Current version: 1.0.0 Windows version includes installer Installing in Linux (requires ffMPEG):
g gunzip opencv-1.0.0.tar.gz p p g tar xvf opencv-1.0.0.tar cd opencv-1.0.0 ./configure / fi make make install
31 January 2008 Lecture 8: OpenCV 8
Compilation Instructions C il ti I t ti
Download the sample code here: D l d th l d h
http://cs377s.stanford.edu/code/opencv-tutorial.zip
Compiling in Linux:
g++ basic cpp o basic \ basic.cpp o -I /usr/local/include/opencv -L /usr/local/lib \ g g -lm -lcv -lhighgui lcvaux
Compiling in Windows:
Start Vi l St di St t Visual Studio and follow along now! d f ll l !
31 January 2008
Lecture 8: OpenCV
31 January 2008
Lecture 8: OpenCV
10
Library directories
OpenCV\lib
31 January 2008
Lecture 8: OpenCV
11
Basic E B i Example l
#include <cv h> <cv.h> #include <highgui.h> int main(int argc, char *argv[]) { IplImage* img = cvLoadImage("tennis.jpg"); cvFlip(img, img); cvSaveImage("tennis_flipped.jpg", img); cvReleaseImage(&img); }
31 January 2008
Lecture 8: OpenCV
13
Pixel Processing Pi l P i
IplImage* img = cvLoadImage("tennis jpg"); cvLoadImage( tennis.jpg ); for (int x=0; x<img->width; x++) { y y<img->height; y g g y++) { for (int y=0; y for (int c=0; c<img->nChannels; c++) { int idx=x*img->nChannels+y*img->widthStep+c; int val=img->imageData[idx]; img->imageData[idx]=255val; } } } cvSaveImage("tennis_inverted.jpg", img); cvReleaseImage(&img);
31 January 2008
Lecture 8: OpenCV
14
Using Wi d U i Windows
cvNamedWindow("ImageWindow"); N dWi d ("I Wi d ") cvShowImage("ImageWindow", img); cvWaitKey(0); W itK (0)
31 January 2008
Lecture 8: OpenCV
15
31 January 2008
Lecture 8: OpenCV
16
Optical Flow O ti l Fl
cvCalcOpticalFlowPyrLK(grlastframe, C l O ti lFl P LK( l tf grcurrframe, pyramid1, pyramid2, lastframe_features, currframe_features, lastframe features currframe features nFeatures, cvSize(3,3), 5, found_features, feature_error, , , cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, .3 ), 0);
31 January 2008
Lecture 8: OpenCV
17
31 January 2008
Lecture 8: OpenCV
18
Optical Flow
cvCalcOpticalFlowPyrLK, cvFindFundamentalMat
Template Matching
cvMatchTemplate, cvMatchShapes, cvCalcEMD2, h l h h l cvMatchContourTrees
Motion
cvKalmanPredict, cvConDensation, cvAcc, cvMeanShift, cvCamShift
Machine Learning g
cvHaarDetectObjects
31 January 2008 Lecture 8: OpenCV 19