Anda di halaman 1dari 29

Computer Vision

SS 2008
Tutorial/Lab II
MSc in CS Moritz Vieth

Overview
Reading Programming

in CV

Basic steps OpenCV Starter kit The CV Lab


Equipment Accounts Source control (SVN)


Tutorial/Lab I 2

SS 2008

Readings
What

is the main underlying problem of CV? What is a model? What are the four representations presented in the reading? In which way can concepts of AI/Machine Learning aid CV? Does CV have to exactly reproduce the human perception system? Name some CV applications (and their means)
SS 2008 Tutorial/Lab I 3

Programming in CV
Basic

tasks:

Data acquisition
Single

images Image sequences (video file/camera)

Image processing
Manipulation Analysis

Output
Display Files etc.

SS 2008

Tutorial/Lab I

OpenCV
Open

Source Library

Originally developed by Intel Written in C/C++ (but mostly C) http://opencvlibrary.sourceforge.net/ Basic functions and structures
Advanced Head

algorithms

start into CV programming

Nomenclature:
SS 2008

Methods start with cv (lowercase) Structures start with Cv (uppercase)


Tutorial/Lab I 5

OpenCV: Basic Functions


Structures

& methods for

Image handling Image acquisition Single image file Video file Camera Image manipulation Output Display Save to file
Tutorial/Lab I 6

SS 2008

OpenCV: Advanced Algorithms


Algorithms

and functions commonly used in CV applications Edge/Corner detection Pattern matching Structural analysis Motion detection Tracking Calibration (not that good, use MATLAB instead) Face Detection ...
Tutorial/Lab I 7

SS 2008

Using OpenCV
Image

acquisition (single file)

#include"cv.h" #include"highgui.h" intmain(intargc,char**argv) { IplImage*img; if(img=cvLoadImage(image.jpg, CV_LOAD_IMAGE_COLOR))!=0) { doSomething(img);//yourprocessingmethod cvWaitKey(5);//veryimportant,containsevent //processingloopinside return0; } return1; }

SS 2008

Tutorial/Lab I

Using OpenCV
Image

acquisition (video file)

#include"cv.h" #include"highgui.h" intmain(intargc,char**argv) { IplImage*img; CvCapture*capture=cvCaptureFromFile(video.mpg); while(img=cvQueryFrame(capture)!=0)) { doSomething(img);//yourprocessingmethod cvWaitKey(5);//veryimportant,containsevent //processingloopinside return0; } cvDestroyCapture(&capture); return1; }
SS 2008 Tutorial/Lab I 9

Using OpenCV
Image

acquisition (camera)

#include"cv.h" #include"highgui.h" intmain(intargc,char**argv) { IplImage*img; CvCapture*capture=cvCaptureFromCAM(0); while(img=cvQueryFrame(capture)!=0)) { doSomething(img);//yourprocessingmethod cvWaitKey(5);//veryimportant,containsevent //processingloopinside return0; } cvDestroyCapture(&capture); return1; }
SS 2008 Tutorial/Lab I 10

Using OpenCV
Image

handling: Accessing a pixel

//Setpixelvalue: //IplImage*image,intchannel,intvalue (((uchar*)(image>imageData+image>widthStep*(y))))[x* image>nChannels+channel]=(uchar)value; //Getpixelvalue: //IplImage*image,intchannel,intvalue value=(((uchar*)(image>imageData+image>widthStep*(y))) [(x*image>nChannels)+channel];

Easy,

isn't it?

We'll come back to that


Tutorial/Lab I 11

SS 2008

Using OpenCV
Image

manipulation: Drawing

