Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing video window using close "X" button in OpenCV, Python

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

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?

like image 441
maupertius Avatar asked Nov 09 '12 11:11

maupertius


Video Answer


1 Answers

With the cv2 Python module there is a way to do that, I posted the solution here:

https://stackoverflow.com/a/37881722/2897426

This post is just for reference so anyone looking for it can find it

like image 170
Simon Hänisch Avatar answered Oct 21 '22 20:10

Simon Hänisch