Read & Write image & other related Function

Download Report

Transcript Read & Write image & other related Function

Introduction of OpenCV

Alireza Shirani Researcher of Medical Image and Signal Processing M.S Electrical Engineering [email protected]

Spring 1392

Outline Of Talking

• • • •

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

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 language OpenCv written in C++ and its primary interface is in C++.There are full interfacing Python, Java ,MATLAB OpenCV can be used in Embedded Systems.

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      o o o o JPEG files - JPEG, JPG, JPE Portable Network Graphics - PNG Portable image format - PBM, PGM, PPM Sun rasters - SR, RAS TIFF files - TIFF, TIF Parameters : CV_LOAD_IMAGE_COLOR the loaded image is forced to be a 3-channel color image CV_LOAD_IMAGE_GRAYSCALE the loaded image is forced to be grayscale CV_LOAD_IMAGE_UNCHANGED the loaded image will be loaded as is.

Read & Write image & other related Function

IplImage

is structure that contain all details about Image that was loaded

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

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

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

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 window o o x – New x coordinate of the top-left corner 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.

Read & Write image & other related Function

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

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.

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

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

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

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

Read & Write image & other related Function

   Save Image

cvSaveImage int cvSaveImage(const char* filename, const CvArr* image)

The function cvSaveImagesaves • filename – Name of the file.

image – Image to be saved the image to the specified file

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

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

Thank You

published by www.Kingsoftstore.com

@Kingsoft_Office kingsoftstore