Table of Contents

image_stream

`image_stream` represents a changing image source. It can receive frames from `image_data`, play an image sequence from a folder, or play an MJPEG AVI file. The GUI `image` object can display an `image_stream`.

`image_stream` is not cloneable because it represents active playback/source state.

Constructor

image_stream()

Creates an empty stream.

stream = image_stream();
print(stream.has_frame);     // false

Properties

Property Type Description
`has_frame` boolean `true` when the stream has at least one frame.
`sequence` number Internal frame sequence counter.
`fps` number Playback frames per second.
`loop` boolean Playback loop state.
`frame_count` number Number of frames in the active player.
`next_frame` number Next frame index in the active player.
`running` boolean `true` when the active player is running.

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

`clone()` is not supported for `image_stream`.


Methods

clear()

Stops and clears any active player, clears the stream, and returns the stream object.

Item Description
Syntax `image_stream.clear()`
Arguments none
Returns image_stream object

Example:

stream.clear();

push(image)

Pushes one `image_data` frame into the stream.

Argument Type Description
`image` image_data Image frame to push.

Returns: `true` if the frame was pushed, or `false` if the image is not valid.

Example:

img = image_data().load("frame.png");
stream = image_stream();
ok = stream.push(img);

load_folder(folder)

Loads a folder as an image sequence using the default filter `*.jpg`.

Argument Type Description
`folder` string Folder containing image frames.

Returns: boolean-style number.

Example:

stream = image_stream();
stream.load_folder("frames");

load_folder(folder, filter)

Loads a folder as an image sequence using a file filter such as `*.png` or `frame_*.jpg`.

Argument Type Description
`folder` string Folder containing image frames.
`filter` string File filter such as `*.png` or `frame_*.jpg`.

Returns: boolean-style number.

Example:

stream = image_stream();
stream.load_folder("frames", "*.png");
stream.fps(10).loop(true).start();

load_avi(filePath)

Loads an MJPEG AVI file as the active player.

Argument Type Description
`filePath` string AVI file path.

Returns: boolean-style number.

Example:

stream = image_stream();
if (stream.load_avi("capture.avi"))
{
    stream.start();
}

fps(value)

Sets playback speed in frames per second.

Argument Type Description
`value` number Playback speed in frames per second.

Returns: image_stream object.

Example:

stream.fps(25);

loop(enabled)

Enables or disables looping.

Argument Type Description
`enabled` boolean Loop state.

Returns: image_stream object.

Example:

stream.loop(false);

start()

Starts the active player.

Item Description
Syntax `image_stream.start()`
Arguments none
Returns boolean-style number

If no folder or AVI player is active, it returns `false`.

Example:

stream.load_folder("frames", "*.jpg");
stream.start();

stop()

Stops playback.

Item Description
Syntax `image_stream.stop()`
Arguments none
Returns boolean-style number

Example:

stream.stop();

Displaying a Stream

Use the GUI `image` object to show an image stream.

stream = image_stream().load_folder("frames", "*.jpg");
view = image().position(10, 10).size(320, 240).load(stream).play();
window().title("Stream").size(360, 300).add(view).show();

Previous: image_data

Next: Utils