*Third party marks and brands are the property of their respective owners Getting Started with OpenCV Yue Gao CS 4758/6758 Robot Learning

Slides:



Advertisements
Similar presentations
DREAMWEAVER Welcome to our website!
Advertisements

Using a Template to Create a Resume and Sharing a Finished Document
Introduction to OpenCV Dr. Chung-Hao Chen Haole Guo Sep 2011.
Getting Started with OpenCV
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Gavin S Page OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio.net November 2005.
OpenCV Stacy O’Malley CS-590 Summer, What is OpenCV? Open source library of functions relating to computer vision. Cross-platform (Linux, OS X,
Based on slides created by Edward Angel
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
L.
Programming a GUI Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name.
Intel Do-It-Yourself Challenge OpenCV
OpenCV Open source C omputer V ision library By: Bahare Torkaman Fall 2010.
OPENCV TUTORIAL OpenCV Windows 7 Microsoft Visual C++ Express 2010.
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Bertrand Bellenot ROOT Users Workshop Mar ROOT GUI Builder Status & Plans ROOT & External GUI World MFC, FOX, Qt, PVSS… Snapshot of the Future.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
Detect Candle.  Open VC++ Directories configuration: Tools > Options > Projects and Solutions > VC++ Directories  Choose "Show directories for: Include.
CSCE Chapter 5 (Links, Images, & Multimedia) CSCE General Applications Programming Benito Mendoza 1 By Benito Mendoza Department.
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
Introduction to Matlab & Data Analysis
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Multimedia Programming 02: Play with Images Departments of Digital Contents Sang Il Park.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
FLTK Tutorial.
Developing the Game User Interface (UI) Lesson 5.
Multimedia Programming 03: Point Processing Departments of Digital Contents Sang Il Park.
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
L. Akshay Masare Piyush Awasthi IMAGE PROCESSING AND OPENCV.
Computer Graphics I, Fall 2010 Input and Interaction.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
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.
Laboratory Exercise # 9 – Inserting Graphics to Documents Office Productivity Tools 1 Laboratory Exercise # 9 Inserting Graphics to Documents Objectives:
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Getting to Know OpenCV 主講人:虞台文. Content Basic Structures Arrays, Matrices, and Images Matrix and Image Operators Drawing Things Drawing Text Data Persistence.
University of New Mexico
Click on this button to move to the previous slide of your notebook. Click on this button to move to the next slide of your notebook. Click on this button.
CHAPTER 12 Enhancing a Document. Learning Objectives Create and modify tables Change the page orientation Divide a document into sections Insert and modify.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Optical Flow walk through Aidean Sharghi Spring 14.
Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
OpenCV Tutorial Part I Using OpenCV with Microsoft Visual Studio .net November 2005 Gavin S Page
Introduction to Event-Driven Programming
CSC461 Lecture 8: Input Devices
A Quick Introduction to the C Interface By David Johnston
Windows Desktop Applications
Enhancing a Document Part 1
Getting Started with OpenCV
Chapter 2 Adding Web Pages, Links, and Images
Enhancing a Document Part 1
GTK + Programming.
Input and Interaction Ed Angel
University of New Mexico
Input and Interaction Ed Angel
Presentation transcript:

*Third party marks and brands are the property of their respective owners Getting Started with OpenCV Yue Gao CS 4758/6758 Robot Learning

*Third party marks and brands are the property of their respective owners Agenda OpenCV facts and overall structure OpenCV facts and overall structure Install OpenCV Install OpenCV OpenCV functions and examples OpenCV functions and examples Some useful OpenCV tips & tricks Some useful OpenCV tips & tricks

*Third party marks and brands are the property of their respective owners What is OpenCV? OpenCV stands for Open Source Computer Vision Library OpenCV stands for Open Source Computer Vision Library Being developed at Intel since 1999 Being developed at Intel since 1999 Written in C/C++; Contains over 500 functions. Written in C/C++; Contains over 500 functions. Available on Windows, Linux and MacOSX. Available on Windows, Linux and MacOSX. So far is extensively used in many companies and research centers So far is extensively used in many companies and research centers Home page: Home page:

*Third party marks and brands are the property of their respective owners OpenCV structure CXCORE basic structures and algoritms, XML support, drawing functions CV Image processing and vision algorithms HighGUI GUI, Image and Video I/O

*Third party marks and brands are the property of their respective owners First OpenCV Program 1. #include 2. #include 3. #include 4. int main( int argc, char** argv ) { 5. CvPoint center; 6. double scale=-3; 7. IplImage* image = argc==2 ? cvLoadImage(argv[1]) : 0; 8. if(!image) return -1; 9. center = cvPoint(image->width/2,image->height/2); 10. for(int i=0;i height;i++) 11. for(int j=0;j width;j++) { 12. double dx=(double)(j-center.x)/center.x; 13. double dy=(double)(i-center.y)/center.y; 14. double weight=exp((dx*dx+dy*dy)*scale); 15. uchar* ptr = &CV_IMAGE_ELEM(image,uchar,i,j*3); 16. ptr[0] = cvRound(ptr[0]*weight); 17. ptr[1] = cvRound(ptr[1]*weight); 18. ptr[2] = cvRound(ptr[2]*weight); } 19. cvSaveImage( “copy.png”, image ); 20. cvNamedWindow( "test", 1 ); 21. cvShowImage( "test", image ); 22. cvWaitKey(); 23. return 0; } Radial gradient

*Third party marks and brands are the property of their respective owners How to build and run the program? 1. Obtain the latest version of OpenCV: a)Get the official release (currently, OpenCV b5 for Windows = OpenCV for Linux) at b)Get the latest snapshot from CVS: 1. Install it: a)On Windows run installer, on Linux use “./configure + make + make install” (see INSTALL document) b)On Windows: open opencv.dsw, do “build all”, add opencv/bin to the system path; on Linux - see a) 2. Build the sample: Windows: Windows: o ocl /I test.cpp /link /libpath: cxcore.lib cv.lib highgui.lib o oCreate project for VS (see opencv/docs/faq.htm) or use opencv/samples/c/cvsample.dsp as starting point Linux: g++ -o test `pkg-config –cflags` test.cpp `pkg-config –libs opencv` 1. Run it: test lena.jpg or./test lena.jpg

