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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix backwards compatability
karjanme committed Mar 25, 2020
commit 5a9e73b8b68419c5369b2f7a249639122c1a4637
8 changes: 3 additions & 5 deletions imutils/video/videostream.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

class VideoStream:
def __init__(self, src=0, usePiCamera=False, resolution=(320, 240),
framerate=32, **kwargs, cap=None):
framerate=32, **kwargs):
# check to see if the picamera module should be used
if usePiCamera:
# only import the picamera packages unless we are
@@ -17,11 +17,9 @@ def __init__(self, src=0, usePiCamera=False, resolution=(320, 240),
self.stream = PiVideoStream(resolution=resolution,
framerate=framerate, **kwargs)

# otherwise, we are using OpenCV so initialize the webcam
# stream
# otherwise, we are using OpenCV so initialize the webcam stream
else:
self.stream = WebcamVideoStream(src=src, cap=cap,
resolution=resolution)
self.stream = WebcamVideoStream(src=src, resolution=resolution)

def start(self):
# start the threaded video stream
13 changes: 7 additions & 6 deletions imutils/video/webcamvideostream.py
Original file line number Diff line number Diff line change
@@ -3,15 +3,16 @@
import cv2

class WebcamVideoStream:
def __init__(self, src=0, cap=None, resolution=(320, 240),
name="WebcamVideoStream"):
# initialize the video camera stream and read the first frame
# from the stream
self.stream = cap
if cap is None:
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