videostream2py
stream2py interface to video.
Read frames from a video file or a camera device as a stream2py source.
The package’s entry point is VideoCapture, a
stream2py.SourceReader backed by OpenCV’s cv2.VideoCapture:
>>> from videostream2py import VideoCapture
>>> VideoCapture.__name__
'VideoCapture'
>>> with VideoCapture(video_input=0) as cap:
... timestamp, ret, frame = cap.read()
The re-export is lazy (PEP 562): a plain import videostream2py never imports
OpenCV. Anything that actually materialises an exported name does – not only
from videostream2py import VideoCapture but also import *, hasattr,
inspect.getmembers() and help(). So on a host where import cv2
itself fails – Linux without libGL.so.1 – importing this package still
works, while introspecting it raises that ImportError.
- class videostream2py.VideoCapture(video_input: str | int = 0)[source]
Video Capture using OpenCV
- close() None[source]
Close and clean up source reader. Will be called when StreamBuffer stops or if an exception is raised during read and append loop.
- property info: dict
A dict with important source info. Default can be init_kwargs and open timestamp.
This info will be available in BufferReader after SourceReader has opened but any changes made between open and close are not guaranteed to be visible. Any continuous status updates should be included with read data instead.
- Returns:
dict
- open() None[source]
Set up source to be read and set some source info affected by open time like the time of open. Will be called in StreamBuffer immediately before first read.