-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowMouseClick.cc
46 lines (43 loc) · 1.21 KB
/
ShowMouseClick.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
if ( event == EVENT_LBUTTONDOWN )
{
cout << "Left button clicked " << x << " " << y << endl;
}
else if ( event == EVENT_RBUTTONDOWN )
{
cout << "Right button clicked " << x << " " << y << endl;
}
else if ( event == EVENT_MBUTTONDOWN )
{
cout << "Middle button is clicked " << x << " " << y << endl;
}
else if (flags == CV_EVENT_FLAG_LBUTTON)
{
cout << "Mouse move over the window " << x << " " << y << endl;
}
}
int main(int argc, char** argv)
{
// Read image from file
Mat img = imread(string(argv[1]));
//if fail to read the image
if ( img.empty() )
{
cout << "Error loading the image" << endl;
return -1;
}
//Create a window
namedWindow("My Window", 1);
//set the callback function for any mouse event
setMouseCallback("My Window", CallBackFunc, NULL);
//show the image
imshow("My Window", img);
// Wait until user press some key
waitKey(0);
return 0;
}