Learning opencv--mouse events (picture frames)

Source: Internet
Author: User

[CPP]View PlainCopyprint?
  1. #include "Cv.h"
  2. #include "highgui.h"
  3. BOOL check_line_state=false;
  4. Iplimage* workimg;
  5. Iplimage* imgshow;
  6. Cvrect Roi_rect;
  7. void On_mouse4 (int event, int x,int y,int flags,void* param)
  8. {
  9. int thickness=2;
  10. Cvpoint P1,P2;
  11. if (event==cv_event_lbuttondown)
  12. {
  13. //Current mouse position (x, y)
  14. Roi_rect.x=x;
  15. Roi_rect.y=y;
  16. Check_line_state=true;
  17. }
  18. Else if (check_line_state&&event==cv_event_mousemove)//mouse state
  19. {
  20. Cvcopy (workimg,imgshow); //This step is important to constantly update the display image, otherwise the picture shown in Figure 2
  21. P1=cvpoint (ROI_RECT.X,ROI_RECT.Y);
  22. P2=cvpoint (x, y);
  23. Cvrectangle (Imgshow,p1,p2,cv_rgb (0,255,150), thickness,cv_aa,0);
  24. Cvshowimage ("image", imgshow);
  25. }
  26. Else if (check_line_state&&event==cv_event_lbuttonup)
  27. {
  28. Check_line_state=false;
  29. Cvwaitkey (20);
  30. }
  31. }
  32. int main ()
  33. {
  34. Workimg=cvloadimage ("d:/demo.jpg", 1);
  35. Imgshow=cvcreateimage (Cvsize (workimg->width,workimg->height), workimg->depth,workimg->nchannels);
  36. Cvcopy (workimg,imgshow);
  37. //cvflip (imgshow);
  38. roi_rect.x=roi_rect.y=0;
  39. Cvnamedwindow ("image", cv_window_autosize);
  40. Cvshowimage ("image", imgshow);
  41. Cvsetmousecallback ("image", on_mouse4);
  42. Cvwaitkey ();
  43. Cvdestroywindow ("image");
  44. }

Figure 1: Figure 2:

from:http://blog.csdn.net/yangtrees/article/details/7573919

Learning opencv--mouse events (picture frames)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.