I have the following code that shows me the values of the X and Y coordinates when I click twice 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 can not.
Does anyone know how to adapt the code? I tried to change the function type to int
and pass x and y by reference, but I did not succeed.