SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
A Basic Introduction
to OpenCV for Image
Processing
Qing Chen (David)
E-mail: qchen@discover.uottawa.ca
DiscoverLab
School of Information Technology & Engineering
University of Ottawa
January 15, 2007
Outline
 1. Introduction
 2. Image data structure in OpenCV
 3. Basic operations for images
 4. Working with videos
 5. References and resources



                                     2
1. Introduction
 General description
   Open source computer vision library in C/C++.
   Optimized and intended for real-time applications.
   OS/hardware/window-manager independent.
   Generic image/video loading, saving, and acquisition.
   Both low and high level API.
   Provides interface to Intel's Integrated Performance
   Primitives (IPP) with processor specific optimization
   (Intel processors).


                                                       3
1. Introduction
 Features:
    Image data manipulation (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.
    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).
    Structural analysis (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).




                                                                               4
1. Introduction
 OpenCV modules:
   cv - Main OpenCV functions.
   cvaux - Auxiliary (experimental) OpenCV
   functions.
   cxcore - Data structures and linear algebra
   support.
   highgui - GUI functions.



                                                 5
2. Image data structure in OpenCV
 Load and display an                           image in OpenCV:
 #include "cv.h" //main OpenCV functions
 #include "highgui.h" //OpenCV GUI functions¯include <stdio.h>

 int main()
 {
           /* declare a new IplImage pointer, the basic
              image data structure in OpenCV */
          IplImage* newImg;
          /* load an image named "apple.bmp", 1 means
             this is a color image */
          newImg = cvLoadImage("apple.bmp",1);
          //create a new window
          cvNamedWindow("Window", 1);
          //display the image in the window
          cvShowImage("Window", newImg);
          //wait for key to close the window
          cvWaitKey(0);
          cvDestroyWindow( "Window" ); //destroy the window
          cvReleaseImage( &newImg ); //release the memory for the image
          return 0;
 }

                                                                          6
2. Image data structure in OpenCV
 IplImage is the basic image data structure in OpenCV




                                                        7
3. Basic operations for images
 Threshold
 #include "cv.h"
 #include "highgui.h"
 #include "math.h"

 int main()
 {
     IplImage* src;
     IplImage* colorThresh;
     IplImage* gray;
     IplImage* grayThresh;
     int threshold = 120, maxValue = 255;
     int thresholdType = CV_THRESH_BINARY;

     src = cvLoadImage("apple.bmp", 1);
     colorThresh = cvCloneImage( src );
     gray = cvCreateImage( cvSize(src->width, src->height), IPL_DEPTH_8U, 1 );
     cvCvtColor( src, gray, CV_BGR2GRAY );
     grayThresh = cvCloneImage( gray );

     cvNamedWindow( "src", 1 );    cvShowImage( "src", src );
     cvNamedWindow( "gray", 1 );    cvShowImage( "gray", gray );

     cvThreshold(src, colorThresh, threshold, maxValue, thresholdType);
     cvThreshold(gray, grayThresh, threshold, maxValue, thresholdType);
     cvNamedWindow( "colorThresh", 1 );      cvShowImage( "colorThresh", colorThresh );

     cvNamedWindow( "grayThresh", 1 );    cvShowImage( "grayThresh", grayThresh );

     cvWaitKey(0);

     cvDestroyWindow( "src" );
     cvDestroyWindow( "colorThresh" );
     cvDestroyWindow( "gray" );
     cvDestroyWindow( "grayThresh" );
     cvReleaseImage( &src );
     cvReleaseImage( &colorThresh );
     cvReleaseImage( &gray );
     cvReleaseImage( &grayThresh );

     return 0;                                                                            8
 }
3. Basic operations for images
 Canny edge detection
 #include "cv.h"
 #include "highgui.h"

 int main()
 {
    IplImage* newImg; // original image
    IplImage* grayImg; // gray image for the conversion of the original image
    IplImage* cannyImg; // gray image for the canny edge detection

     //load original image
     newImg = cvLoadImage("apple.bmp",1);
     //create a single channel 1 byte image (i.e. gray-level image)
     grayImg = cvCreateImage( cvSize(newImg->width, newImg->height), IPL_DEPTH_8U, 1 );
     //convert original color image (3 channel rgb color image) to gray-level image
     cvCvtColor( newImg, grayImg, CV_BGR2GRAY );
     cannyImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 1);

     // canny edge detection
     cvCanny(grayImg, cannyImg, 50, 150, 3);
     cvNamedWindow("src", 1);
     cvNamedWindow("canny",1);
     cvShowImage( "src", newImg );
     cvShowImage( "canny", cannyImg );

     cvWaitKey(0);

     cvDestroyWindow( "src" );
     cvDestroyWindow( "canny" );
     cvReleaseImage( &newImg );
     cvReleaseImage( &grayImg );
     cvReleaseImage( &cannyImg );

     return 0;
 }
                                                                                          9
