Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multimedia Programming 02: Play with Images Departments of Digital Contents Sang Il Park.

Similar presentations


Presentation on theme: "Multimedia Programming 02: Play with Images Departments of Digital Contents Sang Il Park."— Presentation transcript:

1 Multimedia Programming 02: Play with Images Departments of Digital Contents Sang Il Park

2 Announcement Homepage is now open! http://dasan.sejong.ac.kr/~sipark/class2007/mm http://dasan.sejong.ac.kr/~sipark/class2007/mm

3 Outline OpenCV How to start Your first OpenCV code: HelloCV Basic Functions Pixel Draw Lines or whatever you want Conclusion

4 What is OpenCV? OpenCV –Stands for Open Source Computer Vision Library –Includes 500 functions implementing algorithms: Computer vision Image processing General Purpose numeric algorithms –Portable and efficient (C/C++) –Absolutely free!

5 Who did make this? Being developed at Intel since 1999 Available on Windows, Linux and MacOSX. Extensively used in many companies and research centers Home page: www.intel.com/technology/computing/opencv/ www.intel.com/technology/computing/opencv/

6 OpenCV –Intended Applications Computer Human Interaction (HCI) Object Identification Segmentation and Recognition Face Recognition Gesture Recognition Motion Tracking Motion Understanding And so on.

7 Where you can find this http://sourceforge.net/projects/opencvlibrary http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16937

8 OpenCV structure CXCORE basic structures and algoritms, XML support, drawing functions CV Image processing and vision algorithms HighGUI GUI, Image and Video I/O We will mostly focus on these two in this presentation

9 HelloCV: Your First OpenCV Code Loading an image and showing it

10 Make a new project Start Visual Studio 6.0 or Visual Studio.Net Make a new project –Win32 Console Application Program Compile and run it! (Ctrl + F5)

11 Initial Setup Directories: –Includes: "C:\Program Files\OpenCV\cv\include" "C:\Program Files\OpenCV\cxcore\include" "C:\Program Files\OpenCV\otherlibs\highgui“ –Libraries: "C:\Program Files\OpenCV\lib“ Library files you need: –cv.lib cxcore.lib highgui.lib

12 Initial Setup Include Directories (tools  options): "C:\Program Files\OpenCV\cv\include" "C:\Program Files\OpenCV\cxcore\include" "C:\Program Files\OpenCV\otherlibs\highgui“

13 Initial Setup Library Directories: (tools  options) "C:\Program Files\OpenCV\lib“

14 Initial Setup Library files you need: –cv.lib cxcore.lib highgui.lib

15 Initial Set up Include Header files –#include #include #include

16 HelloCV Type this: #include "stdafx.h" #include int _tmain(int argc, _TCHAR* argv[]) { IplImage * img; img = cvLoadImage("d:\\test.jpg"); cvNamedWindow("HelloCV"); cvShowImage("HelloCV", img); cvWaitKey(); cvDestroyWindow("HelloCV"); cvReleaseImage(&img); return 0; } http://dasan.sejong.ac.kr/~sipark/class2007/mm/code/ hellocv.cpp

17 Error! Copy every dll files –from: C:\Program Files\OpenCV\bin –To: under your debug folder

18 HelloCV

19 #include "stdafx.h" #include int _tmain(int argc, _TCHAR* argv[]) { IplImage * img; img = cvLoadImage("d:\\test.jpg"); cvNamedWindow("HelloCV"); cvShowImage("HelloCV", img); cvWaitKey(); cvDestroyWindow("HelloCV"); cvReleaseImage(&img); return 0; } http://dasan.sejong.ac.kr/~sipark/class2007/mm/code/ hellocv.cpp IplImage cvLoadImage cvReleaseImage cvNamedWindow cvShowImage cvDestroyWindow cvWaitKey

20 Image structure IplImage (Image Processing Library) typedef struct _IplImage { int nSize; /* size of iplImage struct */ int ID; /* image header version */ int nChannels; int alphaChannel; int depth; /* pixel depth in bits */ char colorModel[4]; char channelSeq[4]; int dataOrder; int origin; int align; /* 4- or 8-byte align */ int width; int height; struct _IplROI *roi; /* pointer to ROI if any */ struct _IplImage *maskROI; /*pointer to mask ROI if any */ void *imageId; /* use of the application */ struct _IplTileInfo *tileInfo; /* contains information on tiling*/ int imageSize; /* useful size in bytes */ char *imageData; /* pointer to aligned image */ int widthStep; /* size of aligned line in bytes */ int BorderMode[4]; /* the top, bottom, left,and right border mode */ int BorderConst[4]; /* constants for the top, bottom,left, and right border */ char *imageDataOrigin; /* ptr to full, nonaligned image */ } IplImage;

21 Image I/O IplImage* cvLoadImage(image_path, colorness_flag); loads image from file, converts to color or grayscle, if need, and returns it (or returns NULL). image format is determined by the file contents. #define CV_LOAD_IMAGE_COLOR 1 #define CV_LOAD_IMAGE_GRAYSCALE 0 #define CV_LOAD_IMAGE_UNCHANGED -1  DEFAULT cvSaveImage(image_path, image); saves image to file, image format is determined from extension. cvReleaseImage(image_path, image); releases memory BMP, JPEG, PNG, TIFF, PPM/PGM formats are supported. IplImage* img = cvLoadImage(“picture.jpeg”,-1); if( img ) cvSaveImage( “picture.bmp”, img );

