OpenCV- An overview Intel® OPEN SOURCE COMPUTER VISION LIBRARY

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
OpenCV Introduction Hang Xiao Oct 26, History  1999 Jan : lanched by Intel, real time machine vision library for UI, optimized code for intel 
The fundamental matrix F
The University of Adelaide, School of Computer Science
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
CS252: Systems Programming Ninghui Li Program Interview Questions.
Structures in C.
Elementary Data Structures: Part 2: Strings, 2D Arrays, Graphs
Image Transforms 主講人:虞台文. Content Overview Convolution Edge Detection – Gradients – Sobel operator – Canny edge detector – Laplacian Hough Transforms.
Pointer applications. Arrays and pointers Name of an array is a pointer constant to the first element whose value cannot be changed Address and name refer.
Histograms and Matching 主講人:虞台文. Content Overview Basic Histogram Structure Accessing Histograms Basic Manipulations with Histograms Color Spaces Histogram.
Image Indexing and Retrieval using Moment Invariants Imran Ahmad School of Computer Science University of Windsor – Canada.
Introduction to OpenCV Dr. Chung-Hao Chen Haole Guo Sep 2011.
OpenCV Training course
Gavin S Page OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio.net November 2005.
Gavin S Page OpenCV Tutorial Part IV A Brief Guide to Memory Management (and other Miscellaneous Functions) 02 December 2005.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Feature matching and tracking Class 5 Read Section 4.1 of course notes Read Shi and Tomasi’s paper on.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
C++ for Engineers and Scientists Third Edition
Important Problem Types and Fundamental Data Structures
Linear Algebra and Image Processing
L.
Knowledge Systems Lab JN 8/24/2015 A Method for Temporal Hand Gesture Recognition Joshua R. New Knowledge Systems Laboratory Jacksonville State University.
OpenCV Open source C omputer V ision library By: Bahare Torkaman Fall 2010.
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Data Structures Using C++ 2E
Knowledge Systems Lab JN 9/10/2002 Computer Vision: Gesture Recognition from Images Joshua R. New Knowledge Systems Laboratory Jacksonville State University.
Software Resources Multimodal Interaction Dr. Mike Spann
Detect Candle.  Open VC++ Directories configuration: Tools > Options > Projects and Solutions > VC++ Directories  Choose "Show directories for: Include.
Multimedia Programming 02: Play with Images Departments of Digital Contents Sang Il Park.
Facial Recognition Alex Newcomb, Tom Stefanyk. Group Members Alex Newcomb In charge of web server, image compression and facial recognition database The.
L. Akshay Masare Piyush Awasthi IMAGE PROCESSING AND OPENCV.
Image Processing 主講人:虞台文. Content Smoothing Image Morphology Some Applications of Image Morphology Flood Fill Resize Image Pyramids Threshold.
1 Object Oriented Programming Lecture IX Some notes on Java Performance with aspects on execution time and memory consumption.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Multimedia Programming 13: Review and term project Departments of Digital Contents Sang Il Park.
Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering yahoo. com Spring.
Pointers OVERVIEW.
ECE 103 Engineering Programming Chapter 47 Dynamic Memory Alocation Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
12/5/2015 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Getting to Know OpenCV 主講人:虞台文. Content Basic Structures Arrays, Matrices, and Images Matrix and Image Operators Drawing Things Drawing Text Data Persistence.
Main Index Contents 11 Main Index Contents Complete Binary Tree Example Complete Binary Tree Example Maximum and Minimum Heaps Example Maximum and Minimum.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Stereoscopic Imaging for Slow-Moving Autonomous Vehicle By: Alex Norton Advisor: Dr. Huggins February 28, 2012 Senior Project Progress Report Bradley University.
Distortion Correction ECE 6276 Project Review Team 5: Basit Memon Foti Kacani Jason Haedt Jin Joo Lee Peter Karasev.
Course 3 Binary Image Binary Images have only two gray levels: “1” and “0”, i.e., black / white. —— save memory —— fast processing —— many features of.
Computer Vision Computer Vision based Hole Filling Chad Hantak COMP December 9, 2003.
1 Review and Summary We have covered a LOT of material, spending more time and more detail on 2D image segmentation and analysis, but hopefully giving.
MASKS © 2004 Invitation to 3D vision Lecture 3 Image Primitives andCorrespondence.
Optical Flow walk through Aidean Sharghi Spring 14.
Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park.
Multimedia Programming 12: Mouse, Draw and Morphing2 Departments of Digital Contents Sang Il Park.
Object Oriented Programming Lecture 2: BallWorld.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio .net November 2005 Gavin S Page
ECE Application Programming
Data Structure and Algorithms
A Quick Introduction to the C Interface By David Johnston
Outline Image formats and basic operations Image representation
COP 3330 Object-oriented Programming in C++
Presentation transcript:

