OpenCV Open source C omputer V ision library By: Bahare Torkaman 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.
Resources Official webpage: Software download: Books: Learning OpenCV by Gary R. Bradski and Adrian Pisarevsky, O’Reilly (September 2008: First Edition)
Other webpages:
Installation OpenCV win32-vs2008
Installation
Configuration
New project
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 Add library
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
#include 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
#include 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
#include #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
#include 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
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()
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()
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)
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)
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 )
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
(int x, int y) Int width Int height cvSetImageROI
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
?????????
OpenCV Open source C omputer V ision library By: Bahare Torkaman Fall 2010