显示带有黑条的额外窗口

显示带有黑条的额外窗口

本文介绍了OpenCV 显示带有黑条的额外窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Python 上使用 OpenCV,就在昨天我遇到了一个非常奇怪的问题.

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

当我调用一个非常简单的方法 imshow() 时,程序总是会生成额外的窗口,这些窗口与主窗口同名,中间有一个黑条.

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.

有时,不会调用额外的窗口,而有时会在永久循环中生成 50 或 100 个窗口.

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

很奇怪,从昨天开始,卸载opencv-python库,下载opencv-contrib-python时就遇到了.第一次遇到这个问题,控制台日志也给了我缺少GTK-Cambera模块的警告

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"

但是,我确实尝试修复它并在 Ubuntu 上下载库,以便警告现在消失了.此外,我尝试通过删除 opencv-contrib-python 并重用 opencv-python 来反转 opencv 库.不幸的是,问题仍然存在.

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.

我实现的代码:

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()

这是错误的图像:

推荐答案

我没有足够的声誉来发表评论,但您是否有机会使用 opencv 4.3?我遇到了同样的问题,所以我只是降级到 4.2.

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.

这篇关于OpenCV 显示带有黑条的额外窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:38