360 likes | 533 Views
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++ H igh level functions for computer vision and image processing Both low and high level API
E N D
OpenCV Open source Computer Vision library By: BahareTorkaman tr.bahareh@gmail.com Fall 2010
General description • Open source computer vision library in C/C++ • Highlevelfunctions for computer vision and image processing • Both low and high level API • Optimized and intended for real-time applications • OpenCVmodules: • cv - Main OpenCV functions. • cvaux - Auxiliary (experimental) OpenCV functions. • cxcore - Data structures and linear algebra support. • highgui - GUI functions.
Resources • Official webpage: http://www.intel.com/technology/computing/opencv/ • Software download: http://sourceforge.net/projects/opencvlibrary/ • Books: • Learning OpenCV by Gary R. Bradski and Adrian Pisarevsky, O’Reilly (September 2008: First Edition)
Other webpages: 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
Installation OpenCV-2.1.0-win32-vs2008
Add library 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
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
Load a picture #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 video Load camera cut a piece of image
#include <cv.h> #include <highgui.h> #include <cxcore.h> IplImage*frame = 0,*flip=0; intmain() { 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
#include <stdio.h> #include "cv.h" #include "highgui.h" IplImage *frame = 0,*capture= 0; int main( intargc, 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
#include <cv.h> #include <highgui.h> #include <cxcore.h> intmain() { 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 ); intc = cvWaitKey(20); if((char)c==27 ) break; } cvReleaseCapture(&capture); return 0; } Load a picture Load video Load camera cut a piece of image
IplImage • This structure, called IplImage • OpenCV uses this structure to handle all kinds of images: single-channel, multichannel, integer-valued, floating-point-valued, et cetera. cvLoadImage() • 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
cvNamedWindow() • Opens a window on the screen that can contain and display an image • provided by the HighGUIlibrary • 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
cvShowImage() • The cvShowImage() function requires that a named window already exist (created by cvNamedWindow()) cvWaitKey(0) • 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
cvReleaseImage( &img ) • OpenCVexpects 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 cvDestroyWindow() • close the window • de-allocate any associated memory usage cvReleaseCapture(&capture) • free the memory associated with the CvCapture structure • close any open file handles to the AVI file
cvQueryFrame() • 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) cvCreateCameraCapture (int index) • 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
cvFlip • 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 • cvSetImageROI(src1, cvRect(x,y,width,height)); • Given a rectangular subregion of interest • “turn off ” by cvResetImageROI()
cvSetImageROI Int height (int x, int y) Int width
cvCopy • void cvCopy(const CvArr* src,CvArr* dst,constCvArr* 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 • cvGetSize (const CvArr* arr ) • Get size of a two-dimensional array and return as CvSize
OpenCV Open source Computer Vision library By: BahareTorkaman tr.bahareh@gmail.com Fall 2010