Designing Applications that See Designing Applications that See - - PowerPoint PPT Presentation

designing applications that see designing applications
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

R i d Reminders

Pi k A i t # if h ’t l d Pick up Assignment #1 if you haven’t already Assignment #2 due next Tuesday g y Fill out the interim course evaluation form

31 January 2008 2 Lecture 8: OpenCV

slide-3
SLIDE 3

T d ’ G l Today’s Goals

E l th biliti f th O CV Explore the capabilities of the OpenCV library Learn the basics of programming with OpenCV OpenCV Build a few working OpenCV examples Study other examples to learn more

31 January 2008 3 Lecture 8: OpenCV

slide-4
SLIDE 4

O tli Outline

G l i t d ti General introduction Basic video capture and display p p y Image processing examples l fl l Optical flow example Video writing Video writing Look at more examples (time permitting)

31 January 2008 4 Lecture 8: OpenCV

slide-5
SLIDE 5

Wh t i O CV? What is OpenCV?

O C/C t i i lib Open source C/C++ computer vision library Created and maintained by Intel Optimized for real-time applications Composed of four separate sub-libraries: p p

CXCORE: Linear algebra, matrix operations CV: Computer vision algorithms CV: Co pute v s o a go t s HIGHGUI: Media, window, and UI handling

Capture, read, and write videos p Display video windows Handle mouse and keyboard events

CVAUX: Experimental functionality (beta)

31 January 2008 5 Lecture 8: OpenCV

slide-6
SLIDE 6

O CV F t OpenCV Features

Image data manipulation Image data manipulation Image and video I/O Matrix and vector manipulation Matrix and vector manipulation Dynamic data structures Image Processing Image Processing Structural analysis Camera calibration Camera calibration Motion analysis Object recognition j g Basic GUI Basic drawing

31 January 2008 6 Lecture 8: OpenCV

slide-7
SLIDE 7

H l O CV Help on OpenCV

Reference Manuals Reference Manuals

OpenCV\docs

Image Processing Samples g g p

Edge detection: edge Segmentation: pyramid_segmentation Morphology morphology Morphology: morphology Histogram: demhist Distance transform: distrans Ellipse fitting: fitellipse

Video Processing Samples

Color tracking camshiftdemo Color tracking: camshiftdemo Optical flow: lkdemo Motion segmentation: motempl Edge detection: laplace

31 January 2008 7 Lecture 8: OpenCV

slide-8
SLIDE 8

I t lli O CV Installing OpenCV

D l d f S F Download from SourceForge

http://sourceforge.net/projects/opencvlibrary

Current version: 1.0.0 Windows version includes installer Installing in Linux (requires ffMPEG):

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

slide-9
SLIDE 9

C il ti I t ti Compilation Instructions

D l d th l d h Download the sample code here:

http://cs377s.stanford.edu/code/opencv-tutorial.zip

Compiling in Linux:

g++ basic cpp

  • basic \

g++ basic.cpp –o basic \

  • I /usr/local/include/opencv -L /usr/local/lib \
  • lm -lcv -lhighgui –lcvaux

g g

Compiling in Windows:

St t Vi l St di d f ll l ! Start Visual Studio and follow along now!

31 January 2008 9 Lecture 8: OpenCV

slide-10
SLIDE 10

Ch k Wi d P th Check Windows Path

Sh ld i l d O CV\bi Should include OpenCV\bin

31 January 2008 10 Lecture 8: OpenCV

slide-11
SLIDE 11

Update Visual Studio Directories Update Visual Studio Directories

I l d di t i Include directories

OpenCV\cv\include OpenCV\cxcore\include OpenCV\otherlibs\highgui OpenCV\cvaux\include

Library directories Library directories

OpenCV\lib

31 January 2008 11 Lecture 8: OpenCV

slide-12
SLIDE 12

U d t P j t Li k S tti Update Project Link Settings

Li k i t Link against the OpenCV libraries libraries

cv.lib lib cxcore.lib highgui.lib (for HIGHGUI (for HIGHGUI support) cvaux lib cvaux.lib (for CVAUX support)

31 January 2008 12 Lecture 8: OpenCV

slide-13
SLIDE 13

B i E l Basic Example

#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

slide-14
SLIDE 14

Pi l P i Pixel Processing

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

slide-15
SLIDE 15

U i Wi d Using Windows

N dWi d ("I Wi d ") cvNamedWindow("ImageWindow"); cvShowImage("ImageWindow", img); W itK (0) cvWaitKey(0);

31 January 2008 15 Lecture 8: OpenCV

slide-16
SLIDE 16

L di Vid Loading Video

// 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

slide-17
SLIDE 17

O ti l Fl Optical Flow

C l O ti lFl P LK( l tf cvCalcOpticalFlowPyrLK(grlastframe, 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 17 Lecture 8: OpenCV

slide-18
SLIDE 18

S i Vid Saving Video

// Open a video writer to save the output // Open a video writer to save the output CvVideoWriter *writer = cvCreateVideoWriter("output avi" cvCreateVideoWriter( output.avi ,

  • 1, 30, cvSize(width, height));

// Write some frames cvWriteFrame(writer lastframe); cvWriteFrame(writer, lastframe); // R l h fi i h d // Release when finished cvReleaseVideoWriter(&writer);

31 January 2008 18 Lecture 8: OpenCV

slide-19
SLIDE 19

F ti t Ch k O t Functions to Check Out

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