OpenCV- An overview Intel® OPEN SOURCE COMPUTER VISION LIBRARY

Goals Develop a universal toolbox for research and development in the field of Computer Vision

Features Image data manipulation Image and video I/O allocation, release, copying, setting, conversion Image and video I/O file and camera based input, image/video file output Matrix and vector manipulation, and linear algebra routines products, solvers, eigenvalues, SVD Various dynamic data structures lists, queues, sets, trees, graphs Basic image processing filtering, edge detection, corner detection, sampling and interpolation, color conversion, morphological operations, histograms, image pyramids

Features (cont.) Structural analysis Camera calibration connected components, contour processing, distance transform, various moments, template matching, Hough transform, polygonal approximation, line fitting, ellipse fitting, Delaunay triangulation Camera calibration finding and tracking calibration patterns, calibration, fundamental matrix estimation, homography estimation, stereo correspondence Motion analysis optical flow, motion segmentation, tracking Object recognition eigen-methods, HMM Basic GUI display image/video, keyboard and mouse handling, scroll-bars Image labeling line, conic, polygon, text drawing

Modules OpenCV Functionality Cxcore cv Cvaux Highgui more than 350 algorithms Cxcore Data structures and linear algebra support. cv Main OpenCV functions. Cvaux Auxiliary (experimental) OpenCV functions. Highgui GUI functions.

How do I download it? http://www.intel.com/technology/computing/opencv/index.htm Version: beta 5

Forums & Resources http://opencvlibrary.sourceforge.net/ http://groups.yahoo.com/group/OpenCV/ http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html Books Gary R. Bradski, Vadim Pisarevsky, and Jean-Yves Bouguet, Open Source Computer Vision Library, Springer, 1st ed. (June, 2006). Toturial http://nchc.dl.sourceforge.net/sourceforge/opencvlibrary/ippocv.pdf

System requirement Platforms: Win9x/WinNT/Win2000 C++ Compiler (Visual C++ 6.0,Intel C++ Compiler 5.x,Borland C++ 5.5, Mingw GNU C/C++ 2.95.3 are included ) for core libraries Matlab Visual C++ to build the most of demos

Settings- An example in VC Library: project->setting->link cv.lib cvaux.lib highgui.lib cxcore.lib Directories Include C:\PROGRAM FILES\OPENCV\CV\INCLUDE C:\PROGRAM FILES\OPENCV\CVAUX\INCLUDE C:\PROGRAM FILES\OPENCV\OTHERLIBS\HIGHGUI C:\PROGRAM FILES\OPENCV\CXCORE\INCLUDE Library C:\PROGRAM FILES\OPENCV\LIB FilePathName C:\PROGRAM FILES\OPENCV\bin Include in programs #include "cv.h“, "cvaux.h“, "highgui.h“, "cxcore.h"

Outline of this course Basic structures & functions in OpenCV HighGUI & I/O Image processing Structural analysis (contour, geometry) AdaBoost & object detection Object recognition Motion analysis & object tracking Camera calibration & 3D reconstruction

Today’s outline Basic structures Operations on arrays Dynamic structures Drawing functions Miscellaneous functions Error handling