3. Basic operations for images
     Contour detection
 #include "cv.h"
 #include "cxcore.h"
 #include "highgui.h"

 int main()
 {
   IplImage* newImg = NULL;
   IplImage* grayImg = NULL;
   IplImage* contourImg = NULL;

     //parameters for the contour detection
     CvMemStorage * storage = cvCreateMemStorage(0);
     CvSeq * contour = 0;
     int mode = CV_RETR_EXTERNAL;
     mode = CV_RETR_CCOMP; //detect both outside and inside contour

     cvNamedWindow("src", 1);
     cvNamedWindow("contour",1);
     //load original image
     newImg = cvLoadImage("applebw.bmp",1);
     //create a single channel 1 byte image (i.e. gray-level image)
     grayImg = cvCreateImage( cvSize(newImg->width, newImg->height), IPL_DEPTH_8U, 1 );
     //convert original color image (3 channel rgb color image) to gray-level image
     cvCvtColor( newImg, grayImg, CV_BGR2GRAY );
     cvShowImage( "src", newImg );
     //make a copy of the original image to draw the detected contour
     contourImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 3);
     contourImg=cvCloneImage( newImg );

     //find the contour
     cvFindContours(grayImg, storage, &contour, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
     //draw the contour
     cvDrawContours(contourImg, contour, CV_RGB(0, 255, 0), CV_RGB(255, 0, 0), 2, 2, 8);
     cvShowImage( "contour", contourImg );
     cvWaitKey(0);
     cvDestroyWindow( "src" ); cvDestroyWindow( "contour" );
     cvReleaseImage( &newImg );   cvReleaseImage( &grayImg );   cvReleaseImage( &contourImg );
     cvReleaseMemStorage(&storage);
     return 0;
 }                                                                                                    10
3. Basic operations for images
 Dilate/Erode
 #include "cv.h"
 #include "cxcore.h"
 #include "highgui.h"

 int main()
 {

     IplImage* newImg = NULL;
     IplImage* dilateImg = NULL;
     IplImage* erodeImg = NULL;

     cvNamedWindow("src", 1);
     cvNamedWindow("dilate",1);
     cvNamedWindow("erode",1);

     //load original image
     newImg = cvLoadImage("apple.bmp",1);
     cvShowImage( "src", newImg );

     //make a copy of the original image
     dilateImg=cvCloneImage( newImg );
     erodeImg=cvCloneImage( newImg );

     //dilate image
     cvDilate(newImg,dilateImg,NULL,4);
     //erode image
     cvErode(newImg,erodeImg,NULL,4);
     cvShowImage( "dilate", dilateImg );
     cvShowImage( "erode", erodeImg );

     cvWaitKey(0);

     cvDestroyWindow( "src" ); cvDestroyWindow( "dilate" ); cvDestroyWindow( "erode" );
     cvReleaseImage( &newImg );  cvReleaseImage( &dilateImg ); cvReleaseImage( &erodeImg );
     return 0;
 }


                                                                                              11
3. Basic operations for images
 Flood and Fill
 #include "cv.h"
 #include "cxcore.h"
 #include "highgui.h"

 int main()
 {
   IplImage* newImg = NULL;
   IplImage* ffImg = NULL;

     //flood and fill parameters
     int lo_diff, up_diff; //the low and up flood randge which can be adjusted
     CvConnectedComp comp;
     CvPoint floodSeed; //the original pixel where the flood begins
     CvScalar floodColor;
     lo_diff=8;
     up_diff=8;
     floodColor = CV_RGB( 255, 0, 0 ); //set the flood color to red

     cvNamedWindow("src", 1);
     cvNamedWindow("flood&fill",1);

     //load original image
     newImg = cvLoadImage("apple.bmp",1);
     cvShowImage( "src", newImg );
     //make a copy of the original image
     ffImg=cvCloneImage( newImg );
     floodSeed=cvPoint(60,60); //flooding start from pixel(60, 60)

     //Flood and Fill from pixel(60, 60) with color red and the flood range of (-8, +8)
     cvFloodFill( ffImg, floodSeed, floodColor, CV_RGB( lo_diff, lo_diff, lo_diff ),
                                CV_RGB( up_diff, up_diff, up_diff ), &comp, 8, NULL);
     cvShowImage( "flood&fill", ffImg );

     cvWaitKey(0);
     cvDestroyWindow( "src" ); cvDestroyWindow( "flood&fill" );
     cvReleaseImage( &newImg );  cvReleaseImage( &ffImg );
     return 0;
 }
                                                                                          12
