VideoStream

class CameraFailedToStart(cmd, backend, append='')

Bases: RuntimeError

Error when camera initialization fails.

class CameraConnectionLost

Bases: RuntimeError

Error for when the camera connection is not found after the connection has been established.

class WebcamVideoStream(cam=0)

Capture video frames from a webcam or CSI camera attached to your device.

WebcamVideoStream can be instantiated as a context manager:

with edgeiq.WebcamVideoStream() as video_stream:
    ...

To use WebcamVideoStream directly, use the start() and stop() functions:

video_stream = edgeiq.WebcamVideoStream().start()
...
video_stream.stop()

Typical usage:

with edgeiq.WebcamVideoStream() as video_stream:
    while True:
        frame = video_stream.read()
Parameters

cam (integer) – The integer identifier of the camera.

property fps

The FPS of the video stream.

Type

float

Raises

RuntimeError if FPS cannot be queried

read()

Return the most recent frame from the camera.

This function blocks on waiting for a new frame.

Returns

numpy array – The frame that was read from the camera

start()

Start reading frames from the video stream.

Returns

self

Raises

CameraFailedToStart if video stream fails to open

stop()

Stop and clean up the camera connection.

class GStreamerVideoStream(cam=0, display_width=640, display_height=480, framerate=30)

Capture video frames using the gstreamer plugin.

This can be useful for capturing videos from CSI cameras when V4L is not supported.

GStreamerVideoStream can be instantiated as a context manager:

with edgeiq.GStreamerVideoStream() as video_stream:
    ...

To use GStreamerVideoStream directly, use the start() and stop() functions:

video_stream = edgeiq.GStreamerVideoStream().start()
...
video_stream.stop()

Typical usage:

with edgeiq.GStreamerVideoStream() as video_stream:
    while True:
        frame = video_stream.read()
Parameters
  • cam (integer) – The integer identifier of the camera.

  • display_width (integer) – The output image width in pixels.

  • display_height (integer) – The output image height in pixels.

  • framerate (integer) – The recording frame rate.

property fps

The FPS of the video stream.

Type

float

Raises

RuntimeError if FPS cannot be queried

read()

Return the most recent frame from the camera.

This function blocks on waiting for a new frame.

Returns

numpy array – The frame that was read from the camera

start()

Start reading frames from the video stream.

Returns

self

Raises

CameraFailedToStart if video stream fails to open

stop()

Stop and clean up the camera connection.

class FrameRotation(value)

Amount of rotation applied to each frame in degrees

ROTATE_NONE = 0
ROTATE_90 = 90
ROTATE_180 = 180
class JetsonVideoStream(cam=0, rotation=<FrameRotation.ROTATE_NONE: 0>, capture_width=3264, capture_height=2464, display_width=640, display_height=480, framerate=21)

Capture video frames from a CSI ribbon camera on NVIDIA Jetson.

JetsonVideoStream can be instantiated as a context manager:

with edgeiq.JetsonVideoStream() as video_stream:
    ...

To use JetsonVideoStream directly, use the start() and stop() functions:

video_stream = edgeiq.JetsonVideoStream().start()
...
video_stream.stop()

Typical usage:

with edgeiq.JetsonVideoStream() as video_stream:
    while True:
        frame = video_stream.read()
Parameters
  • cam (integer) – The integer identifier of the camera.

  • rotation (FrameRotation) – The rotation applied to each frame

  • capture_width (integer) – The camera capture width in pixels.

  • capture_height (integer) – The camera capture height in pixels.

  • display_width (integer) – The output image width in pixels.

  • display_height (integer) – The output image height in pixels.

  • framerate (integer) – The recording frame rate.

property fps

The FPS of the video stream.

Type

float

Raises

RuntimeError if FPS cannot be queried

read()

Return the most recent frame from the camera.

This function blocks on waiting for a new frame.

Returns

numpy array – The frame that was read from the camera

start()

Start reading frames from the video stream.

Returns

self

Raises

CameraFailedToStart if video stream fails to open

stop()

Stop and clean up the camera connection.

class IPVideoStream(url)

Capture video frames from an IP stream.

IPVideoStream can be instantiated as a context manager:

with edgeiq.IPVideoStream('tcp://0.0.0.0:3333') as video_stream:
    ...

To use IPVideoStream directly, use the start() and stop() functions:

video_stream = edgeiq.IPVideoStream('tcp://0.0.0.0:3333').start()
...
video_stream.stop()

Typical usage:

with edgeiq.IPVideoStream('tcp://0.0.0.0:3333') as video_stream:
    while True:
        frame = video_stream.read()
Parameters

url (string) – The URL of the IP stream

property fps

The FPS of the video stream.

Type

float

Raises

RuntimeError if FPS cannot be queried

read()

Return the most recent frame from the camera.

This function blocks on waiting for a new frame.

Returns

numpy array – The frame that was read from the camera

start()

Start reading frames from the video stream.

Returns

self

Raises

CameraFailedToStart if video stream fails to open

stop()

Stop and clean up the camera connection.

class NoMoreFrames

Bases: RuntimeError

Error when trying to read more frames but no frames remaining to read.

class FileVideoStream(path, queue_size=128, play_realtime=False)

Stream a video file for analysis.

FileVideoStream can be instantiated as a context manager:

with edgeiq.FileVideoStream('/path/to/video.mp4') as video_stream:
    ...

To use FileVideoStream directly, use the start() and stop() functions:

video_stream = edgeiq.FileVideoStream('/path/to/video.mp4').start()
...
video_stream.stop()

Typical usage:

with edgeiq.FileVideoStream('/path/to/video.mp4') as video_stream:
    while video_stream.more():
        frame = video_stream.read()
Parameters
  • path (string) – The path of the video file location.

  • queue_size (integer) – The size of the buffer queue.

  • play_realtime (boolean) – If True play video in simulated realtime, where frames are dropped as they become outdated.

start()

Start reading frames from the video file.

When called a second time, will stop and restart.

Returns

self

Raises

RuntimeError when file doesn’t exist or video stream can’t be opened.

read()

Read the next frame from the file.

This function blocks on waiting for frames to become available.

Returns

numpy array – The next frame

Raises

NoMoreFrames if no frames left to read. RuntimeError if called before start().

more()

Check if there are more frames in the video file.

Returns

True if there are more frames to read in the video file.

Raises

RuntimeError if called before start().

stop()

Stop the FileVideoStream.