Basic structures (1) CvPoint typedef struct CvPoint { int x; /* x-coordinate, usually zero-based */ int y; /* y-coordinate, usually zero-based */ } CvPoint; Usage CvPoint P1; P1.x = 10; P1.y = 2; CvPoint2D32f, CvPoint2D64f, CvPoint3D32f, CvPoint3D64f

Basic structures (2) CvSize CvRect CvScalar CvSize2D32f typedef struct CvSize { int width; /* width of the rectangle */ int height; /* height of the rectangle */ } CvSize; CvSize2D32f CvRect offset and size of a rectangle CvScalar a container for 1-, 2-, 3- or 4-tuples of numbers

Basic structures (3) CvTermCriteria CvArr Arbitrary array Termination criteria for iterative algorithms typedef struct CvTermCriteria { int type; /* a combination of CV_TERMCRIT_ITER and CV_TERMCRIT_EPS */ int max_iter; /* maximum number of iterations */ double epsilon; /* accuracy to achieve */ } CvTermCriteria; CvArr Arbitrary array CvMat, IplImage, CvSeq

Basic structures (4) CvMat CvMatND, CvSparseMat typedef struct CvMat { int type; /* CvMat signature (CV_MAT_MAGIC_VAL), element type and flags */ int step; /* full row length in bytes */ int* refcount; /* underlying data reference counter */ union { uchar* ptr; short* s; int* i; float* fl; double* db; } data; /* data pointers */ #ifdef __cplusplus int rows; int height; }; int cols; int width; #else int rows; /* number of rows */ int cols; /* number of columns */ #endif } CvMat; CvMatND, CvSparseMat

Basic structures (5) Usage of CvMat CvMat* cvCreateMat( int rows, int cols, int type ); void cvReleaseMat( CvMat** mat ); void cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value ); CvScalar cvGet2D( const CvArr* arr, int idx0, int idx1 ); CvMat* M = cvCreateMat(2, 2, CV_32F); cvSet2D(M, 0, 0, cvScalar(1)); cvSet2D(M, 0, 1, cvScalar(2)); cvSet2D(M, 1, 0, cvScalar(3)); cvSet2D(M, 1, 1, cvScalar(4)); i = cvGet2D(M, 0, 0).val[0]; j = cvGet2D(M, 0, 1).val[0];  i = 1, j = 2. cvReleaseMat(&M);

Basic structures (6) Usage of CvMat CvMat* cvInitMatHeader( CvMat* mat, int rows, int cols, int type, void* data=NULL, int step=CV_AUTOSTEP ); void cvMatMulAdd( const CvArr* A, const CvArr* B, const CvArr* C, CvArr* D ); [D=A*B+C] double a[] = { 1, 2, 3, 4 5, 6, 7, 8, 9, 10, 11, 12 }; double b[] = { 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12 }; double c[9]; CvMat Ma, Mb, Mc ; cvInitMatHeader( &Ma, 3, 4, CV_64FC1, a ); cvInitMatHeader( &Mb, 4, 3, CV_64FC1, b ); cvInitMatHeader( &Mc, 3, 3, CV_64FC1, c ); cvMatMulAdd( &Ma, &Mb, 0, &Mc );

Basic structures (7) IplImage: IPL image header typedef struct _IplImage { int nSize; /* sizeof(IplImage) */ int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */ int depth; /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */ int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels. cvCreateImage can only create interleaved images */ int origin; /* 0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style) */ int width; /* image width in pixels */ int height; /* image height in pixels */ struct _IplROI *roi;/* image ROI. when it is not NULL, this specifies image region to process */ int imageSize; /* image data size in bytes */ char *imageData; /* pointer to aligned image data */ int widthStep; /* size of aligned image row in bytes */ char *imageDataOrigin; /* pointer to a very origin of image data (not necessarily aligned) - it is needed for correct image deallocation */ } IplImage;

Basic structures (8) Usage of IplImage IplImage* cvCreateImage( CvSize size, int depth, int channels ); void cvReleaseImage( IplImage** image ); IplImage *src_img; src_img = cvCreateImage(imgSize, IPL_DEPTH_8U, 1); cvReleaseImage( src_img );

Operations on arrays (1) CloneImage: Makes a full copy of image IplImage* cvCloneImage( const IplImage* image ); SetImageROI void cvSetImageROI( IplImage* image, CvRect rect ); GetImageROI CvRect cvGetImageROI( const IplImage* image ); ResetImageROI: Releases image ROI void cvResetImageROI( IplImage* image ); SetImageCOI: Sets channel of interest to given value void cvSetImageCOI( IplImage* image, int coi ); coi = 0 means that all channels are selected. GetImageCOI: Returns index of channel of interest int cvGetImageCOI( const IplImage* image );

Operations on arrays (2) CreateMat/CreateMatHeader: Creates new matrix (header) CvMat* cvCreateMat( int rows, int cols, int type ); ReleaseMat void cvReleaseMat( CvMat** mat ); CloneMat: Creates matrix copy CvMat* cvCloneMat( const CvMat* mat ); CreateData: Allocates array data Void cvCreateData( CvArr* arr ); GetRow: Returns array row cvGetRow( const CvArr* arr, CvMat* submat, int row ); GetCol: Returns array column cvGetCol( const CvArr* arr, CvMat* submat, int col ); GetDiag: Returns one of array diagonals cvGetDiag( const CvArr* arr, CvMat* submat, int diag=0 ); GetSize: Returns size of matrix or image ROI CvSize cvGetSize( const CvArr* arr ); ...

Operations on arrays (3) Copy: Copies one array to another cvCopy( const CvArr* src, CvArr* dst, const CvArr* mask=NULL ); Set: Sets every element of array to given value cvSet( CvArr* arr, CvScalar value, const CvArr* mask=NULL ); SetZero: Clears the array cvSetZero( CvArr* arr ); Reshape: Changes shape of matrix/image without copying data CvMat* cvReshape( const CvArr* arr, CvMat* header, int new_cn, int new_rows=0 ); Image example (from color to gray-level) IplImage* color_img = cvCreateImage( cvSize(320,240), IPL_DEPTH_8U, 3 ); CvMat gray_mat_hdr; IplImage gray_img_hdr, *gray_img; cvReshape( color_img, &gray_mat_hdr, 1 ); gray_img = cvGetImage( &gray_mat_hdr, &gray_img_hdr ); Matrix example (from a 3*3 matrix to a 1*9 vector) CvMat* mat = cvCreateMat( 3, 3, CV_32F ); CvMat row_header, *row; row = cvReshape( mat, &row_header, 0, 1 ); Flip, Split, Merge

Operations on arrays (4) ConvertScale, Add, AddWeighted, Sub, Mul, Div, And, Or, Xor, Cmp, InRange, Max, Min, Sum, Avg, Norm, DotProduct, CrossProduct, Transform, MulTransposed, Trace, Det, Invert, Mahalonobis … Solve: Solves linear system or least-squares problem int cvSolve( const CvArr* A, const CvArr* B, CvArr* X, int method=CV_LU, CV_SVD ); AX = B EigenVV: Computes eigenvalues and eigenvectors of symmetric matrix void cvEigenVV( CvArr* mat, CvArr* evects, CvArr* evals, double eps=0 );

Dynamic structures (1) Memory storages CvMemStorage typedef struct CvMemStorage { struct CvMemBlock* bottom;/* first allocated block */ struct CvMemBlock* top; /* the current memory block – top of the stack */ struct CvMemStorage* parent; /* borrows new blocks from */ int block_size; /* block size */ int free_space; /*free space in the top block (in bytes)*/ } CvMemStorage; block_size free_space bottom top

Dynamic structures (2) CvMemBlock: Memory storage block typedef struct CvMemBlock { struct CvMemBlock* prev; struct CvMemBlock* next; } CvMemBlock; CvMemStoragePos: Memory storage position typedef struct CvMemStoragePos { CvMemBlock* top; int free_space; } CvMemStoragePos;