3. Basic operations for images
 Rotate and Scale
 #include "cv.h"
 #include "highgui.h"
 #include "math.h"

 int main()
 {
     IplImage* src;
     IplImage* dst;
     int delta;
     int angle;

         src = cvLoadImage("apple.bmp", 1);
         dst = cvCloneImage( src );
         delta = 1; angle = 0;
         cvNamedWindow( "src", 1 );
         cvShowImage( "src", src );
         for(;;)
         {
             float m[6];
             double factor = (cos(angle*CV_PI/180.) + 1.1)*3;
             CvMat M = cvMat( 2, 3, CV_32F, m );
             int w = src->width;
             int h = src->height;

            m[0]   =   (float)(factor*cos(-angle*2*CV_PI/180.));
            m[1]   =   (float)(factor*sin(-angle*2*CV_PI/180.));
            m[2]   =   w*0.5f;
            m[3]   =   -m[1];
            m[4]   =   m[0];
            m[5]   =   h*0.5f;

            cvGetQuadrangleSubPix( src, dst, &M, 1, cvScalarAll(0));

            cvNamedWindow( "dst", 1 ); cvShowImage( "dst", dst );

            if( cvWaitKey(5) == 27 )
                break;

             angle = (angle + delta) % 360;
         }
     return 0;                                                         13
 }
4. Working with videos
 Video capture from a file:
   CvCapture* cvCaptureFromFile( const char* filename );

 Video capture from a camera:
   CvCapture* cvCaptureFromCAM( int index );

   example:

   // capture from video device #0
   CvCapture* capture = cvCaptureFromCAM(0);




                                                           14
4. Working with videos
 Grab a frame:
    cvGrabFrame( CvCapture* capture );
 Get the image grabbed with cvGrabFrame:
    cvRetrieveFrame( CvCapture* capture );

    example:
    IplImage* img = 0;
    if(!cvGrabFrame(capture)){ // capture a frame
    printf("Could not grab a framen7");
    exit(0); }
    //retrieve the captured frame
    img=cvRetrieveFrame(capture);
 Release the capture source:
    cvReleaseCapture(&capture);
 For a better understanding of video processing with OpenCV, refer to
 the face detection example under the dir: C:Program
 FilesOpenCVsamplescfacedetect.c
                                                                   15
5. References and resources
 http://www.intel.com/technology/computing/opencv/index.htm
 OpenCV official webpage.
 http://opencvlibrary.sourceforge.net/
 OpenCV documentation and FAQs.
 http://tech.groups.yahoo.com/group/OpenCV/
 OpenCV forum at Yahoo Groups.
 http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/cvis
 ion.htm
 This is a good walkthrough for OpenCV and the Microsoft
 DirectShow technology by Prof. Robert Laganière of university of
 Ottawa. The configuration of OpenCV for MS .Net is also included.
 http://ai.stanford.edu/~dstavens/cs223b/stavens_opencv_optical_flo
 w.pdf
 This is another OpenCV introduction focused on Optical Flow, the
 installation of OpenCV is also included.

                                                                   16
About myself
 I am a Ph.D. candidate at the DiscoverLab, School of Information
 Technology and Engineering, University of Ottawa. My general
 research interests include image processing and computer vision.
 My current research topic is focused on real-time vision-based hand
 gesture recognition for Human Computer Interface (HCI).
 For more information about me, please refer to my webpage:
 http://www.discover.uottawa.ca/~qchen




                                                                  17

Weitere ähnliche Inhalte

Was ist angesagt?

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - videoroxlu
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphicsroxlu
 
C++ amp on linux
C++ amp on linuxC++ amp on linux
C++ amp on linuxMiller Lee
 
Cvpr2010 open source vision software, intro and training part v open cv and r...
Cvpr2010 open source vision software, intro and training part v open cv and r...Cvpr2010 open source vision software, intro and training part v open cv and r...
Cvpr2010 open source vision software, intro and training part v open cv and r...zukun
 
