Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a right click open a drop down menu in my OpenCV imshow() window?

I am trying to run the OpenCV Grabcut Sample on my system:

  • OpenCV version 4.1.0
  • Python version 3.6.8
  • IDLE version 3.6.8
  • Ubuntu 18.04.2

This is the build information from cv2.getBuildInformation(): build information

In the Grabcut Sample script, I need to 'draw a rectangle around the object using the right mouse button.' For some reason, a drop down menu appears when I click the right mouse button (this is me clicking and holding the right mouse button):

drop down

This didn't happen before, but since I reformatted my computer and reinstalled OpenCV I get this drop down menu. The imshow window looks different too. I tried installing lots of video codec packages (from this tutorial), but that didn't help.

This drop down menu interferes with the mouse callback functions. How can I get rid of this drop down menu?

I installed OpenCV with the command pip3 install opencv-contrib-python. I knew I was missing some packages so I tried to install (but failed - 'couldn't find any package by regex...') these packages from this tutorial:

sudo apt-get install python-devel numpy
sudo apt-get install gcc gcc-c++
sudo apt-get install gtk2-devel
sudo apt-get install ffmpeg-devel
sudo apt-get install gstreamer-plugins-base-devel
like image 367
Stephen Meschke Avatar asked Oct 20 '25 03:10

Stephen Meschke


1 Answers

In Python, you can pass the cv2.WINDOW_GUI_NORMAL flag to namedWindow() to disable the dropdown (flag is supported only if you have Qt backend):

cv2.namedWindow("window_name", cv2.WINDOW_GUI_NORMAL)

And then call

cv2.imshow("window_name", img)

Link to documentation of the namedWindow function is here.

like image 87
Kashinath Patekar Avatar answered Oct 21 '25 16:10

Kashinath Patekar