1 / 32

Multimedia Programming 19: Mouse with OpenCV

Multimedia Programming 19: Mouse with OpenCV. Departments of Digital Contents Sang Il Park. Mouse Callback in OpenCV. OpenCV 에서 마우스 사용하기. Mouse. With OPENCV. Keyboard. With OPENCV. int cvWaitKey( interval ). Mouse. With OPENCV. cvSetMouseCallback( … ). Mouse Callback?.

Download Presentation

Multimedia Programming 19: Mouse with OpenCV

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multimedia Programming 19:Mouse with OpenCV Departments of Digital Contents Sang Il Park

  2. Mouse Callback in OpenCV OpenCV에서 마우스 사용하기

  3. Mouse With OPENCV

  4. Keyboard With OPENCV int cvWaitKey(interval)

  5. Mouse With OPENCV cvSetMouseCallback(…)

  6. Mouse Callback? • 콜백 함수(Callback): • 특정 함수가 어떤 함수의 인자로서 사용될 때 이 함수를 콜백 함수라고 한다. • 마우스 콜백(mouse callback): • 마우스의 상태에 변화가 생겼을 때 불리는 함수 • 예시) • 마우스가 움직인다 • 왼(오른) 버튼이 눌리고 있음(올라가고 있음), 더블클릭, …

  7. 마우스 콜백 사용하기 • OpenCV에서는 사용자가 임의의 함수를 만들고 이를 마우스에 변화가 생겼을 때 호출되게 할 수 있다. • 이를 위해서는 다음 2가지 일을 하여야 한다: • 구현(Implementation) • 마우스에 변화가 생겼을 때 무엇을 할 것인가?를 정의함. • 등록(Registration) • 위에 정의한 함수를 opencv에게 사용하겠다고 등록시킴. void yourFunction (int event, int x, int y, int flags, void *param); void cvSetMouseCallback(window_name, yourFunction)

  8. 구현(Implementation) • 함수의 이름은 자유롭게 지을 수 있다 • 예) on_mouse(..), myMouse(…), … • 입력 인자들은 OpenCV가 알려주는 것으로 마우스에 어떤 변화가 생겼는 지 알려주는 정보가 담겨있다. void yourFunction (int event, int x, int y, int flags, void *param);

  9. Implementation • OpenCV가 넘겨주는 메세지 • 어떤 마우스 관련 이벤트 종류인지 알려줌 • Examples) void yourFunction (int event, int x, int y, int flags, void *param); CV_EVENT_MOUSEMOVE (마우스가 움직임)CV_EVENT_LBUTTONDOWN (왼쪽버튼이 눌리고 있음)CV_EVENT_RBUTTONDOWN (오른버튼이 눌리고 있음)CV_EVENT_MBUTTONDOWN (중간버튼이 눌리고 있음) CV_EVENT_LBUTTONUP (왼쪽버튼이 올라가고 있음)CV_EVENT_RBUTTONUP(오른버튼이 올라가고 있음)CV_EVENT_MBUTTONUP (중간버튼이 올라가고 있음)

  10. Implementation • OpenCV가 넘겨주는 메세지 • 마우스의 현재 위치를 표현 (x,y) • 값은 이미지 좌표계를 기준으로 함(왼쪽 윗편이 원점) void yourFunction (int event, int x, int y, int flags, void *param); (0,0) (8,2) x y

  11. Implementation • OpenCV가 넘겨주는 메세지 • 마우스 및 키보드의 현재 상태 • Event는 마우스가 현재 취하는 동작 • Flags는 현재 마우스나 키보드의 상태 • Examples) void yourFunction (int event, int x, int y, int flags, void *param); CV_EVENT_FLAG_LBUTTON(왼버튼이 눌린 상태) CV_EVENT_FLAG_RBUTTON (오른버튼이 눌린 상태) CV_EVENT_FLAG_MBUTTON (중간버튼이 눌린 상태) CV_EVENT_FLAG_CTRLKEY (콘트롤키가 눌린 상태) CV_EVENT_FLAG_SHIFTKEY (쉬프트키가 눌린 상태) CV_EVENT_FLAG_ALTKEY (알트키가 눌린 상태)

  12. 등록(Registration) • 어떤 창(window_name)에 마우스에 변화가 생기면 특정 작업(yourFunction)을 수행하라. • Example)cvSetMouseCallback( “test”, on_mouse); “test”라는 창에서 마우스가 움직이면 on_mouse라는 함수를 호출하라 void cvSetMouseCallback(window_name, yourFunction)

  13. 코딩연습 • 마우스에 변화가 생기면 그 때 마우스의 좌표를 출력하라 1. 구현( Implement your ) void myMouse(int event, int x, int y, int flags, void * param) { printf(“mouse: %d %d \n”, x, y); } 2. main() 함수 내에 등록(registration) cvSetMouseCallback(“test”, myMouse);

  14. Coding Practice • 마우스 왼쪽버튼을 누른 곳에 검은 점을 찍으라 1. 구현( Implement your ) 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); } } 2. main() 함수 내에 등록(registration) cvSetMouseCallback(“test”, myMouse);

  15. 팔렛트 만들기 • 마우스 클릭 한 곳의 색 알아내기 구현부(Implement) void myMouse2(int event, int x, int y, int flags, void * param) { if(event == CV_EVENT_LBUTTONDOWN) { s = cvGet2D(img, y, x); } }

  16. OpenCV를 이용한 도형 그리기 OpenCV에서 마우스 사용하기

  17. 선 그리기 void cvLine( IplImage, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1); • pt1 부터 pt2 까지 주어진 두깨로 선을 그린다 • 점의 위치를 표현하는 구조체: CvPoint: • cvPoint(x,y)함수를 사용하면 쉽게 쓸 수 있다 • 예) (0,0)부터 (100,100)까지 검은 선분을 그리는 명령 struct CvPoint { int x; // x-coordinate int y; // y-coordinate } cvLine( img, cvPoint(0,0), cvPoint(100,100), CV_RGB(0,0,0), 3);

  18. 사각형 그리기 void cvRectangle( IplImage, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1 ) • pt1를 pt2 모서리로 가지는 사각형을 그린다 pt1 pt2 두께에 -1을 주면 어떻게 될까?

  19. 원 그리기 void cvCircle( IplImage, CvPoint center, int radius, CvScalar color, int thickness=1 ) • 주어진 중심과 반지름을 갖는 원을 그린다 radius center

  20. 코딩연습 • 마우스의 왼쪽 버튼 클릭하고 드래깅하여 그 크기만큼 사각형을 그리라 • 마우스의 오른 버튼이 눌린 곳에 반지름 50짜리 원을 그리라또는 마우스의 오른 버튼을 드래깅하여 그 크기만큼 원을 그리라

  21. Topics for the Term Project

  22. Feature based Image Metamorphosis • Thaddeus Beier and Shawn Neely, “Feature-Based Image Metamorphosis “, SIGGRAPH 1992

  23. Image Deformation • S. Schaefer, T. McPhail, J. Warren, “Image Deformation Using Moving Least Squares”, SIGGRAPH 2006

  24. Texture synthesis • A. A. Efros and T. K. Leung, "Texture Synthesis by Non-parametric Sampling", ICCV 99 • Wei and Levoy, “Fast Texture Synthesis using Tree-structured Vector Quantization “, SIGGRAPH 2000

  25. Image Analogy • A. Hertzmann, C. Jacobs, N. Oliver, B. Curless, D. Salesin, “Image Analogy”,SIGGRAPH 2001

  26. Colorization • Tomihisa Welsh, Michael Ashikhmin, and Klaus Mueller, ”Transferring color to grayscale images”, SIGGRAPH 2002

  27. Image Blending • Patrick Perez, Michel Gangnet, Andrew Blake, “Poisson Image Editing”, SIGGRAPH 2003 • http://www.cs.tau.ac.il/~tommer/adv-graphics/ex1.htm Poisson seamless cloning source images

  28. Matting • J. Sun, J. Jia, C. Tang, H. Shum, “Poisson Matting”, SIGGRAPH 2004 extracted foreground object image composition source image opacity

  29. Content-Aware Image Resizing • Shai Avidan, Ariel Shamir, “Seam Carving for Content-Aware Image resizeing”, SIGGRAPH 2006 • http://www.seamcarving.com/ source image resized image

  30. Painterly Rendering • Aaron Hertzmann, "Painterly Rendering with Curved Brush Strokes of Multiple Sizes“, SIGGRAPH 1998

  31. Painterly Rendering2 • Michio Shiraishi and Yasushi Yamaguchi , “Image Moment-Based Stroke Placement”, ACM SIGGRAPH 99 Conference abstracts and applications, 1999

  32. High Dynamic Range Compression • Raanan Fattal, Dani Lischinski, Michael Werman,“Gradient Domain High Dynamic Range Compression”, ACM SIGGRAPH 2002

More Related