1 | initial version |
and here is, how to get your image Mat into the callback function:
void CallBackFunc(int event, int x, int y, int flags, void* userdata) { Mat& image = ((Mat)userdata); // 1st cast, then deref. if (event == EVENT_LBUTTONDOWN) // or rather, buttonup ? { cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl; rectangle(img, ? ? ? ?); // your task ! } }
in main, pass your image to the callback:
setMouseCallback("Display window", CallBackFunc, &image);
2 | No.2 Revision |
and here is, how to get your image Mat into the callback function:
in main, pass (the address of) your image to the callback:
setMouseCallback("Display window", CallBackFunc, &image);
inside the callback function, unwrap it:
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
Mat& image = ((Mat)userdata); *((Mat*)userdata); // 1st cast, then deref.
if (event == EVENT_LBUTTONDOWN) // or rather, buttonup ?
{
cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
rectangle(img, ? ? ? ?); // your task !
}
} in main, pass your image to the callback:
setMouseCallback("Display window", CallBackFunc, &image);
}
you should use the opencv headers like this:
#include "opencv2/core.hpp" // forward slashes, please, and no subfolder
#include "opencv2/highgui.hpp"
you also need the imgproc header:
#include "opencv2/imgproc.hpp"
3 | No.3 Revision |
and here is, how to get your image Mat into the callback function:
in main, pass (the address of) your image to the callback:
setMouseCallback("Display window", CallBackFunc, &image);
inside the callback function, unwrap it:
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
Mat& image = *((Mat*)userdata); // 1st cast, then deref.
if (event == EVENT_LBUTTONDOWN) // or rather, buttonup ?
{
cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
rectangle(img, rectangle(image, ? ? ? ?); // your task !
}
}
you should use the opencv headers like this:
#include "opencv2/core.hpp" // forward slashes, please, and no subfolder
#include "opencv2/highgui.hpp"
you also need the imgproc header:
#include "opencv2/imgproc.hpp"
4 | No.4 Revision |
and here is, how to get your image Mat into the callback function:
in main, pass (the address of) your image to the callback:
setMouseCallback("Display window", CallBackFunc, &image);
inside the callback function, unwrap it:
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
Mat& image = *((Mat*)userdata); // 1st cast, then deref.
if (event == EVENT_LBUTTONDOWN) // or rather, buttonup ?
{
cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
rectangle(image, ? ? ? ?); // your task !
}
}
you should use the opencv headers like this:
#include "opencv2/core.hpp" // forward slashes, please, and no subfolder
#include "opencv2/highgui.hpp"
you also need the imgproc header:header (for any of the drawing calls):
#include "opencv2/imgproc.hpp"
5 | No.5 Revision |
and here is, how to get your image Mat into the callback function:
in main, pass (the address of) your image to the callback:
setMouseCallback("Display window", CallBackFunc, &image);
inside the callback function, unwrap it:
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
Mat& image = *((Mat*)userdata); // 1st cast, then deref.
if (event == EVENT_LBUTTONDOWN) // or rather, buttonup ?
{
cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
rectangle(image, ? ? ? ?); // your task !
imshow("Display window", image); // update our image.
}
}
you should use the opencv headers like this:
#include "opencv2/core.hpp" // forward slashes, please, and no subfolder
#include "opencv2/highgui.hpp"
you also need the imgproc header (for any of the drawing calls):
#include "opencv2/imgproc.hpp"