Skip to contents

A Queue object contains a self-filling, asynchronous queue of images retrieved from a Video or Stream object. Retrieving an image from a video or camera stream is generally fast but it still comes with a time penalty that can become significant when processing large numbers of images and/or videos. A Queue object can help save some of that lost time by reading and storing images from a video or stream in parallel of the main R thread, for instance while other operations are being performed by R on previously read images. These pre-loaded frames are, therefore, immediately available when needed, effectively eliminating the wait time between two frame reads (as long as the queue reads and stores new frames faster than R can process them).

Function for creating Queue objects for Video and Stream objects.

Usage

queue(x, size = 10, delay = 1000, overflow = "pause")

Arguments

x

Either a Video or a Stream object.

size

The number of frames that the Queue object can store (default: 10). This number is fixed if overflow is set to "pause" or "replace". This number may increase if overflow is set to "grow" and the queue becomes full.

delay

Time in microseconds between two queue updates (default: 1000). Increasing the delay will slow down the speed at which the queue fills up. Decreasing it will fill up the queue faster but will use up more processing resources.

overflow

A character string indicating what the Queue object should do when it is full. Three methods are available:

"pause":

the queue will stop retrieving and storing new frames until a frame is read by the user.

"replace":

the oldest frame in the queue is discarded to make space for a new frame.

"grow":

the size of the queue is doubled every time it fills up. This should be used with extreme caution as it can lead to excessive memory usage.

Value

A Queue object.

Slots

dim,ncol,nrow

Functions returning the dimensions of the frames in the queue.

length

Function returning the number of frames in the queue.

capacity

Function returning the maximum number of frames that the queue can hold at any one time.

frame

Function returning the index of the frame to be read next.

full,empty

Function returning the state of the queue (full or empty or neither).

readNext

Function to access the next frame in the queue.

reset

Function to empty the queue and start collecting new frames.

See also

queue, Video, Stream

Author

Simon Garnier, garnier@njit.edu

Examples

balloon <- video(system.file("sample_vid/Balloon.mp4", package = "Rvision"))
#> Error: Could not open the video.
buf <- queue(balloon)
#> Error in eval(expr, envir, enclos): object 'balloon' not found