Histogram dan Segmentasi 2
Histogram dan Segmentasi 2Histogram dan Segmentasi 2
Histogram dan Segmentasi 2Lusiana Diyan
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guiceJordi Gerona
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Mr. Vengineer
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Mr. Vengineer
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPMiller Lee
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Mr. Vengineer
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Mr. Vengineer
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxyginecorehard_by
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]Nilhcem
 
Functional Reactive Programming on Android
Functional Reactive Programming on AndroidFunctional Reactive Programming on Android
Functional Reactive Programming on AndroidSam Lee
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereSergey Platonov
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략 C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략 명신 김
 

Was ist angesagt? (20)

openFrameworks 007 - video
openFrameworks 007 - videoopenFrameworks 007 - video
openFrameworks 007 - video
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
C++ amp on linux
C++ amp on linuxC++ amp on linux
C++ amp on linux
 
Cvpr2010 open source vision software, intro and training part v open cv and r...
Cvpr2010 open source vision software, intro and training part v open cv and r...Cvpr2010 open source vision software, intro and training part v open cv and r...
Cvpr2010 open source vision software, intro and training part v open cv and r...
 
Histogram dan Segmentasi 2
Histogram dan Segmentasi 2Histogram dan Segmentasi 2
Histogram dan Segmentasi 2
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guice
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
 
Functional Reactive Programming on Android
Functional Reactive Programming on AndroidFunctional Reactive Programming on Android
Functional Reactive Programming on Android
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Алексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhereАлексей Кутумов, Coroutines everywhere
Алексей Кутумов, Coroutines everywhere
 
Yacf
YacfYacf
Yacf
 
Modern c++
Modern c++Modern c++
Modern c++
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략 C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략
 

Andere mochten auch

Myro and OpenCV
Myro and OpenCVMyro and OpenCV
Myro and OpenCV2xrobert
 
OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012Wingston
 
Identity based proxy-oriented data uploading and remote data integrity checki...
Identity based proxy-oriented data uploading and remote data integrity checki...Identity based proxy-oriented data uploading and remote data integrity checki...
Identity based proxy-oriented data uploading and remote data integrity checki...Shakas Technologies
 
RoboCV Module 4: Image Processing Techniques using OpenCV
RoboCV Module 4: Image Processing Techniques using OpenCVRoboCV Module 4: Image Processing Techniques using OpenCV
RoboCV Module 4: Image Processing Techniques using OpenCVroboVITics club
 
RoboCV Module 2: Introduction to OpenCV and MATLAB
RoboCV Module 2: Introduction to OpenCV and MATLABRoboCV Module 2: Introduction to OpenCV and MATLAB
RoboCV Module 2: Introduction to OpenCV and MATLABroboVITics club
 
Mobile camera based text detection and translation
Mobile camera based text detection and translationMobile camera based text detection and translation
Mobile camera based text detection and translationVivek Bharadwaj
 
Motion capture
Motion captureMotion capture
Motion capturenooCnoo
 
Using openCV on Raspberry Pi
Using openCV on Raspberry PiUsing openCV on Raspberry Pi
Using openCV on Raspberry PiCAVEDU Education
 
Text & Image: Residents of a dysFUNctional HOME
Text & Image: Residents of a dysFUNctional HOMEText & Image: Residents of a dysFUNctional HOME
Text & Image: Residents of a dysFUNctional HOMES. Song
 
Text and Image based Digital Humanities: providing access to textual heritage...
Text and Image based Digital Humanities: providing access to textual heritage...Text and Image based Digital Humanities: providing access to textual heritage...
Text and Image based Digital Humanities: providing access to textual heritage...Edward Vanhoutte
 
구글Fin
구글Fin구글Fin
구글Finzerk87
 
Arm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armArm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armPrashant Ahire
 
How to make Successful Open APIs for Startups (2012)
How to make Successful Open APIs for Startups (2012)How to make Successful Open APIs for Startups (2012)
How to make Successful Open APIs for Startups (2012)Channy Yun
 
Visual data mining with HeatMiner
Visual data mining with HeatMinerVisual data mining with HeatMiner
Visual data mining with HeatMinerCloudNSci
 
Image to text Converter
Image to text ConverterImage to text Converter
Image to text ConverterDhiraj Raj
 
구글
구글구글
구글zerk87
 

Andere mochten auch (20)

Myro and OpenCV
Myro and OpenCVMyro and OpenCV
Myro and OpenCV
 
OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012
 
Identity based proxy-oriented data uploading and remote data integrity checki...
Identity based proxy-oriented data uploading and remote data integrity checki...Identity based proxy-oriented data uploading and remote data integrity checki...
Identity based proxy-oriented data uploading and remote data integrity checki...
 
RoboCV Module 4: Image Processing Techniques using OpenCV
RoboCV Module 4: Image Processing Techniques using OpenCVRoboCV Module 4: Image Processing Techniques using OpenCV
RoboCV Module 4: Image Processing Techniques using OpenCV
 
RoboCV Module 2: Introduction to OpenCV and MATLAB
RoboCV Module 2: Introduction to OpenCV and MATLABRoboCV Module 2: Introduction to OpenCV and MATLAB
RoboCV Module 2: Introduction to OpenCV and MATLAB
 
PPT FOR IDBSDDS SCHEMES
PPT FOR IDBSDDS SCHEMESPPT FOR IDBSDDS SCHEMES
PPT FOR IDBSDDS SCHEMES
 
Motion
MotionMotion
Motion
 
Mobile camera based text detection and translation
Mobile camera based text detection and translationMobile camera based text detection and translation
Mobile camera based text detection and translation
 
Motion capture
Motion captureMotion capture
Motion capture
 
DM8168 Dual SuperHD image capture using DaVinci
DM8168 Dual SuperHD image capture using DaVinciDM8168 Dual SuperHD image capture using DaVinci
DM8168 Dual SuperHD image capture using DaVinci
 
Using openCV on Raspberry Pi
Using openCV on Raspberry PiUsing openCV on Raspberry Pi
Using openCV on Raspberry Pi
 
Text & Image: Residents of a dysFUNctional HOME
Text & Image: Residents of a dysFUNctional HOMEText & Image: Residents of a dysFUNctional HOME
Text & Image: Residents of a dysFUNctional HOME
 
MMT image & graphics
MMT image & graphicsMMT image & graphics
MMT image & graphics
 
Text and Image based Digital Humanities: providing access to textual heritage...
Text and Image based Digital Humanities: providing access to textual heritage...Text and Image based Digital Humanities: providing access to textual heritage...
Text and Image based Digital Humanities: providing access to textual heritage...
 
구글Fin
구글Fin구글Fin
구글Fin
 
Arm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_armArm cortex-m3 by-joe_bungo_arm
Arm cortex-m3 by-joe_bungo_arm
 
How to make Successful Open APIs for Startups (2012)
How to make Successful Open APIs for Startups (2012)How to make Successful Open APIs for Startups (2012)
How to make Successful Open APIs for Startups (2012)
 
Visual data mining with HeatMiner
Visual data mining with HeatMinerVisual data mining with HeatMiner
Visual data mining with HeatMiner
 
Image to text Converter
Image to text ConverterImage to text Converter
Image to text Converter
 
구글
구글구글
구글
 

Ähnlich wie A basic introduction to open cv for image processing

Histogram dan Segmentasi
Histogram dan SegmentasiHistogram dan Segmentasi
Histogram dan SegmentasiLusiana Diyan
 
Primer vistazo al computer vision | 4Sessions Feb17
Primer vistazo al computer vision | 4Sessions Feb17Primer vistazo al computer vision | 4Sessions Feb17
Primer vistazo al computer vision | 4Sessions Feb17[T]echdencias
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .netStephen Lorello
 
Automated Face Detection System
Automated Face Detection SystemAutomated Face Detection System
Automated Face Detection SystemAbhiroop Ghatak
 
License Plate Recognition System
License Plate Recognition System License Plate Recognition System
License Plate Recognition System Hira Rizvi
 
What is image in Swift?/はるふ
What is image in Swift?/はるふWhat is image in Swift?/はるふ
What is image in Swift?/はるふha1f Yamaguchi
 
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...Saeed Ullah
 
Object detection
Object detectionObject detection
Object detectionSomesh Vyas
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Checking GIMP's Source Code with PVS-Studio
Checking GIMP's Source Code with PVS-StudioChecking GIMP's Source Code with PVS-Studio
Checking GIMP's Source Code with PVS-StudioAndrey Karpov
 
Computer vision Nebraska (Nebraska Code)
Computer vision Nebraska (Nebraska Code)Computer vision Nebraska (Nebraska Code)
Computer vision Nebraska (Nebraska Code)Andrew Rangel
 

