OpenCV showing extra windows with black bar?

人走茶凉 提交于 2021-02-05 11:54:20

问题


I am working with OpenCV on Python and just from yesterday I encountered a very weird problem.

When I call a very simple method, imshow(), the program always spawn additional windows which has the same name as the main one and a black bar at the central.

Sometime, there is no extra window called, while sometime there are like 50 or 100 windows spawns in forever loop.

It is very strange and I encountered it since yesterday, when I uninstalled the opencv-python library and downloaded opencv-contrib-python. The first time I had this problem, the console log also gave me warning about the lack of GTK-Cambera module

Gtk-Message: Failed to load module "canberra-gtk-module"

However, I did try to fix it and download libraries on Ubuntu so that the warning is gone now. Furthermore, I try to reverse the opencv library by remove opencv-contrib-python and reuse opencv-python instead. Unfortunately, the problem still occurs.

In addition, I have a feeling that the more power the programs need, the more chance the "additional window" will appear.

The code I implemented:

import numpy as np
import cv2

cap = cv2.VideoCapture(4)

while(cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Here is the image of the error:

Error showing


回答1:


I don't have enough reputation to comment, but are you using opencv 4.3 by any chance? I had the same problem, so I just downgraded to 4.2.



来源:https://stackoverflow.com/questions/63223020/opencv-showing-extra-windows-with-black-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!