*Third party marks and brands are the property of their respective owners The Program Quick Review short and clear program, no need to mess with MFC/GTK/QT/…, cross-platform short and clear program, no need to mess with MFC/GTK/QT/…, cross-platform cvLoadImage() and cvSaveImage() provide the easiest way to save/load images of various formats. cvLoadImage() and cvSaveImage() provide the easiest way to save/load images of various formats. cvPoint and other “constructor” functions make the code shorter and allow 1-line functions call. cvPoint and other “constructor” functions make the code shorter and allow 1-line functions call. CV_IMAGE_ELEM() – pretty fast way to access image pixels CV_IMAGE_ELEM() – pretty fast way to access image pixels cvRound() is very fast and convenient way to cast float/double to int cvRound() is very fast and convenient way to cast float/double to int cvNamedWindow() creates “smart” window for viewing an image cvNamedWindow() creates “smart” window for viewing an image cvShowImage() shows image in the window cvShowImage() shows image in the window cvWaitKey() delays the execution until key pressed or until the specified timeout is over cvWaitKey() delays the execution until key pressed or until the specified timeout is over 1. #include 2. #include 3. #include 4. int main( int argc, char** argv ) { 5. CvPoint center; 6. double scale=-3; cvLoadImage 7. IplImage* image = argc==2 ? cvLoadImage(argv[1]) : 0; 8. if(!image) return -1; cvPoint 9. center = cvPoint(image->width/2,image->height/2); 10. for(int i=0;i height;i++) 11. for(int j=0;j width;j++) { 12. double dx=(double)(j-center.x)/center.x; 13. double dy=(double)(i-center.y)/center.y; 14. double weight=exp((dx*dx+dy*dy)*scale); CV_IMAGE_ELEM 15. uchar* ptr = &CV_IMAGE_ELEM(image,uchar,i,j*3); cvRound 16. ptr[0] = cvRound(ptr[0]*weight); cvRound 17. ptr[1] = cvRound(ptr[1]*weight); cvRound 18. ptr[2] = cvRound(ptr[2]*weight); } cvSaveImage 19. cvSaveImage( “copy.png”, image ); cvNamedWindow 20. cvNamedWindow( "test", 1 ); cvShowImage 21. cvShowImage( "test", image ); cvWaitKey 22. cvWaitKey(); 23. return 0; }

