20
Copyright © Robotix Team, IIT Copyright © Robotix Team, IIT Kharagpur Kharagpur February 1st – 4th ,2007

A Tutorial On Ip 2

Embed Size (px)

Citation preview

Page 1: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

February 1st – 4th ,2007

Page 2: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image Acquisition and Real Image Acquisition and Real Time Processing TechniquesTime Processing Techniques

Page 3: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Why Real-time Image Processing?Why Real-time Image Processing?

Image processing is an important tool in Image processing is an important tool in many applications.many applications.Problem is that one needs to acquire Problem is that one needs to acquire images and pre-process them before images and pre-process them before doing actual IP.doing actual IP.Sometimes it may be required that offline Sometimes it may be required that offline image processing is not possible i.e. one image processing is not possible i.e. one needs to proceed with real-time IP or even needs to proceed with real-time IP or even more, processing of the video itself.more, processing of the video itself.

Page 4: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Real-Time Image ProcessingReal-Time Image Processing

Such Real-Time Image processing can be Such Real-Time Image processing can be done on standalone hardware like DSP or done on standalone hardware like DSP or ASIC.ASIC.Another approach being using a personal Another approach being using a personal computer.computer.

Page 5: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image AcquisitionImage Acquisition

Image acquisition from the video capture Image acquisition from the video capture devices connected to the computer, is an devices connected to the computer, is an important task in Real Time Image important task in Real Time Image Processing applications.Processing applications.Few approaches being, developing Few approaches being, developing custom standalone applications or using custom standalone applications or using software like MATLAB (image and video software like MATLAB (image and video processing toolbox) etc.processing toolbox) etc.

Page 6: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Problems with MATLABProblems with MATLAB

Even though MATLAB is simple and Even though MATLAB is simple and robust ,it doesn’t have features for real-robust ,it doesn’t have features for real-time image processing (Even the latest time image processing (Even the latest image and video processing tool box image and video processing tool box doesn’t provide this feature), which doesn’t provide this feature), which renders it useless in this problemrenders it useless in this problem

Page 7: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Another approach being developing Another approach being developing custom applications in languages like C, custom applications in languages like C, C++, VC++, VB, Java etc.C++, VC++, VB, Java etc.This languages don’t have capability to This languages don’t have capability to handle Images and they require different handle Images and they require different libraries to achieve these tasks. libraries to achieve these tasks.

Page 8: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Different Libraries for image Different Libraries for image acquisition on Windows Platformacquisition on Windows PlatformDirectShow (part of the DirectX API)DirectShow (part of the DirectX API)OpenCVOpenCVVision SDKVision SDKJava Media FrameworkJava Media Framework

Page 9: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Comparison of the Various Comparison of the Various approachesapproaches

OpenCV and Vision SDK comprise of the OpenCV and Vision SDK comprise of the High Level Functions. Where as the High Level Functions. Where as the DirectX is a set of Low Level API, which DirectX is a set of Low Level API, which directly interact with the hardware.directly interact with the hardware.OpenCV and Vision SDK encapsulate the OpenCV and Vision SDK encapsulate the DirectX API.DirectX API.

Page 10: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Tools RequiredTools Required

Windows (2000 or later)Windows (2000 or later)Visual Studio (6.0 or later)Visual Studio (6.0 or later)DirectX SDK (9.0 or later)DirectX SDK (9.0 or later)OpenCV (4.0 or later)OpenCV (4.0 or later)

Page 11: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

OpenCVOpenCV

OpenCV is an opensource project OpenCV is an opensource project supported by Intel.supported by Intel.It is a collection of C structures, functions It is a collection of C structures, functions and C++ classes that contain and C++ classes that contain implementation of algorithms of image implementation of algorithms of image processing and computer visionprocessing and computer vision

Page 12: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Some basic C StructuresSome basic C Structures

IplImage :IplImage :Every Image in OpenCV is an instantiation Every Image in OpenCV is an instantiation of a structure called of a structure called IplImageIplImage..This structure consists of Image data in a This structure consists of Image data in a 1-D array format. Others fields of this 1-D array format. Others fields of this structure consist of data like width, height, structure consist of data like width, height, no of channels etc.no of channels etc.

Page 13: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Some basic Structures (cont..)Some basic Structures (cont..)

Some other commonly used structures Some other commonly used structures are are

1)CvPoint { int x,int y}1)CvPoint { int x,int y} 2)CvSize {int width, int height }2)CvSize {int width, int height } 3)CvRect {int x,y,width,height }3)CvRect {int x,y,width,height } 4)CvScalar { double val[4] }4)CvScalar { double val[4] } 5)CvMat5)CvMat

Page 14: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Some basic Structures (cont..)Some basic Structures (cont..)

CvArr CvArr --> IplImage , CvMat> IplImage , CvMatCvCaptureCvCapture

Page 15: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Some Important functionsSome Important functionsInitialization FunctionsInitialization Functions

cvNamedWindow(char*)cvNamedWindow(char*)cvCreateImagecvCreateImagecvCaptureFromCAM(index)cvCaptureFromCAM(index)

Page 16: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Image Processing FunctionsImage Processing Functions

cvCopycvCopycvFlipcvFlipcvCvtColorcvCvtColorcvNotcvNotcvSmoothcvSmoothcvZerocvZero

Page 17: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Memory Release functionsMemory Release functions

cvReleaseImagecvReleaseImagecvReleaseCapturecvReleaseCapturecvDestroyWindowcvDestroyWindow

Page 18: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Program StepsProgram Steps

1)1) Create WindowCreate Window2)2) Create a capture streamCreate a capture stream3)3) Grab a frame from the streamGrab a frame from the stream4)4) Display frame on the screenDisplay frame on the screen5)5) Release capture and ImagesRelease capture and Images6)6) Destroy window Destroy window

Page 19: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

Sample CodeSample Code

CvCapture* cap = cvCaptureFromCAM(0);CvCapture* cap = cvCaptureFromCAM(0); cvNamedWindow(“Webcam”);cvNamedWindow(“Webcam”); for(;;)for(;;) {{ IplImage* frame = cvQueryFrame(cap);IplImage* frame = cvQueryFrame(cap); cvShowImage(“Webcam”,frame);cvShowImage(“Webcam”,frame); }} cvReleaseCapture(&cap);cvReleaseCapture(&cap); cvDestroyWindow(“Webcam”);cvDestroyWindow(“Webcam”);

Page 20: A Tutorial On Ip 2

Copyright © Robotix Team, IIT KharagpurCopyright © Robotix Team, IIT Kharagpur

THANK YOUTHANK YOU