Skip to content

Release webcamera stream#81

Open
leonidwang wants to merge 2 commits intoPyImageSearch:masterfrom
leonidwang:master
Open

Release webcamera stream#81
leonidwang wants to merge 2 commits intoPyImageSearch:masterfrom
leonidwang:master

Conversation

@leonidwang
Copy link

WebcamVideoStream initialized stream from cv2.VideoCapture but didn't release it in stop().

@jrosebr1
Copy link
Contributor

Releasing the cv2.VideoCapture pointer should be performed in your main thread. An example of which can be found here:

https://www.pyimagesearch.com/2018/08/13/opencv-people-counter/

@leonidwang
Copy link
Author

Nice example on people counter! :)

However, I still think WebcamVideoStream shall release camera.
People call vs.start() / vs.stop() as a pair, it's unusual to ask people to release camera by manually calling vs.stream.release(), people shouldn't even be aware of vs.stream if it's been wrapped by WebcamVideoStream.

See the snippet below, we shall eliminate manual reference and release of vs.stream, right?

In [1]: from imutils.video import WebcamVideoStream

In [2]: vs = WebcamVideoStream(src=0)
   ...: vs.start()
   ...:
   ...:
Out[2]: <imutils.video.webcamvideostream.WebcamVideoStream at 0x1c42477d470>

In [3]: cap = vs.stream

In [4]: vs.stop()

In [5]: cap.isOpened()
Out[5]: True

In [6]: cap.release()

In [7]: cap.isOpened()
Out[7]: False

@liquiddandruff
Copy link

liquiddandruff commented Dec 15, 2019

I agree that having vs.stream.release() called automatically from vs.stop() should be the default, expected behavior.

Copy link

@Abik1111 Abik1111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this technique worked for me, the previous vs.stop() didn't work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants