introduction of opencv alireza shirani researcher of medical image and signal processing m. s...

20
Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M.S Electrical Engineering [email protected] Spring 1392

Upload: roy-reynolds

Post on 03-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Introduction of OpenCV

Alireza ShiraniResearcher of Medical Image and Signal ProcessingM.S Electrical Engineering

[email protected] 1392

Page 2: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Outline Of Talking

• Introduction of OpenCV• How to Install OpenCV• Read & Write image & other related Function• Read & Write video & other related Function

Page 3: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Introduction of OpenCV

OpenCv (open computer vision ) library is library of programming function mainly aimed at real time computer vision

developed by Intel and now supported by Willow Garage.

It’s free for use under the open source BSD License OS Support:

Windows ,Android ,Blackberry ,Linux Distribution such as puppy, Ubuntu,…,Maemo ,Free BSD,…

Programming languageOpenCv written in C++ and its primary interface is in

C++.There are full interfacing Python, Java ,MATLAB

OpenCV can be used in Embedded Systems.

Page 4: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Load Image: cvLoadImage The function cvLoadImage loads an image from the

specified file and returns the pointer to the loaded image IplImage* cvLoadImage(const char* filename,

Parameters)• Currently the following file formats are supported:

Windows bitmaps - BMP, DIB JPEG files - JPEG, JPG, JPE Portable Network Graphics - PNG Portable image format - PBM, PGM, PPM Sun rasters - SR, RAS TIFF files - TIFF, TIFo Parameters :o CV_LOAD_IMAGE_COLOR the loaded image is forced to be a 3-channel

color imageo CV_LOAD_IMAGE_GRAYSCALE the loaded image is forced to be grayscaleo CV_LOAD_IMAGE_UNCHANGED the loaded image will be loaded as is.

Page 5: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related FunctionIplImage is structure that contain all details about Image that was loaded

Page 6: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function Open window cvNamedWindow cvNamedWindow(const char* name, int flags)¶ The function cvNamedWindow creates a window which can be

used as a placeholder for images name – Name of the window in the window caption that may be used as a window identifier.flags – Flags of the window. Currently the only supported flag is CV_WINDOW_AUTOSIZE

Delay in milliseconds cvWaitKey Int cvWaitKey(int delay=0)The function cvWaitKey waits for key event infinitely ( delay<=0) or for

delay milliseconds. Returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed

Page 7: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Release Space of RAM cvReleaseImage void cvReleaseImage(IplImage* image) Deallocates the image header and the image data

• image – Double pointer to the image header

Page 8: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Create image cvCreateImage IplImage* cvCreateImage(CvSize size, int depth, int channels)

Creates an image header and allocates the image data• size – Image width and height• depth – Bit depth of image elements.• channels – Number of channels per pixel

Point of image CvPoint

2D point with integer coordinates

Page 9: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

MoveWindoe cvMoveWindow(*name,x,y) cvMoveWindow(const char* name, int x, int y)• The function cvMoveWindow() changes the position of

the windowo x – New x coordinate of the top-left cornero y – New y coordinate of the top-left corner

Convert Image cvConvertImage cvConvertImage(const CvArr* src, CvArr* dst, int flags=0)• Converts one image to another with an optional vertical flip• src – Source image dst – Destination image• The operation flags:

• CV_CVTIMG_FLIP - Flips the image vertically• CV_CVTIMG_SWAP_RB - Swaps the red and blue channels. In OpenCV

color images have BGR channel order, however on some systems the order needs to be reversed before displaying the image.

Page 10: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function Font setting in opencv cvInitFont cvInitFont(CvFont* font, int fontFace, double hscale, double vscale, double

shear=0, int thickness=1, int lineType=8) The function initializes the font structure that can be passed to text rendering

functions font – Pointer to the font structure initialized by the function• fontFace :

