stanford hci group / cs377s
Designing Applications that See Designing Applications that See Lecture 8: OpenCV
Dan Maynes-Aminzade 31 January 2008 31 January 2008
Designing Applications that See http://cs377s.stanford.edu
Designing Applications that See Designing Applications that See - - PowerPoint PPT Presentation
stanford hci group / cs377s Designing Applications that See Designing Applications that See Lecture 8: OpenCV Dan Maynes-Aminzade 31 January 2008 31 January 2008 Designing Applications that See http://cs377s.stanford.edu R Reminders i d
Designing Applications that See http://cs377s.stanford.edu
31 January 2008 2 Lecture 8: OpenCV
31 January 2008 3 Lecture 8: OpenCV
31 January 2008 4 Lecture 8: OpenCV
Capture, read, and write videos p Display video windows Handle mouse and keyboard events
31 January 2008 5 Lecture 8: OpenCV
31 January 2008 6 Lecture 8: OpenCV
OpenCV\docs
Edge detection: edge Segmentation: pyramid_segmentation Morphology morphology Morphology: morphology Histogram: demhist Distance transform: distrans Ellipse fitting: fitellipse
Color tracking camshiftdemo Color tracking: camshiftdemo Optical flow: lkdemo Motion segmentation: motempl Edge detection: laplace
31 January 2008 7 Lecture 8: OpenCV
http://sourceforge.net/projects/opencvlibrary
gunzip opencv-1.0.0.tar.gz g p p g tar –xvf opencv-1.0.0.tar cd opencv-1.0.0 / fi ./configure make make install
31 January 2008 8 Lecture 8: OpenCV
http://cs377s.stanford.edu/code/opencv-tutorial.zip
g++ basic cpp
g++ basic.cpp –o basic \
g g
31 January 2008 9 Lecture 8: OpenCV
31 January 2008 10 Lecture 8: OpenCV
31 January 2008 11 Lecture 8: OpenCV
31 January 2008 12 Lecture 8: OpenCV
#include <cv h> #include <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); cvReleaseImage(&img); }
31 January 2008 13 Lecture 8: OpenCV
IplImage* img = cvLoadImage("tennis jpg"); IplImage* img = cvLoadImage( tennis.jpg ); for (int x=0; x<img->width; x++) { for (int y=0; y<img->height; y++) { y y g g 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]=255–val; } } } cvSaveImage("tennis_inverted.jpg", img); cvReleaseImage(&img);
31 January 2008 14 Lecture 8: OpenCV
31 January 2008 15 Lecture 8: OpenCV
// Open the input video // Open the input video CvCapture *video = cvCaptureFromFile("stanley.avi"); // Query first frame cvQueryFrame(video); // Read video properties int width = cvGetCaptureProperty(video CV CAP PROP FRAME WIDTH); cvGetCaptureProperty(video,CV_CAP_PROP_FRAME_WIDTH); int height = cvGetCaptureProperty(video,CV_CAP_PROP_FRAME_HEIGHT); int nFrames = cvGetCaptureProperty(video,CV_CAP_PROP_FRAME_COUNT);
31 January 2008 16 Lecture 8: OpenCV
31 January 2008 17 Lecture 8: OpenCV
31 January 2008 18 Lecture 8: OpenCV
Image Processing Image Processing
cvSobel, cvLaplace, cvCanny, cvCornerHarris, cvGoodFeaturesToTrack, cvHoughLines2, cvHoughCircles
Optical Flow Optical Flow
cvCalcOpticalFlowPyrLK, cvFindFundamentalMat
Template Matching
h l h h l cvMatchTemplate, cvMatchShapes, cvCalcEMD2, cvMatchContourTrees
Motion
cvKalmanPredict, cvConDensation, cvAcc, cvMeanShift, cvCamShift
Segmentation and Grouping
cvSnakeImage, cvKMeans2, cvSeqPartition, cvCalcSubdivVoronoi2D, cvCreateSubdivDelaunay2D
Machine Learning
cvHaarDetectObjects
31 January 2008 19 Lecture 8: OpenCV