Ask Your Question
0

cv::setMouseCallBack does not work on MacOS

asked 2017-06-26 12:32:54 -0500

Dear All,

I have started to learn OpenCV. But have a question.

My MacOS version is Sierra 10.12.5. I downloaded opencv and opencv_contrib repos and build using CMAKE 3.8.2, everything seems ok.But I wrote this sample (see Github) to test my installation every line of code works well but mouseCallBack doesn't work as expected.

I would be pleased if anyone give me another perspective.

Regards. Mehmet.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2017-06-26 23:47:13 -0500

berak gravatar image

apple users always suspect, that it's about their funny little boxes, but here - not so.

your mouse handler expects to be passed an image via the void* param, but you fail to give it an image

so, that should be:

cv::setMouseCallback(ORIGINAL_WINDOW_NAME, MouseHandler::onMouse, (void*)(&image));

you also should check for invalid pointers:

void  MouseHandler::onMouse(int event, int x, int y, int, void *param) {
    std::cout << "Mouse event fired!" << std::endl;
    if (!param) {
        std::cout << "there is no image !!" << std::endl;
        return;
    }
    cv::Mat *im = static_cast<cv::Mat *>(param);
    ....
edit flag offensive delete link more

Comments

Thank you for your answer.I also pass image address as a parameter. It is still same.

mganitombalak gravatar imagemganitombalak ( 2017-07-16 13:06:03 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-26 12:31:44 -0500

Seen: 145 times

Last updated: Jun 26 '17