*Third party marks and brands are the property of their respective owners What else HighGUI can do? “Smart” windows “Smart” windows Image I/O, rendering Image I/O, rendering Processing keyboard and other events, timeouts Processing keyboard and other events, timeouts Trackbars Trackbars Mouse callbacks Mouse callbacks Video I/O Video I/O

*Third party marks and brands are the property of their respective owners Windows cvNamedWindow(window_name, fixed_size_flag); cvNamedWindow(window_name, fixed_size_flag); creates window accessed by its name. Window handles repaint, resize events. Its position is remembered in registry: cvNamedWindow(“ViewA”,1);cvMoveWindow(“ViewA”,300,100);cvDestroyWindow(“ViewA”);… cvShowImage(window_name, image); cvShowImage(window_name, image); copies the image to window buffer, then repaints it when necessary. {8u|16s|32s|32f}{C1|3|4} are supported. only the whole window contents can be modified. Dynamic updates of parts of the window are done using operations on images, drawing functions etc. only the whole window contents can be modified. Dynamic updates of parts of the window are done using operations on images, drawing functions etc. On Windows native Win32 UI API is used On Windows native Win32 UI API is used Linux – GTK+ 2 MacOSX – X11 & GTK+ 2; Native Aqua support is planned.

*Third party marks and brands are the property of their respective owners Image I/O IplImage* cvLoadImage(image_path, colorness_flag); loads image from file, converts to color or grayscle, if need, and returns it (or returns NULL). image format is determined by the file contents. cvSaveImage(image_path, image); saves image to file, image format is determined from extension. BMP, JPEG (via libjpeg), PNG (via libpng), TIFF (via libtiff), PPM/PGM formats are supported. IplImage* img = cvLoadImage(“picture.jpeg”,-1); if( img ) cvSaveImage( “picture.png”, img );

*Third party marks and brands are the property of their respective owners Waiting for keys… cvWaitKey(delay=0); cvWaitKey(delay=0); waits for key press event for ms or infinitely, if delay=0. The only function in highgui that process message queue => should be called periodically. The only function in highgui that process message queue => should be called periodically. Thanks to the function many highgui programs have clear sequential structure, rather than event-oriented structure, which is typical for others toolkits Thanks to the function many highgui programs have clear sequential structure, rather than event-oriented structure, which is typical for others toolkits To make program continue execution if no user actions is taken, use cvWaitKey( ); and check the return value To make program continue execution if no user actions is taken, use cvWaitKey( ); and check the return value // opencv/samples/c/delaunay.c … for(…) { … int c = cvWaitKey(100); if( c >= 0 ) // key_pressed break; } delaunay.c, 240 lines

*Third party marks and brands are the property of their respective owners Trackbars cvCreateTrackbar(trackbar_name,window_name, position_ptr,max_value,callback=0); creates trackbar and attaches it to the window. Value range 0..max_value. When the position is changed, the global variable updated and callback is called, if specified. // opencv/samples/c/morphology.c int dilate_pos=0; // initial position value void Dilate(int pos) { … cvShowImage( “E&D”, erode_result ); } int main(…){ … cvCreateTrackbar(“Dilate”,”E&D”, &dilate_pos,10,Dilate); … cvWaitKey(0); // check for events & process them...} morphology.c, 126 lines

*Third party marks and brands are the property of their respective owners Mouse Events cvSetMouseCallback(window_name, callback, userdata=0); sets callback on mouse events (button clicks, cursor moves) for the specified window // opencv/samples/c/lkdemo.c void on_mouse(int event,int x,int y,int flags, void* param) { … } int main(…){ … cvSetMouseCallback(“LkDemo”,on_mou se,0); … cvWaitKey(0); // check for events & process them … } Scroll forward for example

