-
Notifications
You must be signed in to change notification settings - Fork 0
Multithreaded video streaming
Tim Poulsen edited this page Feb 24, 2019
·
1 revision
Robovision offers efficient, multithreaded video camera streaming. One thread reads frames from the camera and puts them onto a queue. When you request a frame, another thread pulls it off the queue for you.
You must create an instance of the VideoStream class for each video source you'll read from. Then, you start() it, which starts the capture thread running. Pull frames as needed with read_frame(). When done, be sure to call stop() on the source to halt all threads.
import robovision as rv
# create your VideoStream instance, for example:
vs_webcam = rv.VideoStream(cam_id=0)
vs_ipcam = rv.VideoStream(source="ipcam", ipcam_url="http://10.15.18.101/mjpg/video.mjpg")
vs_picam = rv.VideoStream(source="picam")
vs_jetson = rv.VideoStream(source="jetson", resolution=(1920, 1080))
# or, use the shorthand notation for the IPCam or USB web cam
source = 0 # the integer identifying your webcam
vs = rv.get_video_stream(source)
# start the source, for example:
vs_webcam.start()
while True:
# retrieve a frame from the queue
frame = vs_webcam.read_frame()
# do stuff with the frame
# wait for Esc or q key and then exit
key = cv2.waitKey(1) & 0xFF
if key == 27 or key == ord("q"):
vs_webcam.stop()
break
© 2019 Tim Poulsen, library: MIT, docs: CC BY-SA 4.0