140 likes | 161 Views
Computer Vision. Resources: OpenCV David Pycock D.Pycock@bham.ac.uk www.bham.ac.uk/pycockd. OpenCV. Windows program based on Intel IP Library More than 300 functions Features Multi-platform Provides a simple window manager with sliders mouse call backs etc
E N D
Computer Vision Resources: OpenCV David Pycock D.Pycock@bham.ac.uk www.bham.ac.uk/pycockd
OpenCV • Windows program based on Intel IP Library • More than 300 functions • Features • Multi-platform • Provides a simple window manager with sliders mouse call backs etc • Uses Intel Integrated Performance Primitives to enhance performance • Tutorials & Documentation • Sample code • Download from • sourceforge.net/projects/opencvlibrary/ • Operates under • Windows 95/98/NT/2000/XP • POSIX Linux/BSD/OSX/Win2K/WinXP
Image Input (HighGUI) • Still images from file • Using cvLoadImage() IplImage* cvLoadImage(const char* filename, int iscolor=1); Returns a pointer to an ipl image Filename: the name of the image file iscolor: >0 image is loaded as 3 channel colour 0 image is loaded as grey-level <0 No. of channels determined by file • File formats • Windows bitmaps: bmp, DIB • JPEG files: jpeg, jpg, jpe • Portable Network Graphics: png • Portable image format: pbm, pgm, ppm • Sun raster: sr, ras • Tiff Files: tiff, tif
Load and Display an Image /* usage: prog <image_name> */ #include "cv.h“ /* OpenCV data types and prototypes */ #include "highgui.h“ /* Image read and display*/ int main( int argc, char** argv ) {IplImage* img; if(argc==2 && (img=cvLoadImage(argv[1], 1)) !=0) {cvNamedWindow("Image view", 1); cvShowImage("Image view", img); cvWaitKey(0); /*very important, contains event */ /*processing loop inside */ cvDestroyWindow("Image view"); cvReleaseImage(&img); return 0; } return -1; }
Image Display (HighGUI) • Need to register image window and display it • int cvNamedWindow(const char* name, int flags);name: id name and text on image bannerint: 1, autosize to fit the image • void cvShowImage(const char* name, const CvArr* img);name: id name and text on image bannerimg: pointer to image to be displayed • CvCapture* cvCaptureFromFile(const char* fname);fname: video file name • CvCapture* cvCaptureFromCAM(int index);index: positive integer specifies video source
Other Libraries:(CV) • Image Processing • Edges, filters, morphologic operators, pyramids, histograms, boundary tracing • Structural analysis • Contour processing, computational geometry • Motion Analysis and Object Tracking • Object tracking, optical flow, motion templates • Pattern Recognition • Camera calibration and 3D Reconstruction • Camera calibration, pose estimation, epipolar geometry
Other Libraries:cxcore • Operations on arrays • Linear algebra, statistics, random number generator • Dynamic structures • Trees, graphs, sets, sequences • Drawing • Curves, text, point sets, contours
Other Libraries:ML • Machine Learning • Bayes classifier • K-nearest neighbour classifier • Support Vector Machine • Decision Trees • Boosting • Random Forest • Expectation Maximisation • Neural Networks
Other Libraries:CvCam/Cvaux • CvCam • Video Input / Output • Select and set up a camera • Render a video stream • Control the Video • Process video frames • Multiple cameras under Linux and Windows • Cvaux • Experimental functions
Key tips • IplImage data Types • IPL_DEPTH_8U unsigned 8 bit • IPL_DEPTH_8S signed 8 bit • IPL_DEPTH_16U unsigned 16 bit • IPL_DEPTH_16S signed 16 bit • IPL_DEPTH_32S signed 32 bit • IPL_DEPTH_32F single precision floating point • IPL_DEPTH_ 64F double precision floating point • Channels: 1, 2, 3 or 4 sequence is: b0, g0, r0, b1, g1, r1 • Accessing image pixels • Coordinates are indexed from 0 • Origin is top left or bottom left • To access an element of an 8-bit 1-channel image,I (IplImage* img):I(x,y)~ ((uchar*)(img->imageData + img->widthStep*y)[x]
To access an element of an 8-bit 3-channel image,I (IplImage* img):I(x,y)blue~ ((uchar*)(img->imageData + img->widthStep*y)[x*3]I(x,y)green~ ((uchar*)(img->imageData + img->widthStep*y)[x*3+1]I(x,y)red~ ((uchar*)(img->imageData + img->widthStep*y)[x*3+2] • To access an element of a 32-bit floating point 1-channel image, I (IplImage* img):I(x,y)~ ((float*)(img->imageData + img->widthStep*y)[x]
In general to access an element of an N-channel image of type TI(x,y)c~ ((T*)(img->imageData + img->widthStep*y)[x*N+c] • More simply using the provided macroCV_IMAGE_ELEM(img, T, y, x*N+c) • Efficient way to increment brightness of point(100, 100) by 30CvPoint pt = {100, 100};uchar *tmp_ptr=&((uchar*)(img->ImageData + img->widthStep*pt.y))[x*3];tmp_ptr[0]+=30;tmp_ptr[1]+=30;tmp_ptr[2]+=30;
Key Resources • A brief intro to OpenCV:www.cs.iit.edu/~agam/cs512/lect-notes/ opencv-intro/index.html • A more detailed guide (also describes DirectX/DirectShow):http://www.site.uottawa.ca/~laganier/tutorial/ opencv+directshow/cvision.htm • Wikipediahttp://en.wikipedia.org/wiki/OpenCV • BookLearning OpenCV: Computer Vision with the OpenCV Library (Paperback)Gary Bradski and Adrian KaehlerO'Reilly Media, Inc. (15 Jul 2008) ISBN 0596516134
General Resources • The Computer Vision home page at Carnegie Mellon Universitywww.cs.cmu.edu/afs/cs/project/cil/ftp/html/vision.html • Includes an online publications page:www.cs.cmu.edu/afs/cs/project/cil/www/v-pubs.html • Hyper Media Image Processing Reference (HIPR) at The University of Edinburgh:homepages.inf.ed.ac.uk/rbf/HIPR2/ • Cvonline, a compendium of Computer Vision at Edinburgh University:homepages.inf.ed.ac.uk/rbf/CVonline/ • British Machine Vision Association (BMVA):www.bmva.ac.uk