0
I have the following code that shows me the values of the coordinates X and Y when I double click with the left mouse button.
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void mouse_callback(int event, int x, int y, int flag, void *param)
{
if (event == EVENT_LBUTTONDBLCLK)
{
cout << "(" << x << ", " << y << ")" << endl;
}
}
int main()
{
Mat img = imread("img1.jpg");
namedWindow("exemplo");
setMouseCallback("exemplo", mouse_callback);
imshow("exemplo", img);
waitKey();
return 0;
}
However, I need to return the x and y coordinates to perform some calculations and I’m not getting.
Does anyone know how to adapt the code? I tried to change the type of function to int
and pass x and y by reference, but did not succeed.
You can’t change the signature of the callback. If you want to do calculations outside of it, store the values in global variables, or call your own callback from it.
– Luiz Vieira
I managed to do what I wanted using global variables. Thank you very much!
– zampnrs