Ask Your Question

Revision history [back]

With your current code snippet, you are simply drawing a rectangle over a selected button. To achieve what you want, two things are needed:

  1. Have a global button object/variable which keeps track of the last selected button/rectangle. For this example, let's call it lastSelectedBtn
  2. Your callback manipulation will look like this

    void callBackFunc1(int event, int x, int y, int flags, void* userdata)
    {
        Buttons* button = (Buttons*)userdata;
        Vec3b selectButton;
    
        if (event == EVENT_LBUTTONDOWN)
        {
            if (button-> leftHand.contains(Point(x, y)))
            {
                lastSelectedBtn.hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Hand ROI\n" << endl;
                rectangle(drawRect, button->leftHand, selectButton, 5, 8, 0);
            }
            else if (button->leftElbow.contains(Point(x, y)))
            {
                lastSelectedBtn.hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Elbow ROI\n" << endl;
                rectangle(drawRect, button->leftElbow, selectButton, 5, 8, 0);
            }
        imshow("Label Tool", drawRect);
      }
    }
    

DISCLAIMER

Correct me if I am wrong but a glimpse into OpenCV High GUI shows that they do not provide any way of hiding created GUI element. This means that the lastSelectedBtn.hidden = true logic part will have to be done at the OS level.

With your current code snippet, you are simply drawing a rectangle over a selected button. To achieve what you want, two things are needed:

  1. Have a global button object/variable which keeps track of the last selected button/rectangle. For this example, let's call it lastSelectedBtn
  2. Your callback manipulation will look like this

    void callBackFunc1(int event, int x, int y, int flags, void* userdata)
    {
        Buttons* button = (Buttons*)userdata;
        Vec3b selectButton;
    
        if (event == EVENT_LBUTTONDOWN)
        {
            if (button-> leftHand.contains(Point(x, y)))
            {
                lastSelectedBtn.hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Hand ROI\n" << endl;
                rectangle(drawRect, button->leftHand, selectButton, 5, 8, 0);
            }
            else if (button->leftElbow.contains(Point(x, y)))
            {
                lastSelectedBtn.hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Elbow ROI\n" << endl;
                rectangle(drawRect, button->leftElbow, selectButton, 5, 8, 0);
            }
        imshow("Label Tool", drawRect);
      }
    }
    

DISCLAIMER

Correct me if I am wrong but a glimpse into OpenCV High GUI shows that they do not provide any a way of hiding created GUI element. elements. This means that the lastSelectedBtn.hidden = true logic part will have to be done at the OS level.

With your current code snippet, you are simply drawing a rectangle over a selected button. To achieve what you want, two things are needed:

  1. Have a global button object/variable which keeps track of the last selected button/rectangle. For this example, let's call it lastSelectedBtn
  2. Your callback manipulation will look like this

    void callBackFunc1(int event, int x, int y, int flags, void* userdata)
    {
        Buttons* button = (Buttons*)userdata;
        Vec3b selectButton;
    
        if (event == EVENT_LBUTTONDOWN)
        {
            if (button-> leftHand.contains(Point(x, y)))
            {
                lastSelectedBtn.hidden lastSelectedBtn->hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Hand ROI\n" << endl;
                rectangle(drawRect, button->leftHand, selectButton, 5, 8, 0);
            }
            else if (button->leftElbow.contains(Point(x, y)))
            {
                lastSelectedBtn.hidden lastSelectedBtn->hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Elbow ROI\n" << endl;
                rectangle(drawRect, button->leftElbow, selectButton, 5, 8, 0);
            }
        imshow("Label Tool", drawRect);
      }
    }
    

DISCLAIMER

Correct me if I am wrong but a glimpse into OpenCV High GUI shows that they do not provide a way of hiding created GUI elements. This means that the lastSelectedBtn.hidden lastSelectedBtn->hidden = true logic part will have to be done at the OS level.

With your current code snippet, you are simply drawing a rectangle over a selected button. To achieve what you want, two things are needed:

  1. Have a global button object/variable which keeps track of the last selected button/rectangle. button. For this example, let's call it lastSelectedBtn

  2. Your callback manipulation will look like this

    void callBackFunc1(int event, int x, int y, int flags, void* userdata)
    {
        Buttons* button = (Buttons*)userdata;
        Vec3b selectButton;
    
        if (event == EVENT_LBUTTONDOWN)
        {
            if (button-> leftHand.contains(Point(x, y)))
            {
                lastSelectedBtn->hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Hand ROI\n" << endl;
                rectangle(drawRect, button->leftHand, selectButton, 5, 8, 0);
            }
            else if (button->leftElbow.contains(Point(x, y)))
            {
                lastSelectedBtn->hidden = true; // hide the last selected button
                lastSelectedBtn = button; // update it to the recently selected button
                selectButton = Vec3b(0, 0, 250);
                cout << "Select Left Elbow ROI\n" << endl;
                rectangle(drawRect, button->leftElbow, selectButton, 5, 8, 0);
            }
        imshow("Label Tool", drawRect);
      }
    }
    

DISCLAIMER

Correct me if I am wrong but a glimpse into OpenCV High GUI shows that they do not provide a way of hiding created GUI elements. This means that the lastSelectedBtn->hidden = true logic part will have to be done at the OS level.