SS 2008
Tutorial/Lab II
MSc in CS Moritz Vieth
Overview
Reading Programming
in CV
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
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
Nomenclature:
SS 2008
Image handling Image acquisition Single image file Video file Camera Image manipulation Output Display Save to file
Tutorial/Lab I 6
SS 2008
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
#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
#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
Easy,
isn't it?
SS 2008
Using OpenCV
Image
manipulation: Drawing
Same
SS 2008
Tutorial/Lab I
12
Using OpenCV
Image
SS 2008
Tutorial/Lab I
13
Using OpenCV
Image
output: Windows
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
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);
OpenCV: Compiling
If
you are compiling OpenCV from scratch, don't forget to add ffmpeg support! To compile programs using OpenCV:
-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:
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(...)
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?
CvUtils
SS 2008
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
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
Sony IEEE1394 zoom cams Several USB webcams 2 (3) PTZ cams Tripods
Some
SS 2008
CV-Lab
You
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
Introduction
is the project about? What is the context of the project? What is the Motivation?
Materials
What
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):
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?
SS 2008
Tutorial/Lab I
29