identifier of on_change function is not defined in cv::createButton()

asked 2017-05-11 11:58:36 -0600

updated 2017-05-11 12:01:20 -0600

berak gravatar image

Hello,

I'ver got a problem with the initalisation of the required function pionter "on_change" in

 createButton(const string& bar_name, ButtonCallback on_change, void* userdata=NULL, int type=CV_PUSH_BUTTON, bool initial_button_state=0 ).

The compiler gives the error that the identifiers is not defined. Although, I initalised it just like the "CallBackFunc" which is working fine.

Does somebody has an idea where the problem is?

Thank you!

This is my code:

void On_click(int state, void *pointer)
{
    printf("Check!");
}


void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
    if (event == EVENT_LBUTTONDOWN)
    {
        cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
    }
    else if (event == EVENT_RBUTTONDOWN)
    {
        cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
    }
    else if (event == EVENT_MBUTTONDOWN)
    {
        cout << "Middle button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
    }
    else if (event == EVENT_MOUSEMOVE)
    {
        cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;

    }
}

int main(int argc, char** argv)
{

    // Read image from file 
    Mat img = imread("lena.tif");

    //if fail to read the image
    if (img.empty())
    {
        cout << "Error loading the image" << endl;
        return -1;
    }
    //Create a window
    namedWindow("My Window", CV_WINDOW_NORMAL);
    char* nameb1 = "button1";
    cv::createButton(nameb1, On_click, nameb1, CV_CHECKBOX, 1);
    //set the callback function for any mouse event
    setMouseCallback("My Window", CallBackFunc, NULL);

    //show the image
    imshow("My Window", img);

    // Wait until user press some key
    waitKey(0);

    return 0;

}
edit retag flag offensive close merge delete

Comments

1

are you aware, that createButton() is only available, IF you compiled the highgui module with Qt ?

also, the exact error msg is needed, here.

berak gravatar imageberak ( 2017-05-11 12:03:07 -0600 )edit
1

No, I that is the problem because I'm working with VS. Thanks for the quick response!

Veratarier gravatar imageVeratarier ( 2017-05-11 12:07:27 -0600 )edit
1

actually, that would have lead to a runtime exception.

it IS possible, to compile it wit Qt using VS though. not sure, where your compiler error is from. so anyway, could you at least update the error ? (maybe someone else has an idea about that)

berak gravatar imageberak ( 2017-05-11 12:12:25 -0600 )edit
1

Yes you can compile and execute withoutQT and :

OpenCV Error: The function/feature is not implemented (The library is compiled without QT support) in cv::createButton, file G:\Lib\opencv\modules\highgui\src\window.cpp, line 526
LBerger gravatar imageLBerger ( 2017-05-11 12:46:00 -0600 )edit