opencv open source c omputer v ision library by: bahare torkaman [email protected] fall 2010

36
OpenCV Open source Computer Vision library By: Bahare Torkaman [email protected] Fall 2010

Upload: agatha-brooks

Post on 26-Dec-2015

222 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

OpenCV

Open source Computer Vision libraryBy:

Bahare Torkaman

[email protected]

Fall 2010

Page 2: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

General description

Open source computer vision library in C/C++

High level functions for computer vision and image processing

Both low and high level API

Optimized and intended for real-time applications

OpenCV modules:

cv - Main OpenCV functions.

cvaux - Auxiliary (experimental) OpenCV functions.

cxcore - Data structures and linear algebra support.

highgui - GUI functions.

Page 4: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html

http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/cvision.htm

http://opencv.willowgarage.com/documentation/cpp/index.html

http://www.seas.upenn.edu/~bensapp/opencvdocs/ref/opencvref_cv.htm

http://tech.groups.yahoo.com/group/OpenCV/messages

http://opencv.willowgarage.com/wiki/

http://www.aishack.in/2010/02/capturing-images/

http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/

http://www.sharifi.id.ir/2010/08/opencv-1.html

Other webpages:

Page 5: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

InstallationOpenCV-2.1.0-win32-vs2008

Page 6: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Installation

Page 7: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Installation

Page 8: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 9: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 10: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 11: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 12: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 13: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 14: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Configuration

Page 15: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

New project

Page 16: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

New project

Page 17: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

New project

Page 18: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

New project

Page 19: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

New project

Page 20: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Add library

Page 21: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

cv210.lib cvaux210.lib cxcore210.lib cxts210.lib highgui210d.lib ml210d.lib opencv_ffmpeg210d.lib cv210d.lib cvaux210d.lib cxcore210d.lib highgui210.lib ml210.lib opencv_ffmpeg210.lib

Add library

Page 22: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Tools options project and solutions vc++ directories

executable files C:\OpenCV2.1\bin Include files C:\OpenCV2.1\include\opencv Library files C:\OpenCV2.1\lib

File new project win32 win32 console application application settings empty project … project add new item c++ file(.cpp)

Project properties configuration properties linker input additional dependencies

cv210.lib cvaux210.lib cxcore210.lib cxts210.lib highgui210d.lib ml210d.lib opencv_ffmpeg210d.lib cv210d.lib cvaux210d.lib cxcore210d.lib highgui210.lib ml210.lib opencv_ffmpeg210.lib

Page 23: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

#include <cv.h>#include <highgui.h>int main(){IplImage* img = cvLoadImage("C:\\orangeman.jpg"); cvNamedWindow("Original"); cvShowImage("Original", img); // We add processing code here cvWaitKey(0); cvReleaseImage(&img); return 0;}

Load a picture

Load video

Load camera

cut a piece of image

Page 24: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

#include <cv.h>#include <highgui.h>#include <cxcore.h>IplImage *frame = 0,*flip=0;int main(){CvCapture* capture = 0;capture = cvCaptureFromFile("C:\\cap2.avi");if(!capture) { printf("Could not initialize capturing...\n"); return -1; }while(true) { IplImage* frame = 0;

frame = cvQueryFrame(capture); if(!frame) break;

cvShowImage("video", frame);//cvFlip(frame,flip,0);cvShowImage("flip", frame);int c = cvWaitKey(20);if((char)c==27 )

break; } cvReleaseCapture(&capture); return 0;}

Load a picture

Load video

Load camera

cut a piece of image

Page 25: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

#include <stdio.h>#include "cv.h"#include "highgui.h"IplImage *frame = 0,*capture= 0;int main( int argc, char **argv ){CvCapture *capture =cvCreateCameraCapture(-1);IplImage *img;while(1){img=cvQueryFrame(capture);if(!img)break;cvShowImage("Original", img);char c=cvWaitKey(33);if(c==27) break;

}cvReleaseCapture(&capture);cvDestroyWindow("Original");return 0;}

