Mat function and setMouseCallback

I have an example function my_mouse_callback that works with IplImage *:

 void my_mouse_callback(int event, int x, int y, int flags, void* param) { IplImage* image = (IplImage*) param; switch( event ) { case CV_EVENT_LBUTTONDOWN: drawing_box = true; box = cvRect(x, y, 0, 0); break; ... draw_box(image, box); break; } 

which is implemented in main as follows:

 cvSetMouseCallback(Box Example,my_mouse_callback,(void*) image); 

The problem is that in my code I use a Mat object and it cannot be passed to the setMouseCallback function.

I am looking for a solution that does not include passing Mat in IplImage *.

Or, if there is no solution, how can I convert Mat to IplImage * correctly?

I tried this already with this code from the opencv documentation:

 Mat I; IplImage* pI = &I.operator IplImage(); 

and it didn’t work.

+4
source share
2 answers

There is no equivalent of this function in the C ++ interface, as far as I can tell.

But you can convert cv::Mat to IplImage* like this , and vice versa:

 cv::Mat mat(my_IplImage); 
+3
source

Why can't you port Mat to your MouseCallback function? You just did it with IplImage. Mats are just pointers. Here is how I did it.

 void onMouse(int event, int x, int y, int flags, void* param) { Mat src; src = *((Mat*)param); ... 

and called it like this in my main loop:

  setMouseCallback("source", onMouse, &src); 
+2
source

Source: https://habr.com/ru/post/1381938/


All Articles