IplImage*img; if(img=cvLoadImage(image.jpg,CV_LOAD_IMAGE_COLOR))!=0) { //drawaredrectanglefrom(20,20)to(100,100) cvRectangle(img,cvPoint(20,20),cvPoint(100,100), CV_RGB(255,0,0)); cvWaitKey(5);//veryimportant,containsevent //processingloopinside }

Same

goes for cvCircle, cvLine, cvEllipse, ...

SS 2008

Tutorial/Lab I

12

Using OpenCV
Image

manipulation: Color conversion

IplImage*img; IplImage*hsv_img; if(img=cvLoadImage(image.jpg,CV_LOAD_IMAGE_COLOR))!=0) { hsv_img=cvCreateImg(cvGetSize(img),8,3); cvCvtColor(img,hsv_img,CV_BGR2HSV); cvWaitKey(5);//veryimportant,containsevent //processingloopinside }

SS 2008

Tutorial/Lab I

13

Using OpenCV
Image

output: Windows

CvCapture*capture=cvCaptureFromCAM(0); IplImage*frame=cvQueryFrame(capture) cvNamedWindow("myWindow",CV_WINDOW_AUTOSIZE); while(frame!=0){ cvShowImage(myWindow,frame); cvWaitKey(5); frame=cvQueryFrame(capture); } cvReleaseCapture(&capture); cvDestroyWindow(myWindow);

Windows

are created and referenced by name You can use as many NamedWindows as you like
SS 2008 Tutorial/Lab I 14

Using OpenCV
Image

output: Saving

IplImage*img; if(img=cvLoadImage(image.jpg,CV_LOAD_IMAGE_COLOR))!=0) { //drawaredrectanglefrom(20,20)to(100,100) cvRectangle(img,cvPoint(20,20),cvPoint(100,100), CV_RGB(255,0,0)); cvWaitKey(5);//veryimportant,containsevent //processingloopinside cvSaveImage(image.bmp,img); return0; }

SS 2008

Tutorial/Lab I

15

Using OpenCV
Interactivity
CvCapture*capture=cvCaptureFromCAM(0); IplImage*frame=cvQueryFrame(capture); cvNamedWindow("myWindow",CV_WINDOW_AUTOSIZE); intkey=0; while(frame!=0&&key!='c'){ cvShowImage(mywindow,frame); frame=cvQueryFrame(capture); key=cvWaitKey(250); } cvReleaseCapture(&capture); cvDestroyWindow(myWindow);

[spot the error]


SS 2008 Tutorial/Lab I 16

OpenCV: Compiling
If

you are compiling OpenCV from scratch, don't forget to add ffmpeg support! To compile programs using OpenCV:

Specify the include path: Specify the library path:


-L/usr/local/lib/

-I/usr/local/include/opencv

(or wherever you installed it) Tell the linker to use the shared libraries:
-lcv -lcvaux -lhighgui

SS 2008

Tutorial/Lab I

17

OpenCV: Compiling
Common

->

errors:

Undefined reference to... when compiling/linking


Make sure you have linked to the libs (-l...), and set the library path correctly (-L...)

Undefined reference to... when starting the program


Tell

the shell how to find the shared libraries (Linux:) export LD_LIBRARY_PATH=/usr/local/lib
(or wherever the missing libs are)

SS 2008

Tutorial/Lab I

18

OpenCV: Examples
Find

Circles in an Image:

cvHoughCircles(...)

[Images by Thomas Hofhammer]


SS 2008 Tutorial/Lab I 19

OpenCV: Examples
Detect

Faces:

cascade = (CvHaarClassifierCascade*) cvLoad( cascade_name, 0, 0, 0 ); CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,1.1, 2, 0, cvSize(30, 30) );

www.lenna.org

SS 2008

Tutorial/Lab I

20

See it live
A

short demo
Read and display a video stream Paint circles React to user input

SS 2008

Tutorial/Lab I

21

CvUtils
OpenCV

is not complete
pixel access?

Sometimes a little complicated


Remember

Some (utility) functions are just missing

CvUtils

SS 2008

library (by me)

ImageUtils -> Mostly access and drawing MathUtils -> Frequently used shortcuts Pixel -> used to store coordinates along with color Blob -> a collection of pixels ParFile (by Stefan Hahne) -> Easy config file access
Tutorial/Lab I 22

Starter Kit
Should

accelerate the getting started part A bit more sophisticated than the demo Main file

reads config file and command line

Controller Basic

input (video file or camera) Basic output (one main window) Error codes Uses CvUtils
SS 2008 Tutorial/Lab I 23

Output Library
Shared

library for output Used to format output Controls output level (no more searching for those DEBUG messages) Automated logging Automatic display of function names (if desired) Thread-safe Backtrace support (for Linux/Unix) Silly name (niftout)
SS 2008 Tutorial/Lab I 24

Equipment
Equipment

Color

available for projects:

Various IEEE1394 industrial cams


or b/w, mostly 640x480 Various lenses (wide angle and tele)

Sony IEEE1394 zoom cams Several USB webcams 2 (3) PTZ cams Tripods

Some

SS 2008

other stuff (e.g. Stereo Cam) in the RoboCup lab


Just ask them!
Tutorial/Lab I 25

CV-Lab
You

can work on your projects in the CV lab

Get accounts on the lab server Work on fast machines (some dual or quad core) Multiple FireWire support

Use

source control

There is a SVN repository on the lab server Access via lab account ->Ask!

SS 2008

Tutorial/Lab I

26

Project Proposals
Contents

Name(s) of Student(s) Student ID(s) (Matr. Nr.) Title of the CV project (after approval of the instructor) Description of the CV project (plan of attack) (max. 2 pages, incl. graphics) (kind of working contract between you and me) References (min. 2 peer reviewed) of a project proposal
SS 2008 Tutorial/Lab I 27

Project Proposals
Description

What

of the CV project should contain:

Introduction
is the project about? What is the context of the project? What is the Motivation?

Materials
What

is the Equipment needed? What setup do you have in mind?

Methods
How

are you going to achieve your goals? (CV methods, not a storyline)

SS 2008

Tutorial/Lab I

28

Project Proposals
Description

(cont'd):

of the CV project should contain

Assumptions
What

are the prerequisites for your project (e.g. lighting conditions, background, etc.)? What are the restrictions on you project? What may be changed in the environment?

Expected results Distinction: who does what?

SS 2008

Tutorial/Lab I

29

Anda mungkin juga menyukai