• CV_FONT_HERSHEY_SIMPLEX - normal size sans-serif font• CV_FONT_HERSHEY_PLAIN - small size sans-serif font• CV_FONT_HERSHEY_DUPLEX - normal size sans-serif font (more complex

than Hscale : Horizontal scale Vscale: Vertical scale param thickness : Thickness of the text strokes param shear: Approximate tangent of the character slope relative to the vertical

line. A zero value means a non-italic font. 1.0f means about a 45 degree slope, etc. lineType : The function initializes the font structure that can be passed to text

rendering functions.

Page 11: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Write string on OpenCV cvPutText void cvPutText(CvArr* img, const char* text, CvPoint org,

const CvFont* font, CvScalar color) The function renders the text in the image with the specified

font and color• img – Input image• text – String to print• org – Coordinates of the bottom-left corner of the first letter• font – Pointer to the font structure• color – Text color CvScaler: is structure that contain R,G,B values of Pixels

Example CV_RGB(255,255,255) create white color

Page 12: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Convert Image cvCreateImage IplImage* cvCreateImage(CvSize size, int depth, int channels) Creates an image header and allocates the image data

• size – Image width and height• depth – Bit depth of image elements.• channels – Number of channels per pixel.

Page 13: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function Implements the Canny Algorithm cvCanny void cvCanny(const CvArr* image, CvArr * edges, double threshold1,

double threshold2, int aperture_size=3) The function finds the edges on the input image and marks them in

the output image edges using the Canny algorithm.• image – Single-channel input image• edges – Single-channel image to store the edges found by the function• threshold1 – The first threshold• threshold2 – The second threshold• aperture_size – Aperture parameter for the Sobel operator

Page 14: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Draws a line cvLine cvLine(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int

thickness=1, int lineType=8, int shift=0) The function draws the line segment between pt1 and pt2 points in

the image• img – The image• pt1 – First point of the line segment• pt2 – Second point of the line segment• color – Line color• thickness – Line thickness• lineType – Type of the line:

• 8 - (or omitted) 8-connected line.• 4 - 4-connected line.• CV_AA - antialiased line.

• shift – Number of fractional bits in the point coordinates

Page 15: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Draw circle cvCircle cvCircle(CvArr* img, CvPoint center, int radius, CvScalar color,

int thickness=1, int lineType=8, int shift=0) The function draws a simple or filled circle with a given center and

radius.• img – Image where the circle is drawn• center – Center of the circle• radius – Radius of the circle• color – Circle color• thickness – Thickness of the circle outline if positive, otherwise this

indicates that a filled circle is to be drawn• lineType – Type of the circle boundary• shift – Number of fractional bits in the center coordinates and radius value

Page 16: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function Smooth cvSmooth cvSmooth(const CvArr* src, CvArr* dst, int

smoothtype=CV_GAUSSIAN, int param1=3, int param2=0, double param3=0, double param4=0)

Function smooths an image using one of several methods.• src – The source image• dst – The destination image• smoothtype – Type of the smoothing:

• CV_BLUR_NO_SCALE linear convolution with box kernel (all 1’s). If you want to smooth different pixels with different-size box kernels, you can use the integral image that is computed using Integral

• CV_BLUR linear convolution with box kernel (all 1’s) with subsequent scaling by • CV_GAUSSIAN linear convolution with a Gaussian kernel• CV_MEDIAN median filter with a square aperture• CV_BILATERAL bilateral filter with a square aperture

Page 17: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write image & other related Function

Save ImagecvSaveImage int cvSaveImage(const char* filename, const CvArr* image) The function cvSaveImagesaves the image to the specified file

• filename – Name of the file.• image – Image to be saved

Page 18: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write video & other related Function

capturing a video from a camera cvCaptureFromCAM The functioncvCaptureFromCAMallocates and initializes the

CvCapture structure for reading a video stream from the camera CvCapture* cvCaptureFromCAM(int index)

index – Index of the camera to be used

Page 19: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Read & Write video & other related Function

Extract frame from camera cvQueryFrame Grabs and returns a frame from a camera or file IplImage* cvQueryFrame(CvCapture* capture)

capture – video capturing structure

Page 20: Introduction of OpenCV Alireza Shirani Researcher of Medical Image and Signal Processing M. S Electrical Engineering shiranialireza @ yahoo. com Spring

Thank You

Kingsoft Officepublished by www.Kingsoftstore.com

@Kingsoft_Office

kingsoftstore

Kingsoft Office