otx.api.usecases.exportable_code.streamer#

Initialization of streamer.

Functions

get_streamer([input_stream, loop, threaded])

Get streamer object based on the file path or camera device index provided.

Classes

CameraStreamer([camera_device])

Stream video frames from camera.

DirStreamer(input_path[, loop])

Stream from directory of images.

ImageStreamer(input_path[, loop])

Stream from image file.

ThreadedStreamer(streamer[, buffer_size])

Runs a BaseStreamer on a separate thread.

VideoStreamer(input_path[, loop])

Video Streamer.

BaseStreamer()

Base Streamer interface to implement Image, Video and Camera streamers.

Exceptions

InvalidInput(message)

Exception for wrong input format.

OpenError(message)

Exception for error opening reader.

exception otx.api.usecases.exportable_code.streamer.InvalidInput(message: str)[source]#

Bases: Exception

Exception for wrong input format.

exception otx.api.usecases.exportable_code.streamer.OpenError(message: str)[source]#

Bases: Exception

Exception for error opening reader.

class otx.api.usecases.exportable_code.streamer.BaseStreamer[source]#

Bases: object

Base Streamer interface to implement Image, Video and Camera streamers.

fps()[source]#

Returns a frequency of getting images from source.

abstract get_type() MediaType[source]#

Get type of streamer.

Returns:

type of streamer.

Return type:

MediaType

class otx.api.usecases.exportable_code.streamer.CameraStreamer(camera_device: int = 0)[source]#

Bases: BaseStreamer

Stream video frames from camera.

Parameters:

camera_device (int) – Camera device index e.g, 0, 1

Example

>>> streamer = CameraStreamer(camera_device=0)
... for frame in streamer:
...     cv2.imshow("Window", frame)
...     if ord("q") == cv2.waitKey(1):
...         break
get_type() MediaType[source]#

Returns the type of media.

class otx.api.usecases.exportable_code.streamer.DirStreamer(input_path: str, loop: bool = False)[source]#

Bases: BaseStreamer

Stream from directory of images.

Parameters:

path – Path to directory.

Example

>>> streamer = DirStreamer(path="../images")
... for frame in streamer:
...     cv2.imshow("Window", frame)
...     cv2.waitKey(0)
get_type() MediaType[source]#

Returns the type of the streamer.

class otx.api.usecases.exportable_code.streamer.ImageStreamer(input_path: str, loop: bool = False)[source]#

Bases: BaseStreamer

Stream from image file.

Parameters:
  • input_path (str) – Path to an image.

  • loop (bool) – Whether to loop through the image or not. Defaults to False.

Example

>>> streamer = ImageStreamer(path="../images")
... for frame in streamer:
...     cv2.imshow("Window", frame)
...     cv2.waitKey(0)
get_type() MediaType[source]#

Returns the type of the streamer.

class otx.api.usecases.exportable_code.streamer.ThreadedStreamer(streamer: BaseStreamer, buffer_size: int = 2)[source]#

Bases: BaseStreamer

Runs a BaseStreamer on a separate thread.

streamer (BaseStreamer): The streamer to run on a thread buffer_size (int): Number of frame to buffer internally. Defaults to 2.

Example

>>> streamer = VideoStreamer(path="../demo.mp4")
>>> threaded_streamer = ThreadedStreamer(streamer)
>>> for frame in threaded_streamer:
...    pass
get_type() MediaType[source]#

Get type of internal streamer.

Returns:

type of internal streamer.

Return type:

MediaType

class otx.api.usecases.exportable_code.streamer.VideoStreamer(input_path: str, loop: bool = False)[source]#

Bases: BaseStreamer

Video Streamer.

Parameters:

path – Path to the video file.

Example

>>> streamer = VideoStreamer(path="../demo.mp4")
... for frame in streamer:
...    pass
fps()[source]#

Returns a frequency of getting images from source.

get_type() MediaType[source]#

Returns the type of media.

otx.api.usecases.exportable_code.streamer.get_streamer(input_stream: int | str = 0, loop: bool = False, threaded: bool = False) BaseStreamer[source]#

Get streamer object based on the file path or camera device index provided.

Parameters:
  • input_stream (Union[int, str]) – Path to file or directory or index for camera.

  • loop (bool) – Enable reading the input in a loop. Defaults to False.

  • threaded (bool) – Run streaming on a separate thread. Threaded streaming option. Defaults to False.

Returns:

Streamer object.

Return type:

BaseStreamer