Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park.

Similar presentations


Presentation on theme: "Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park."— Presentation transcript:

1 Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park

2 Outline Review Mouse Callback in OpenCV Draw Morphing

3 Review Image Morphing 1.Create an intermediate shape (by interpolation) 2.Warp both images towards it 3.Cross-dissolve the colors in the newly warped images

4 Mouse Callback in OpenCV Mouse Interaction with OpenCV

5 Mouse With OPENCV

6 Keyboard With OPENCV int cvWaitKey(interval)

7 Mouse With OPENCV cvSetMouseCallback(…)

8 Mouse Callback? Callback: –executable code that is passed as an argument to other code.executable codeargument Mouse Callback: –A function that is called when any change happens in your mouse –Examples) Mouse Move Left(right) Button Down(Up), Double click …

9 Mouse Callback Two things you have to do: –Implementation Define what you are going to do when events happen –Setting (registration) Let the OpenCV know which one is the callback function void cvSetMouseCallback(window_name, yourFunction) void yourFunction (int event, int x, int y, int flags, void *param);

10 Implementation You can make your own function name Example) on_mouse, myMouse, … Parameters are for the information about the incoming mouse event from OvenCV void yourFunction (int event, int x, int y, int flags, void *param);

11 Implementation Message from the OpenCV Telling what kind of the mouse event is coming Examples) CV_EVENT_MOUSEMOVE CV_EVENT_LBUTTONDOWN CV_EVENT_RBUTTONDOWN CV_EVENT_MBUTTONDOWN CV_EVENT_LBUTTONUP CV_EVENT_RBUTTONUP CV_EVENT_MBUTTONUP CV_EVENT_LBUTTONDBLCLK CV_EVENT_RBUTTONDBLCLK CV_EVENT_MBUTTONDBLCLK void yourFunction (int event, int x, int y, int flags, void *param);

12 Implementation Message from the OpenCV Mouse position (x,y) Based on the Image Coordinate System y (0,0)(8,2) x void yourFunction (int event, int x, int y, int flags, void *param);

13 Implementation Message from the OpenCV Telling the status of the mouse or the keyboard Examples) CV_EVENT_FLAG_LBUTTON CV_EVENT_FLAG_RBUTTON CV_EVENT_FLAG_MBUTTON CV_EVENT_FLAG_CTRLKEY CV_EVENT_FLAG_SHIFTKEY CV_EVENT_FLAG_ALTKEY void yourFunction (int event, int x, int y, int flags, void *param);

14 Registration Example) cvSetMouseCallback( “test”, on_mouse); void cvSetMouseCallback(window_name, yourFunction)

15 Coding Practice Put a point when you click your left button. void myMouse(int event, int x, int y, int flags, void * param) { if(event == CV_EVENT_LBUTTONDOWN) { cvSet2D(img, y, x, CV_RGB(0,0,0)); cvShowImage(“test”, img); } 1. Implement your function 2. Register your function in main() cvSetMouseCallback(“test”, myMouse);

16 Using a Palette Get color when you click your left button. void myMouse2(int event, int x, int y, int flags, void * param) { if(event == CV_EVENT_LBUTTONDOWN) { s = cvGet2D(img, y, x); } Implement your function

17 Draw Line void cvLine( IplImage, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1); Draw Line from pt1 to pt2 with the given thickness CvPoint: a structure for storing 2D position –Use cvPoint(x,y) for a quick usage. struct CvPoint { int x; // x-coordinate int y; // y-coordinate } struct CvPoint { int x; // x-coordinate int y; // y-coordinate }

18 Draw Rectangle void cvRectangle( IplImage, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1 ) void cvRectangle( IplImage, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1 ) Draw a rectangle with two opposite corners pt1 and pt2 pt1 pt2 What happens if thickness is -1?

19 Draw Circle void cvCircle( IplImage, CvPoint center, int radius, CvScalar color, int thickness=1 ) void cvCircle( IplImage, CvPoint center, int radius, CvScalar color, int thickness=1 ) Draw a circle with given center and radius center radius

20 Basic Morphing with Mouse Moving one point to the other

21 Basic Morphing with Mouse Moving one point to the other

22 Basic Morphing with Mouse Moving one point to the other

23 Basic Morphing with Mouse Moving one point to the other

24 Bilinear interpolation Sampling at f(x,y): displacement at (x,y)

25 Basic Morphing with Mouse Moving one point to the other

26 ? Basic Morphing with Mouse Moving one point to the other

27 Basic Morphing with Mouse Moving one point to the other

28 ? Basic Morphing with Mouse Moving one point to the other


Download ppt "Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park."

Similar presentations


Ads by Google