Ask Your Question
0

How to call setmousecallback opencv in button winforms?

asked 2019-11-22 02:34:52 -0600

Walid gravatar image

updated 2019-11-24 21:47:47 -0600

I want to get coordinate X/Y from image, how to use setmousecallback opencv in button winforms? Thank you Button code :

private: System::Void b_SAsel_Click(System::Object^  sender, System::EventArgs^  e) {
             namedWindow("Display window", 0);
             Mat img = imread("PIC 1.jpg");
             setMouseCallback("Display window", mouseHandler, &img);
}

mousehandler code :

static void mouseHandler(int event, int x, int y, int, void* imgptr){
    Point2f coordinate[30][30];
    int temp;

    RNG rng(12345);
    cv::Point pts[30];
    Mat shape, kontur;
    Mat res;

    if (event != 1) return;
    Mat & img = (*(Mat*)imgptr);
    cv::Point pt1 = cv::Point(x, y);
    temp++;
    pts[temp - 1] = cv::Point(x, y);
    cout << temp << endl;
    coordinate[temp][0] = Point2f(float(x), float(y));
    img.copyTo(shape);
    img.copyTo(kontur);
    .................
        ...........
}

i got this error : Error 10 error C2664: 'void cv::setMouseCallback(const cv::String &,cv::MouseCallback,void *)' : cannot convert argument 2 from 'void (__clrcall *)(int,int,int,int,void *)' to 'cv::MouseCallback' ...\guithes1\guithes\guithesDlg.h 395 1 GUITHES

edit retag flag offensive close merge delete

Comments

maybe you can cast the callback pointer:

setMouseCallback("Display window", (cv::MouseCallback)mouseHandler, &img);

but this is terrible, and won't work:

         Mat img = imread("PIC 1.jpg");
         setMouseCallback(....,...., &img);

img will get destroyed at the end of the function, and you have a dangling pointer in &img

you must NOT create that Mat in a local function, it has to stay alive for the wole lifetime of your program

berak gravatar imageberak ( 2019-11-25 01:42:29 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-11-22 02:46:14 -0600

berak gravatar image

updated 2019-11-22 02:49:11 -0600

if you meant .Net winforms -- you can't.

there is no way opencv can interact with it.

(you'll have to write your own routines there)

edit flag offensive delete link more

Comments

visual studio windows forms app c++, please check my program, thank you

Walid gravatar imageWalid ( 2019-11-24 21:48:55 -0600 )edit

forms app

don't.

berak gravatar imageberak ( 2019-11-25 03:58:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-11-22 02:34:52 -0600

Seen: 487 times

Last updated: Nov 24 '19