Multimedia Programming 10: Mouse, Draw and Morphing Departments of Digital Contents Sang Il Park
Outline Review Mouse Callback in OpenCV Draw Morphing
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
Mouse Callback in OpenCV Mouse Interaction with OpenCV
Mouse With OPENCV
Keyboard With OPENCV int cvWaitKey(interval)
Mouse With OPENCV cvSetMouseCallback(…)
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 …
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);
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);
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);
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);
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);
Registration Example) cvSetMouseCallback( “test”, on_mouse); void cvSetMouseCallback(window_name, yourFunction)
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);
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
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 }
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?
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
Basic Morphing with Mouse Moving one point to the other
Basic Morphing with Mouse Moving one point to the other
Basic Morphing with Mouse Moving one point to the other
Basic Morphing with Mouse Moving one point to the other
Bilinear interpolation Sampling at f(x,y): displacement at (x,y)
Basic Morphing with Mouse Moving one point to the other
? Basic Morphing with Mouse Moving one point to the other
Basic Morphing with Mouse Moving one point to the other
? Basic Morphing with Mouse Moving one point to the other