22 Windows cvNamedWindow(window_name, fixed_size_flag); creates window accessed by its name. Window handles repaint, resize events. Its position is remembered in registry: cvNamedWindow(“ViewA”); cvMoveWindow(“ViewA”,300,100); cvDestroyWindow(“ViewA”); … cvShowImage(window_name, image); copies the image to window buffer, then repaints it when necessary. {8u|16s|32s|32f}{C1|3|4} are supported. only the whole window contents can be modified. Dynamic updates of parts of the window are done using operations on images, drawing functions etc. cvDestroyWindow(window_name); deletes the window with the given name

23 User Input int cvWaitKey( int delay=0 ) waits for a pressed key. After waiting for the given delay, it proceeds. Zero delay means waiting forever until user input. –Delay in milliseconds.  Good for animating something Example) swapping between two images

24 What else HighGUI can do? “Smart” windows Image I/O, rendering Processing keyboard and other events, timeouts Trackbars Mouse callbacks Video I/O

25 Pixel Accessing Image Coordinate System Color Value: CvScalar –A container for 1-,2-,3- or 4-tuples of numbers –typedef struct CvScalar { double val[4]; } CvScalar; Example) CvScalar s; s.val[0] = 200;(Blue) s.val[1] = 11;(Green) s.val[2] = 123;(Red) x y (0,0)(8,2)

26 Pixel Accessing CvScalar cvGet2D (image, y, x) Gets color value at (x,y). –Example)CvScalar s; s = cvGet2D(img, 30, 40); void cvSet2D (image, y, x, CvScalar) Sets color value at (x,y). –Example)CvScalar s = cvScalar(100,0,0); cvSet2D(img, 30, 40, s); OR cvSet2D(img, 30, 40, cvScalar(100,0,0)); OR cvSet2D(img, 30, 40, CV_RGB(0,0,100));

27 Create an empty canvas IplImage* cvCreateImage( CvSize size, int depth, int channels ); –Depth: color depth: IPL_DEPTH_8U –Channels: 1,2,3,4 (1=grey, 3=color) –Example) IplImage * img; img = cvCreateImage(cvSize(200,100), IPL_DEPTH_8U,3); cvSet(image, CvScalar) –Fill canvas with a color –Example) cvSet(img, CV_RGB(255,255,255));

28 So far what you’ve learned: IplImage cvLoadImage (file_name) cvCreateImage (size, depth, channels) cvSaveImage (file_name, image) cvReleaseImage (image) cvNamedWindow (window_name) cvShowImage (window_name, image) cvDestroyWindow (window_name) cvWaitKey (delay) cvGet2D (image, y, x) cvSet2D (image, y, x, cvScalar)

29 Put everything together! int _tmain(int argc, _TCHAR* argv[]) { IplImage * img; img = cvLoadImage("d:\\test.jpg"); cvNamedWindow("HelloCV"); cvShowImage("HelloCV", img); cvWaitKey(); int x,y; for(x=0; x<100; x++) for(y=0; y<100; y++) { CvScalar s = cvGet2D(img, y,x); s.val[0] +=50; s.val[1] +=50; s.val[2] +=50; cvSet2D(img,y,x,s); } cvShowImage("HelloCV", img); cvWaitKey(); cvDestroyWindow("HelloCV"); cvReleaseImage(&img); return 0; } HelloCV2.cpp

30 A Simple Function: Line Drawing Horizontal line drawing: –void DrawHLine (IplImage * img, int y, int st, int ed, CvScalar color) image

31 Do more! Design a function that draws a rectangle –void DrawRectangle (IplImage * img, int x, int y, int w, int h, CvScalar color) –Don’t forget to make sure a pixel is inside the image 0 width 0 height If done, try to draw 50 random boxes with random colors! (x,y) w h

32 For those who want more OpenCV Wiki-pages: http://opencvlibrary.sourceforge.nethttp://opencvlibrary.sourceforge.net For HighGUI: –http://opencvlibrary.sourceforge.net/HighGuihttp://opencvlibrary.sourceforge.net/HighGui For cxcore: –http://opencvlibrary.sourceforge.net/CxCorehttp://opencvlibrary.sourceforge.net/CxCore Supplied documentation: OpenCV/docs/index.htm, faq.htm A Korean Community: http://www.opencv.co.kr/http://www.opencv.co.kr/

33 Program Assignment #1 Long long times ago in Russian Empire –Sergei Mikhailovich Prokudin-Gorskii (1863-1944) –A man who pursuing a colorful future in 1907 http://www.loc.gov/exhibits/empire/

34 Program Assignment #1 His invention A cameraHis camera

35 Program Assignment #1 His pictures with the current digital technology

36 Program Assignment #1 Recover the colorful world in 1907 by yourself! 1I3 align B G R

37 Program Assignment #1 4 Images can be found in the class homepage: –http://dasan.sejong.ac.kr/~sipark/class2007/mm/http://dasan.sejong.ac.kr/~sipark/class2007/mm/ Make a team of two students Due date: 9/11 before the class –Submit a written report and email the codes and a execution file Type the filename in the cmd window, then generate a color image! Grading Policy: –Making a color image: 60 –Automatic alignment: 40


Download ppt "Multimedia Programming 02: Play with Images Departments of Digital Contents Sang Il Park."

Similar presentations


Ads by Google