SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "opencv2/highgui/highgui.hpp"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. using namespace cv;
  6.  
  7. void CallBackFunc(int event, int x, int y, int flags, void* userdata)
  8. {
  9.      if  ( event == EVENT_LBUTTONDOWN )
  10.      {
  11.           cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
  12.      }
  13.      else if  ( event == EVENT_RBUTTONDOWN )
  14.      {
  15.           cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
  16.      }
  17.      else if  ( event == EVENT_MBUTTONDOWN )
  18.      {
  19.           cout << "Middle button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
  20.      }
  21.      else if ( event == EVENT_MOUSEMOVE )
  22.      {
  23.           cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;
  24.  
  25.      }
  26. }
  27.  
  28. int main(int argc, char** argv)
  29. {
  30.      // Read image from file
  31.      Mat img = imread("MyPic.JPG");
  32.  
  33.      //if fail to read the image
  34.      if ( img.empty() )
  35.      {
  36.           cout << "Error loading the image" << endl;
  37.           return -1;
  38.      }
  39.  
  40.      //Create a window
  41.      namedWindow("My Window", 1);
  42.  
  43.      //set the callback function for any mouse event
  44.      setMouseCallback("My Window", CallBackFunc, NULL);
  45.  
  46.      //show the image
  47.      imshow("My Window", img);
  48.  
  49.      // Wait until user press some key
  50.      waitKey(0);
  51.  
  52.      return 0;
  53.  
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top