*Third party marks and brands are the property of their respective owners Video I/O API CvCapture* cvCaptureFromCAM(camera_id=0); initializes capturing from the specified camera CvCapture* cvCaptureFromFile(videofile_path); initializes capturing from the video file. IplImage* cvQueryFrame(capture); retrieves the next video frame (do not alter the result!), or NULL if there is no more frames or an error occured. cvGetCaptureProperty(capture, property_id); cvSetCaptureProperty(capture, property_id, value); retrieves/sets some capturing properties (camera resolution, position within video file etc.) cvReleaseCapture(&capture); do not forget to release the resouces at the end! Used interfaces: –Windows: VFW, IEEE1394, MIL, DShow (in progress), Quicktime (in progress) –Linux: V4L2, IEEE1394, FFMPEG –MacOSX: FFMPEG, Quicktime (in progress)

*Third party marks and brands are the property of their respective owners Video I/O Example // opencv/samples/c/lkdemo.c int main(…){ … CvCapture* capture = ? cvCaptureFromCAM(camera_id) : cvCaptureFromFile(path); if( !capture ) return -1; for(;;) { IplImage* frame=cvQueryFrame(capture); if(!frame) break; // … copy and process image cvShowImage( “LkDemo”, result ); c=cvWaitKey(30); // run at ~20-30fps speed if(c >= 0) { // process key }} cvReleaseCapture(&capture);} lkdemo.c, 190 lines (needs camera to run)

*Third party marks and brands are the property of their respective owners Using OpenCV in User Apps Least squares (real example from OpenCV itself). Least squares (real example from OpenCV itself). // was (A – NxN matrix, b – Nx1 right-side vector, x – solution): some_old_least_sq_func_32f( /* float* */ A, /* int */ N, /* int */ N, /* float* */ b, /* float* */ x); // has been converted to: { CvMat _A=cvMat(N,N,CV_32F,A), _b=cvMat(N,1,CV_32F,b), _x=cvMat(N,1,CV_32F,x); cvSolve( &_A, &_b, &_x, CV_SVD ); } Advantages: –error handling –size and type checking –easier 32f 64f conversion

*Third party marks and brands are the property of their respective owners What can be drawn in image (besides circles)? cxcore provides numerous drawing functions: cxcore provides numerous drawing functions: –Lines, Circles, Ellipses, Elliptic Arcs –Filled polygons or polygonal contours –Text (using one of embedded fonts) –Everything can be drawn with different colors, different line width, antialiasing on/off –Arbitrary images types are supported (for depth!=8u antializing is off)

*Third party marks and brands are the property of their respective owners Save your data (to load it then) Need a config file? Need a config file? Want to save results of your program to pass it to another one, or look at it another day? Want to save results of your program to pass it to another one, or look at it another day? It all can be easily done with OpenCV persistence-related functions. // somewhere deep in your code… you get 5x5 // matrix that you’d want to save { CvMat A = cvMat( 5, 5, CV_32F, the_matrix_data ); cvSave( “my_matrix.xml”, &A ); } // to load it then in some other program use … CvMat* A1 = (CvMat*)cvLoad( “my_matrix.xml” ); 5 f my_matrix.xml

*Third party marks and brands are the property of their respective owners Some OpenCV Tips and Tricks Use short inline “constructor” functions: cvScalar, cvPoint, cvSize, cvMat etc. Use short inline “constructor” functions: cvScalar, cvPoint, cvSize, cvMat etc. Use cvStackAlloc for small buffers Use cvStackAlloc for small buffers Consider CV_IMPLEMENT_QSORT_EX() as possible alternative to qsort() & STL sort(). Consider CV_IMPLEMENT_QSORT_EX() as possible alternative to qsort() & STL sort(). To debug OpenCV program when runtime error dialog error pops up, press “Retry” (works with debug version of libraries) To debug OpenCV program when runtime error dialog error pops up, press “Retry” (works with debug version of libraries)…

*Third party marks and brands are the property of their respective owners Where to get more information? OpenCV Wiki-pages: OpenCV Wiki-pages: Supplied documentation: OpenCV/docs/index.htm, faq.htm Supplied documentation: OpenCV/docs/index.htm, faq.htm

*Third party marks and brands are the property of their respective owners Take away points -Google is your best friend - Learn OpenCV coding style

*Third party marks and brands are the property of their respective owners Thank you!