Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to WebcamVideoStream (VideoCapture Properties and Release) #177

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion imutils/video/videostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, src=0, usePiCamera=False, resolution=(320, 240),
# otherwise, we are using OpenCV so initialize the webcam
# stream
else:
self.stream = WebcamVideoStream(src=src)
self.stream = WebcamVideoStream(src=src, resolution=resolution)

def start(self):
# start the threaded video stream
Expand Down
15 changes: 11 additions & 4 deletions imutils/video/webcamvideostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import cv2

class WebcamVideoStream:
def __init__(self, src=0, name="WebcamVideoStream"):
# initialize the video camera stream and read the first frame
# from the stream
self.stream = cv2.VideoCapture(src)
def __init__(self, src=0, resolution=(320, 240), name="WebcamVideoStream"):
# initialize the video camera stream
if isinstance(src, int):
self.stream = cv2.VideoCapture(src)
self.stream.set(3, int(resolution[0])) # cv2.CAP_PROP_FRAME_WIDTH
self.stream.set(4, int(resolution[1])) # cv2.CAP_PROP_FRAME_HEIGHT
else:
self.stream = src

# read the first frame from the stream
(self.grabbed, self.frame) = self.stream.read()

# initialize the thread name
Expand Down Expand Up @@ -38,5 +44,6 @@ def read(self):
return self.frame

def stop(self):
self.stream.release()
# indicate that the thread should be stopped
self.stopped = True