View
245
Download
0
Embed Size (px)
Citation preview
8/8/2019 Appendix+a OpenCV+Tutorial+v012
1/35
1
Appendix 2
Introduction to OpenCV
Speaker:
8/8/2019 Appendix+a OpenCV+Tutorial+v012
2/35
Contents
Introduction
Image Displaying
Image Copying
OpenCV Library
8/8/2019 Appendix+a OpenCV+Tutorial+v012
3/35
Introduction
Overview
OpenCV is an open source computer vision library
It implements thousands of high-level functions for
computer vision and image processing.
Each function name in OpenCV starts with cv :
cvCreateImage, cvSobel, cvAdd,
It includes many high-level datatypes, such as, Sets,Trees, Graphs, and Matrices. . .
8/8/2019 Appendix+a OpenCV+Tutorial+v012
4/35
Introduction
Why OpenCV?
Computer vision market is large and still
continues to grow.
There is no standard APIs like OpenGL forgraphics.
Research Code
Very expensive commercial toolkits
Specialized solution bundled withhardware
Standard library would simplify development of
new applications and solutions much easier.
4/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
5/35
Introduction
5/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
6/35
Introduction
Library Design
Initial Goal: build high-level and ready-to-use
components, such as gesture recognition.
But, the computer vision problem is alwayscomplex and hard to be solved directly.
The design is to split complex problem into
building block which is a function in OpenCV
6/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
7/35
Introduction
7/60
No free libraries could do this.
We have to do it ourselves.
8/8/2019 Appendix+a OpenCV+Tutorial+v012
8/35
Introduction
8/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
9/35
Introduction
OpenCV Installation
Download the OpenCV 2.1 from website
http://sourceforge.net/projects/opencvlibrary/
Execute the file OpenCV-2.1.0-win32-vs2008.exeto install the OpenCv 2.1
VC2008 Installation
Download the VC2008 from website
Install the VC2008 on your computer
8/8/2019 Appendix+a OpenCV+Tutorial+v012
10/35
Introduction
Project Creation
10/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
11/35
Introduction
Project Creation
11/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
12/35
Introduction
Environment Setup
Include the header files: C:\Program
Files\OpenCV2.1\include\opencv
8/8/2019 Appendix+a OpenCV+Tutorial+v012
13/35
Introduction
Environment Setup
Include the header files: C:\Program
Files\OpenCV2.1\include\opencv
13/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
14/35
Introduction
Environment Setup
Include the library files: C:\Program
Files\OpenCV2.1\lib
14/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
15/35
Introduction
Environment Setup
Input the library files to project: cv210.lib
highgui210.lib cxcore210.lib cvaux210.lib
15/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
16/35
Introduction
Environment Setup
Input the library files to project: cv210.lib
highgui210.lib cxcore210.lib cvaux210.lib
16/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
17/35
Image Displaying
Application
Load the well-known lena.jpg from the file
Display the loaded image on the window
Save the loaded image as result.jpg
8/8/2019 Appendix+a OpenCV+Tutorial+v012
18/35
Image Displaying
Lena Application: Sample Code
#include "cv.h"
#include "highgui.h "
int _tmain(int argc, _TCHAR* argv[]){
..
return 0;}/* End of main body */
8/8/2019 Appendix+a OpenCV+Tutorial+v012
19/35
Image Displaying
Lena Application: Sample Code
int _tmain(int argc, _TCHAR* argv[]){
IplImage* pImage1=NULL;
pImage1 = cvLoadImage("lena.jpg");
cvNamedWindow("Lena", 1);
cvShowImage("Lena", pImage1);
cvWaitKey(0);
if(pImage1 != NULL)
cvSaveImage(result.jpg, pImage1);
return 0;
}/* End of main body */
8/8/2019 Appendix+a OpenCV+Tutorial+v012
20/35
Image Copying
IplImage Data Structure
typedef struct_IplImage {
int nChannels; /* support 1,2,3 or 4 channels */
int depth; /* pixel depth in bits*/
int width; /* image width in pixels */
int height; /* image height in pixels */
char *imageData; /* pointer to aligned image data */
} IplImage;
8/8/2019 Appendix+a OpenCV+Tutorial+v012
21/35
Image Copying
IplImage Data Structure
nDepths: data type of the channel
imageData: one-dimensional array
IPL_DEPTH_8U,
IPL_DEPTH_8S,
IPL_DEPTH_16S,
IPL_DEPTH_32S,
IPL_DEPTH_32FIPL_DEPTH_64F
8/8/2019 Appendix+a OpenCV+Tutorial+v012
22/35
Image Copying
Image Creating: cvCreateImage();
IplImage* pImage2 = NULL;
pImage2 = cvCreateImage(cvSize(512, 512), IPL_DEPTH_8U, 1);
8/8/2019 Appendix+a OpenCV+Tutorial+v012
23/35
Image Copying
23/60
#include "cv.h"
#include "highgui.h "
int _tmain(int argc, _TCHAR* argv[]){
..
unsigned char* ptr1 = (unsigned char*) pImage1->imageData;
unsigned char* ptr2 = (unsigned char*) pImage2->imageData;
..
return 0;
}/* End of main body */
8/8/2019 Appendix+a OpenCV+Tutorial+v012
24/35
Image Copying
24/60
8/8/2019 Appendix+a OpenCV+Tutorial+v012
25/35
Image Copying
Image Data Indexing
25/60
offset: i+ j*width R offset: 3*(i+ j*width) + 0G offset: 3*(i+ j*width) + 1B offset: 3*(i+ j*width)+2
8/8/2019 Appendix+a OpenCV+Tutorial+v012
26/35
Image Copying
unsigned char* ptr1 = (unsigned char*) pImage1->imageData;
unsigned char* ptr2 = (unsigned char*) pImage2->imageData;
int width = pImage1->width;
int height= pImage1->height;
for(int h=0; h < height; h++)
for(int w=0; w < width; w++){
int sum = 0;
sum += ptr1[3 * (w + h * width) + 0];
sum += ptr1[3 * (w + h * width) + 1];sum += ptr1[3 * (w + h * width) + 2];
ptr2[w + h * width] = sum / 3;
}/* End of for-loop */
8/8/2019 Appendix+a OpenCV+Tutorial+v012
27/35
Image Copying
8/8/2019 Appendix+a OpenCV+Tutorial+v012
28/35
OpenCV Library
Description
There are three main OpenCV libraries
cxcore library
cv library
highgui library
The detailed documentation can be found through
the website.
\docs\index.htm
There are many available samples codes for
testing
8/8/2019 Appendix+a OpenCV+Tutorial+v012
29/35
8/8/2019 Appendix+a OpenCV+Tutorial+v012
30/35
OpenCV Library
cxcore Library
Basic Data/Support Linear Algebra Structures CvPoint :2D point with integer coordinates
CvPoint2D32f:2D point with floating-point coordinates CvMat :Multi-channel matrix
IplImage: IPL image header
Operations
IplImage* cvCreateImage( CvSize size, int depth, intchannels );
IplImage* cvCloneImage( const IplImage* image );
void cvSetImageROI( IplImage* image, CvRect rect );
8/8/2019 Appendix+a OpenCV+Tutorial+v012
31/35
OpenCV Library
cv Library
It includes many useful algorithms Image Processing
Structural Analysis
Motion Analysis Algorithm
Algorithms void cvCanny : for edge-detection
void cvGoodFeaturesToTrack: determine strong corners on
image void cvCvtColor :Converts image from one color space to
another
8/8/2019 Appendix+a OpenCV+Tutorial+v012
32/35
OpenCV Library
Edge-detection Segmentation
Histogram
8/8/2019 Appendix+a OpenCV+Tutorial+v012
33/35
OpenCV Library
Highgui Library It includes operations for I/O manipulation
Simple GUI
Loading and Saving Images
Video I/O
CvCapture* capture = 0;
capture = cvCaptureFromCAM() / cvCaptureFromAVI()
IplImage* frame = 0;
frame = cvQueryFrame(capture );
8/8/2019 Appendix+a OpenCV+Tutorial+v012
34/35
OpenCV Library
Useful Links
OpenCV for Linux : basic tutorial
http://easynews.dl.sourceforge.net/sourceforge/opencvlibra
ry/ippocv.pdf
Overview of all the capabilities of OpenCV
http://www.intel.com/research/mrl/research/opencv/overvie
w.htm
8/8/2019 Appendix+a OpenCV+Tutorial+v012
35/35
35Advanced Multimedia Lab.Advanced Multimedia Lab.