Load a picture

Load video

Load camera

cut a piece of image

Page 26: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

#include <cv.h>#include <highgui.h>#include <cxcore.h>int main(){CvCapture* capture = 0;capture = cvCaptureFromCAM(0);while(true) {

IplImage* frame = 0;frame = cvQueryFrame(capture);

if(!frame) break;

cvShowImage("video", frame);cvSetImageROI( frame, cvRect( 10,60, 100,200 ) ); IplImage *img2 = cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels); cvCopy( frame, img2 ); cvShowImage("video2", img2);

cvResetImageROI( frame ); int c = cvWaitKey(20);

if((char)c==27 ) break; } cvReleaseCapture(&capture); return 0;}

Load a picture

Load video

Load camera

cut a piece of image

Page 27: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

This structure, called IplImage

OpenCV uses this structure to handle all kinds of images:

single-channel, multichannel, integer-valued, floating-point-

valued, et cetera.

IplImage

is a high-level routine

determines the file format to be loaded based on the file name

automatically allocates the memory needed for the image data

structure

can read a wide variety of image formats: BMP,DIB,JPEG,

JPE,PNG,PBM,PGM,PPM,SR,RAS, and TIFF

cvLoadImage()

Page 28: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Opens a window on the screen that can contain and

display an image

provided by the HighGUI library

Assigns a name to the window

The second argument to cvNamedWindow() defines

window properties→0 (the default value) : size of the window ↔ image size

image will be scaled to fit within the window→CV_WINDOW_AUTOSIZE :

the window will expand or contract automatically when an image is loaded so as to accommodate the image’s true size

image in the form of an IplImage* pointer

cvNamedWindow()

Page 29: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

The cvShowImage() function requires that a named window

already exist (created by cvNamedWindow())

cvShowImage()

asks the program to stop and wait for a keystroke

argument: positive : the program will wait for that number of

milliseconds and then continue even if nothing is pressed Zero or negative: the program will wait indefinitely for a

keypress

cvWaitKey(0)

Page 30: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

OpenCV expects a pointer to the IplImage* pointer for this operation

After the call is completed, the pointer img will be set to NULL

free the allocated memory

cvReleaseImage( &img )

close the window de-allocate any associated memory usage

cvDestroyWindow()

free the memory associated with the CvCapture structure close any open file handles to the AVI file

cvReleaseCapture(&capture)

Page 31: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

cvQueryFrame() takes as its argument a pointer to a CvCapture structure

grabs the next video frame into memory (memory that is actually part of the CvCapture structure)

cvQueryFrame()

index:

If there is only one camera or it does not matter what camera to use -1 may be passed

this is important only when multiple cameras are available

cvCreateCameraCapture (int index)

Page 32: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

Flip an array about a selected axis, around the x-axis, the y-axis, or both

the argument flip_mode is set to: 0: image will be flipped around the x-axis positive: image will be flipped around the y-axis negative: image will be flipped around both axis

cvSetImageROI(src1, cvRect(x,y,width,height));Given a rectangular subregion of interest“turn off ” by cvResetImageROI()

cvSetImageROI

cvFlip

Page 33: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

(int x, int y)

Int width

Int height

cvSetImageROI

Page 34: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

void cvCopy(const CvArr* src,CvArr* dst,const CvArr* mask = NULL);

Copy elements of one array to another The cvCopy() function expects both arrays to have the

same type, the same size, and the same number of dimensions

cvGetSize (const CvArr* arr )Get size of a two-dimensional array and return as CvSize

cvGetSize

cvCopy

Page 35: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

?????????

Page 36: OpenCV Open source C omputer V ision library By: Bahare Torkaman tr.bahareh@gmail.com Fall 2010

OpenCV

Open source Computer Vision library

By:

Bahare Torkaman

[email protected]

Fall 2010