Dynamic structures (3) CreateMemStorage: Creates memory storage CvMemStorage* cvCreateMemStorage( int block_size ); MemStorageAlloc: Allocates memory buffer in the storage void* cvMemStorageAlloc( CvMemStorage* storage, size_t size ); ReleaseMemStorage: Releases memory storage CvMemStorage* cvReleaseMemStorage(CvMemStorage** storage); ClearMemStorage: Clears memory storage void cvClearMemStorage( CvMemStorage* storage );

Dynamic structures (4) CreateChildMemStorage: Creates child memory storage CvMemStorage* cvCreateChildMemStorage( CvMemStorage* parent ); It is similar to memory storage except for the differences in the memory allocation/deallocation mechanism. Require a new block: get it from the parent. The first unoccupied parent block available is taken & excluded from the parent block list. If no blocks are available, the parent either allocates a block or borrows one from its own parent. Release or clear: return all blocks to the parent. Dynamic data processing without using child storage Dynamic data processing using a child storage

Dynamic structures (5) CvSeq: Growable sequence of elements #define CV_SEQUENCE_FIELDS() int flags; /* micsellaneous flags */ int header_size; /* size of sequence header */ struct CvSeq* h_prev; /* previous sequence */ struct CvSeq* h_next; /* next sequence */ struct CvSeq* v_prev; /* 2nd previous sequence */ struct CvSeq* v_next; /* 2nd next sequence */ int total; /* total number of elements */ int elem_size;/* size of sequence element in bytes */ char* block_max;/* maximal bound of the last block */ char* ptr; /* current write pointer */ int delta_elems; /* how many elements allocated when the sequence grows (sequence granularity) */ CvMemStorage* storage; /* where the seq is stored */ CvSeqBlock* free_blocks; /* free blocks list */ CvSeqBlock* first; /* pointer to the first sequence block */ typedef struct CvSeq { CV_SEQUENCE_FIELDS() } CvSeq; Operations of CvSeq

Dynamic structures (6) CvSet CvGraph CV_TREE_NODE_FIELDS Collection of nodes CvGraph Oriented or unoriented weigted graph CV_TREE_NODE_FIELDS For a tree node type declaration

Drawing functions CV_RGB, cvLine, cvRectangle, cvCircle, cvEllipse, cvFillPoly, cvFillConvexPoly, cvPolyLine, cvDrawContours. cvInitFont, cvPutText, cvGetTextSize.

Miscellaneous functions cvKMeans2() Splits set of vectors by given number of clusters void cvKMeans2( const CvArr* samples, int cluster_count, CvArr* labels, CvTermCriteria termcrit );

Example of KMeans2 C-code

Error handling (1) There are no return error codes It raises an error using CV_ERROR macro that calls cvError int cvError( int status, const char* func_name, const char* err_msg, const char* file_name, int line );

Error handling (2) #define __BEGIN__ { #define __END__ goto exit; exit: ; } /* proceeds to "resource release" stage */ #define EXIT goto exit /* Declares locally the function name for CV_ERROR() use */ #define CV_FUNCNAME( Name ) static char cvFuncName[] = Name /* Raises an error within the current context */ #define CV_ERROR( Code, Msg ) { cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); EXIT; } /* Checks status after calling CXCORE function */ #define CV_CHECK() { if( cvGetErrStatus() < 0 ) CV_ERROR( CV_StsBackTrace, "Inner function failed." ); } /* Provies shorthand for CXCORE function call and CV_CHECK() */ #define CV_CALL( Statement ) { Statement; CV_CHECK(); } /* Checks some condition in both debug and release configurations */ #define CV_ASSERT( Condition ) { if( !(Condition) ) CV_ERROR( CV_StsInternal, "Assertion: " #Condition " failed" ); }

Error handling (3) Three modes of error handling Leaf: The program is terminated after error handler is called. This is the default value. Parent: The program is not terminated, but the error handler is called. Silent: Similar to Parent mode, but no error handler is called. SetErrMode: #define CV_ErrModeLeaf 0 #define CV_ErrModeParent 1 #define CV_ErrModeSilent 2 int cvSetErrMode( int mode ); Check error code int cvGetErrStatus( void );