Ask Your Question
0

Should destroyAllWindows and release functions be used in Python?

asked 2020-02-02 05:22:43 -0600

hernancrespo gravatar image

Hi, i wrote a simple script to read frames from webcam

import cv2
cv2.destroyAllWindows()
capture = cv2.VideoCapture(0,cv2.CAP_DSHOW)
while (True):
    ret, frame = capture.read()
    cv2.imshow('video', frame)
    if cv2.waitKey(30) == 27:
        break
capture.release()
cv2.destroyAllWindows()

In this document, any many other codes i have seen, these two functions have used

capture.release()
cv2.destroyAllWindows()

but when i remove these two lines, code works without any problem. So, why we need these (in python) *

edit retag flag offensive close merge delete

Comments

1

2.4 doc is obsolete : don't use it. Today it is opencv 4.2 or opencv 3.4.9-dev

and you should destroy videocapture and windows before exiting your program

LBerger gravatar imageLBerger ( 2020-02-02 06:56:39 -0600 )edit
1

if you just run python my.py you probably don't have to (it's all cleaned up automatically).

but try to run it in a repl (and do something else then), or from demo.py, and you'll see, why it's there.

berak gravatar imageberak ( 2020-02-02 13:43:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-02-02 06:14:25 -0600

mvuori gravatar image

That document doesn't use either. When your program ends, the cleanup is done automatically. Those functions are useful in a called routine to setup environment and release unneeded resources for any processing that follows.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-02-02 05:22:43 -0600

Seen: 2,094 times

Last updated: Feb 02 '20