morteza kasravi
morteza kasravi

Reputation: 41

mouse click event in openCVsharp

I'm trying to get mouse position inside and opened window in c# using openCVsharp methods.

First I define a callback function:

public void mc(MouseEvent me, int x, int y, MouseEvent me2) {}

Then in initiating phase I open the window an assign that callback function to it:

CvMouseCallback mo = new CvMouseCallback(mc);
Cv.NamedWindow("capture");
Cv.SetMouseCallback("capture", mo);

But callback is not called with mouse clicks in the opened window.

I tried to google it but no sample code or instructions was found for opencvsharp. And since in openCV its just a regular callback method -no need to that CVmousecallback - I couldn't find out how to perform this on openCVsharp.

Has anybody done that in openCVsharp?

Upvotes: 4

Views: 2002

Answers (1)

ResearcherDude
ResearcherDude

Reputation: 11

This works for me:

Mat img = ...;
Window foo = new Window("bar", img); // class OpenCvSharp.CPlusPlus.Window
foo.OnMouseCallback += new CvMouseCallback(mc);

I also tried SetMouseCallback method on the first time, but it didn't work for me either.

Upvotes: 1

Related Questions