Adapt code to return mouse position

0

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.

    
asked by anonymous 04.09.2018 / 20:38

0 answers