OpenCV Open source C omputer V ision library By : Bahare Torkaman [email protected]
description
Transcript of OpenCV Open source C omputer V ision library By : Bahare Torkaman [email protected]
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:
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)
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:
InstallationOpenCV-2.1.0-win32-vs2008
Installation
Installation
Configuration
Configuration
Configuration
Configuration
Configuration
Configuration
Configuration
New project
New project
New project
New project
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 <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
#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
#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
#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
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
?????????
OpenCVOpen source Computer Vision library
By:Bahare Torkaman
Fall 2010