Ähnlich wie A basic introduction to open cv for image processing (20)

Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Facedetect
FacedetectFacedetect
Facedetect
 
Histogram dan Segmentasi
Histogram dan SegmentasiHistogram dan Segmentasi
Histogram dan Segmentasi
 
OpenCV Introduction
OpenCV IntroductionOpenCV Introduction
OpenCV Introduction
 
Primer vistazo al computer vision | 4Sessions Feb17
Primer vistazo al computer vision | 4Sessions Feb17Primer vistazo al computer vision | 4Sessions Feb17
Primer vistazo al computer vision | 4Sessions Feb17
 
Of class1
Of class1Of class1
Of class1
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Automated Face Detection System
Automated Face Detection SystemAutomated Face Detection System
Automated Face Detection System
 
OpenCVの基礎
OpenCVの基礎OpenCVの基礎
OpenCVの基礎
 
License Plate Recognition System
License Plate Recognition System License Plate Recognition System
License Plate Recognition System
 
What is image in Swift?/はるふ
What is image in Swift?/はるふWhat is image in Swift?/はるふ
What is image in Swift?/はるふ
 
N1802038292
N1802038292N1802038292
N1802038292
 
Python OpenCV Real Time projects
Python OpenCV Real Time projectsPython OpenCV Real Time projects
Python OpenCV Real Time projects
 
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
downsampling and upsampling of an image using pyramids (pyr up and pyrdown me...
 
Object detection
Object detectionObject detection
Object detection
 
Dip iit workshop
Dip iit workshopDip iit workshop
Dip iit workshop
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Checking GIMP's Source Code with PVS-Studio
Checking GIMP's Source Code with PVS-StudioChecking GIMP's Source Code with PVS-Studio
Checking GIMP's Source Code with PVS-Studio
 
Computer vision Nebraska (Nebraska Code)
Computer vision Nebraska (Nebraska Code)Computer vision Nebraska (Nebraska Code)
Computer vision Nebraska (Nebraska Code)
 

Kürzlich hochgeladen

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 

Kürzlich hochgeladen (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 

A basic introduction to open cv for image processing

  • 1. A Basic Introduction to OpenCV for Image Processing Qing Chen (David) E-mail: qchen@discover.uottawa.ca DiscoverLab School of Information Technology & Engineering University of Ottawa January 15, 2007
  • 2. Outline 1. Introduction 2. Image data structure in OpenCV 3. Basic operations for images 4. Working with videos 5. References and resources 2
  • 3. 1. Introduction General description Open source computer vision library in C/C++. Optimized and intended for real-time applications. OS/hardware/window-manager independent. Generic image/video loading, saving, and acquisition. Both low and high level API. Provides interface to Intel's Integrated Performance Primitives (IPP) with processor specific optimization (Intel processors). 3
  • 4. 1. Introduction Features: Image data manipulation (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. 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). Structural analysis (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). 4
  • 5. 1. Introduction OpenCV modules: cv - Main OpenCV functions. cvaux - Auxiliary (experimental) OpenCV functions. cxcore - Data structures and linear algebra support. highgui - GUI functions. 5
  • 6. 2. Image data structure in OpenCV Load and display an image in OpenCV: #include "cv.h" //main OpenCV functions #include "highgui.h" //OpenCV GUI functions¯include <stdio.h> int main() { /* declare a new IplImage pointer, the basic image data structure in OpenCV */ IplImage* newImg; /* load an image named "apple.bmp", 1 means this is a color image */ newImg = cvLoadImage("apple.bmp",1); //create a new window cvNamedWindow("Window", 1); //display the image in the window cvShowImage("Window", newImg); //wait for key to close the window cvWaitKey(0); cvDestroyWindow( "Window" ); //destroy the window cvReleaseImage( &newImg ); //release the memory for the image return 0; } 6
  • 7. 2. Image data structure in OpenCV IplImage is the basic image data structure in OpenCV 7
  • 8. 3. Basic operations for images Threshold #include "cv.h" #include "highgui.h" #include "math.h" int main() { IplImage* src; IplImage* colorThresh; IplImage* gray; IplImage* grayThresh; int threshold = 120, maxValue = 255; int thresholdType = CV_THRESH_BINARY; src = cvLoadImage("apple.bmp", 1); colorThresh = cvCloneImage( src ); gray = cvCreateImage( cvSize(src->width, src->height), IPL_DEPTH_8U, 1 ); cvCvtColor( src, gray, CV_BGR2GRAY ); grayThresh = cvCloneImage( gray ); cvNamedWindow( "src", 1 ); cvShowImage( "src", src ); cvNamedWindow( "gray", 1 ); cvShowImage( "gray", gray ); cvThreshold(src, colorThresh, threshold, maxValue, thresholdType); cvThreshold(gray, grayThresh, threshold, maxValue, thresholdType); cvNamedWindow( "colorThresh", 1 ); cvShowImage( "colorThresh", colorThresh ); cvNamedWindow( "grayThresh", 1 ); cvShowImage( "grayThresh", grayThresh ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "colorThresh" ); cvDestroyWindow( "gray" ); cvDestroyWindow( "grayThresh" ); cvReleaseImage( &src ); cvReleaseImage( &colorThresh ); cvReleaseImage( &gray ); cvReleaseImage( &grayThresh ); return 0; 8 }
  • 9. 3. Basic operations for images Canny edge detection #include "cv.h" #include "highgui.h" int main() { IplImage* newImg; // original image IplImage* grayImg; // gray image for the conversion of the original image IplImage* cannyImg; // gray image for the canny edge detection //load original image newImg = cvLoadImage("apple.bmp",1); //create a single channel 1 byte image (i.e. gray-level image) grayImg = cvCreateImage( cvSize(newImg->width, newImg->height), IPL_DEPTH_8U, 1 ); //convert original color image (3 channel rgb color image) to gray-level image cvCvtColor( newImg, grayImg, CV_BGR2GRAY ); cannyImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 1); // canny edge detection cvCanny(grayImg, cannyImg, 50, 150, 3); cvNamedWindow("src", 1); cvNamedWindow("canny",1); cvShowImage( "src", newImg ); cvShowImage( "canny", cannyImg ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "canny" ); cvReleaseImage( &newImg ); cvReleaseImage( &grayImg ); cvReleaseImage( &cannyImg ); return 0; } 9
  • 10. 3. Basic operations for images Contour detection #include "cv.h" #include "cxcore.h" #include "highgui.h" int main() { IplImage* newImg = NULL; IplImage* grayImg = NULL; IplImage* contourImg = NULL; //parameters for the contour detection CvMemStorage * storage = cvCreateMemStorage(0); CvSeq * contour = 0; int mode = CV_RETR_EXTERNAL; mode = CV_RETR_CCOMP; //detect both outside and inside contour cvNamedWindow("src", 1); cvNamedWindow("contour",1); //load original image newImg = cvLoadImage("applebw.bmp",1); //create a single channel 1 byte image (i.e. gray-level image) grayImg = cvCreateImage( cvSize(newImg->width, newImg->height), IPL_DEPTH_8U, 1 ); //convert original color image (3 channel rgb color image) to gray-level image cvCvtColor( newImg, grayImg, CV_BGR2GRAY ); cvShowImage( "src", newImg ); //make a copy of the original image to draw the detected contour contourImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 3); contourImg=cvCloneImage( newImg ); //find the contour cvFindContours(grayImg, storage, &contour, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0)); //draw the contour cvDrawContours(contourImg, contour, CV_RGB(0, 255, 0), CV_RGB(255, 0, 0), 2, 2, 8); cvShowImage( "contour", contourImg ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "contour" ); cvReleaseImage( &newImg ); cvReleaseImage( &grayImg ); cvReleaseImage( &contourImg ); cvReleaseMemStorage(&storage); return 0; } 10
  • 11. 3. Basic operations for images Dilate/Erode #include "cv.h" #include "cxcore.h" #include "highgui.h" int main() { IplImage* newImg = NULL; IplImage* dilateImg = NULL; IplImage* erodeImg = NULL; cvNamedWindow("src", 1); cvNamedWindow("dilate",1); cvNamedWindow("erode",1); //load original image newImg = cvLoadImage("apple.bmp",1); cvShowImage( "src", newImg ); //make a copy of the original image dilateImg=cvCloneImage( newImg ); erodeImg=cvCloneImage( newImg ); //dilate image cvDilate(newImg,dilateImg,NULL,4); //erode image cvErode(newImg,erodeImg,NULL,4); cvShowImage( "dilate", dilateImg ); cvShowImage( "erode", erodeImg ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "dilate" ); cvDestroyWindow( "erode" ); cvReleaseImage( &newImg ); cvReleaseImage( &dilateImg ); cvReleaseImage( &erodeImg ); return 0; } 11
  • 12. 3. Basic operations for images Flood and Fill #include "cv.h" #include "cxcore.h" #include "highgui.h" int main() { IplImage* newImg = NULL; IplImage* ffImg = NULL; //flood and fill parameters int lo_diff, up_diff; //the low and up flood randge which can be adjusted CvConnectedComp comp; CvPoint floodSeed; //the original pixel where the flood begins CvScalar floodColor; lo_diff=8; up_diff=8; floodColor = CV_RGB( 255, 0, 0 ); //set the flood color to red cvNamedWindow("src", 1); cvNamedWindow("flood&fill",1); //load original image newImg = cvLoadImage("apple.bmp",1); cvShowImage( "src", newImg ); //make a copy of the original image ffImg=cvCloneImage( newImg ); floodSeed=cvPoint(60,60); //flooding start from pixel(60, 60) //Flood and Fill from pixel(60, 60) with color red and the flood range of (-8, +8) cvFloodFill( ffImg, floodSeed, floodColor, CV_RGB( lo_diff, lo_diff, lo_diff ), CV_RGB( up_diff, up_diff, up_diff ), &comp, 8, NULL); cvShowImage( "flood&fill", ffImg ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "flood&fill" ); cvReleaseImage( &newImg ); cvReleaseImage( &ffImg ); return 0; } 12
  • 13. 3. Basic operations for images Rotate and Scale #include "cv.h" #include "highgui.h" #include "math.h" int main() { IplImage* src; IplImage* dst; int delta; int angle; src = cvLoadImage("apple.bmp", 1); dst = cvCloneImage( src ); delta = 1; angle = 0; cvNamedWindow( "src", 1 ); cvShowImage( "src", src ); for(;;) { float m[6]; double factor = (cos(angle*CV_PI/180.) + 1.1)*3; CvMat M = cvMat( 2, 3, CV_32F, m ); int w = src->width; int h = src->height; m[0] = (float)(factor*cos(-angle*2*CV_PI/180.)); m[1] = (float)(factor*sin(-angle*2*CV_PI/180.)); m[2] = w*0.5f; m[3] = -m[1]; m[4] = m[0]; m[5] = h*0.5f; cvGetQuadrangleSubPix( src, dst, &M, 1, cvScalarAll(0)); cvNamedWindow( "dst", 1 ); cvShowImage( "dst", dst ); if( cvWaitKey(5) == 27 ) break; angle = (angle + delta) % 360; } return 0; 13 }
  • 14. 4. Working with videos Video capture from a file: CvCapture* cvCaptureFromFile( const char* filename ); Video capture from a camera: CvCapture* cvCaptureFromCAM( int index ); example: // capture from video device #0 CvCapture* capture = cvCaptureFromCAM(0); 14
  • 15. 4. Working with videos Grab a frame: cvGrabFrame( CvCapture* capture ); Get the image grabbed with cvGrabFrame: cvRetrieveFrame( CvCapture* capture ); example: IplImage* img = 0; if(!cvGrabFrame(capture)){ // capture a frame printf("Could not grab a framen7"); exit(0); } //retrieve the captured frame img=cvRetrieveFrame(capture); Release the capture source: cvReleaseCapture(&capture); For a better understanding of video processing with OpenCV, refer to the face detection example under the dir: C:Program FilesOpenCVsamplescfacedetect.c 15
  • 16. 5. References and resources http://www.intel.com/technology/computing/opencv/index.htm OpenCV official webpage. http://opencvlibrary.sourceforge.net/ OpenCV documentation and FAQs. http://tech.groups.yahoo.com/group/OpenCV/ OpenCV forum at Yahoo Groups. http://www.site.uottawa.ca/~laganier/tutorial/opencv+directshow/cvis ion.htm This is a good walkthrough for OpenCV and the Microsoft DirectShow technology by Prof. Robert Laganière of university of Ottawa. The configuration of OpenCV for MS .Net is also included. http://ai.stanford.edu/~dstavens/cs223b/stavens_opencv_optical_flo w.pdf This is another OpenCV introduction focused on Optical Flow, the installation of OpenCV is also included. 16
  • 17. About myself I am a Ph.D. candidate at the DiscoverLab, School of Information Technology and Engineering, University of Ottawa. My general research interests include image processing and computer vision. My current research topic is focused on real-time vision-based hand gesture recognition for Human Computer Interface (HCI). For more information about me, please refer to my webpage: http://www.discover.uottawa.ca/~qchen 17