As the title says. I was getting mouse events with opencv-python, ** When I tried to get right-click events, the menu was opened with the default function **. I've found that some people are doing well without doing anything, so the opencv version may be the cause.
--Environment
Ubuntu 18.04 LTS
opencv install with pip (maybe this is the cause)
--Date and time
2019/11/20
opencv 2.2 documentation »User interface stackoverflow/Why does a right click open a drop down menu in my OpenCV imshow() window?
According to **, right-clicking to open the menu seems to be a feature of this Qt backend **. So it seems that we need to get rid of this feature or use another backend. I'm not sure about the backend, and I don't need this feature, so I'll remove it.
[From the official document above]
--flags Window flags. The currently supported flags are: --CV_WINDOW_NORMAL or CV_WINDOW_AUTOSIZE: Specify CV_WINDOW_NORMAL to allow the user to change the window size. Conversely, if you specify CV_WINDOW_AUTOSIZE, the window size is automatically adjusted to fit the displayed image (see ShowImage), and the user cannot change the window size. --CV_WINDOW_FREERATIO or CV_WINDOW_KEEPRATIO: If CV_WINDOW_FREERATIO is specified, the image size will be adjusted without maintaining the aspect ratio, and conversely, if CV_WINDOW_KEEPRATIO is specified, the aspect ratio will be adjusted. --CV_GUI_NORMAL or CV_GUI_EXPANDED: CV_GUI_NORMAL allows you to display the previous window without the status bar and toolbar. Conversely, if you specify CV_GUI_EXPANDED, a new enhanced GUI will be displayed.
Apparently, you can do this by specifying the flags argument of cv2.namedWindow
.
cv2.namedWindow("hoge", CV_GUI_NORMAL)
cv2.namedWindow("hoge", cv2.CV_GUI_NORMAL)
cv2.namedWindow("hoge", cv.CV_GUI_NORMAL)
I wonder why ...
stackoverflow / NameError: global name'CV_GUI_NORMAL' is not defined Value is written, ...
WINDOW_AUTOSIZE = 1
WINDOW_FREERATIO = 256
WINDOW_FULLSCREEN = 1
WINDOW_GUI_EXPANDED = 0
WINDOW_GUI_NORMAL = 16
WINDOW_KEEPRATIO = 0
WINDOW_NORMAL = 0
WINDOW_OPENGL = 4096
WND_PROP_ASPECT_RATIO = 2
WND_PROP_AUTOSIZE = 1
WND_PROP_FULLSCREEN = 0
WND_PROP_OPENGL = 3
WND_PROP_VISIBLE = 4
Since WINDOW_GUI_NORMAL = 16
, ...
cv2.namedWindow("hoge", 16)
The above numbers are described in detail in High-level GUI.
Recommended Posts