使用关闭“X"关闭视频窗口OpenCV、Python 中的按钮 [英] Closing video window using close "X" button in OpenCV, Python

查看:128
本文介绍了使用关闭“X"关闭视频窗口OpenCV、Python 中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 中的 OpenCV 显示来自摄像机的实时视频.这是代码:

I am displaying live video from a camera using OpenCV in Python. This is the code:

capture = cv.CaptureFromCAM(0)
if capture:
    cv.NamedWindow("Live Video", cv.CV_WINDOW_AUTOSIZE)
    frame = cv.QueryFrame(capture)
    if frame:
        cv.ShowImage("Live Video", frame)    
        cv.WaitKey(0)

cv.DestroyWindow("Live Video")

现在,我只能通过按esc"来关闭我的视频窗口,但是当我点击我窗口的关闭X"按钮时没有任何反应.有没有办法让它发挥作用?

Now, I can only close my video window by pressing "esc", but nothing happens when I click on my window's close "X" button. Is there a way to make that work?

推荐答案

OpenCV 没有这个功能,默认只处理按键操作.

OpenCV does not have this feature, and only handles key presses by default.

如果你想这样做,你必须使用创建你的窗口的窗口管理器的句柄(GTK、QT、...).

If you want to do this, you must use the handle of the window manager that creates your windows (GTK, QT, ...).

这篇文章描述了使用 Windows 时的类似问题.如果没有,请告诉我;)

This post describes a similar issue in case you use windows. Let me know if not ;)

这篇关于使用关闭“X"关闭视频窗口OpenCV、Python 中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