How to make buttons in OpenCV 3.1 using cv2.createButton?
Solution 1
The documentation says
Another important application of trackbar is to use it as a button or switch. OpenCV, by default, doesn’t have button functionality. So you can use trackbar to get such functionality (found at Trackbar as the Color Palette).
There is a small example how to use it as button.
Solution 2
cv2.namedWindow("Frame")
cv2.createButton("Back",back,None,cv2.QT_PUSH_BUTTON,1)
def back(*args):
pass
The above code shows how to implement the cv2.createButton() method.
Notes:
- "Back" = text displayed on the button
- back = function called when the button is pressed
- the cv2 window must be created before the button
- if your button is not appearing: click inside the frame, press ctrl+p or command+p (for mac) and the button menu should appear
Admin
Updated on June 17, 2022Comments
-
Admin almost 2 years
I'm trying to add a button to my image processing script to save the high and low HSV values for my binary threshold.
According to the OpenCV 3.0 documentation here, OpenCV evidently has a function which does that.
I am writing the function like this
cv2.createButton('Button',f)
WhereButton
is the name of the button andf
is the callback function (just an empty function)However I keep on getting:-
AttributeError: 'module' object has no attribute 'createButton'
Apparently the same function works fine with C/C++ but it isn't working with python. Most probably because it isn't there for python (maybe) ?
How do I get around this problem?
-
ppasler over 6 years@DuncanWhyte indeed, but as I see it, it is the closest thing to OP's question.
-
edison over 3 yearsIt works to create a button in a pop-up named "Python settings" that is launched from an invisible button set (10) on top of the frame.
-
edison over 3 yearsBTW I'm using opencv-python v4.4.0
-
Ramtin Nouri about 3 yearsIt is possible. You have to compile OpenCV yourself and make sure to enable QT support
-
mins about 3 yearsSo what is the reason AttributeError: 'module' object has no attribute 'createButton' does appear? cv2 has indeed a function createButton, even if as of today the documentation doesn't show the correct parameter names.
-
ArduinoBen about 2 yearshmm why do we need ctrl+p>