Package pyvision :: Package types :: Module Video :: Class VideoInterface
[hide private]
[frames] | no frames]

Class VideoInterface

source code

object --+
         |
        VideoInterface
Known Subclasses:

VideoInterface is an abstract class meant only to define a common interface for all Video subtypes. The VideoInterface defines the methods that every video data source should provide.

Instance Methods [hide private]
 
query(self)
Must be overridden to implement the specific frame-grabbing required by different video sources.
source code
 
grab(self)
This is a placeholder for the open cv webcam interface that sometimes requires this call.
source code
 
next(self)
The next method calls self.query(), so it is common to most video sources and may not need to be overridden.
source code
 
resize(self, frame)
Used to resize the source frame to the desired output size.
source code
 
__iter__(self)
Override to provide an appropriate iterator for your video source so that it can be used in a for loop as "for im in videoX: ..."
source code
 
play(self, window='Input', pos=None, delay=20, annotate=True, imageBuffer=None, startframe=0, endframe=None, onNewFrame=None, **kwargs)
Plays the video, calling the onNewFrame function after loading each frame from the video.
source code
 
_pauseAndPlay(self, delayObj={'current_state': 'PLAYING', 'wait_time': 20})
This function is intended to be used in the playback loop of a video.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

next(self)

source code 

The next method calls self.query(), so it is common to most video sources and may not need to be overridden.

Returns:
The next frame in the sequence, or raise StopIteration if done.

resize(self, frame)

source code 

Used to resize the source frame to the desired output size. This method is common to most sources and may not need to be overridden. The query() method will typically call this resize() method prior to returning the captured image.

Parameters:
  • frame - An openCV image (note: not a pyvision image)
Returns:
An openCV image with the new dimensions

play(self, window='Input', pos=None, delay=20, annotate=True, imageBuffer=None, startframe=0, endframe=None, onNewFrame=None, **kwargs)

source code 

Plays the video, calling the onNewFrame function after loading each
 frame from the video. The user may interrupt video playback by
 hitting (sometimes repeatedly) the spacebar, upon which they are
 given a text menu in the console to abort program, quit playback,
 continue playback, or step to the next frame.
@param window: The window name used to display the video. If None,
then the video won't be shown, but onNewFrame will be called at
each frame.
@param pos: A tuple (x,y) where the output window should be located
on the users screen. None indicates default openCV positioning algorithm
will be used.
@param delay: The delay in ms between window updates. This allows the user
to control the playback frame rate. A value of 0 indicates that the video
will wait for keyboard input prior to advancing to the next frame. This
delay is used by the pauseAndPlay interface, so it will affect the rate
at which onNewFrame is called as well.
@param annotate: If True, the image will be annotated with the frame number
in the upper left corner. Set false for no frame number annotation.
@param imageBuffer: An optional pyvision ImageBuffer object to contain the
most recent frames. This is useful if a buffer is required for background
subtraction, for example. The buffer contents is directly modified each
time a new image is captured from the video, and a reference to the buffer
is passed to the onNewFrame function (defined below).
@param startframe: If > 0, then the video will cue itself by quickly fast-forwarding
to the desired start frame before any images are shown. During the cueing process,
any _onNewFrame function callbacks (or VideoStreamProcessor objects) will NOT be
activated.
@param endframe: If not None, then the playback will end after this frame has
been processed.
@param onNewFrame: A python callable object (function) with a
signature of 'foo( pvImage, frameNum, key=None, buffer=None )', where key is
the key pressed by the user (if any) during the pauseAndPlay interface, and
buffer is a reference to the optional image buffer provided to the play method.
@param kwargs: Optional keyword arguments that should be passed
onto the onNewFrame function.
@return: The final frame number of the video, or the frame number at which
the user terminated playback using the 'q'uit option.

_pauseAndPlay(self, delayObj={'current_state': 'PLAYING', 'wait_time': 20})

source code 

This function is intended to be used in the playback loop of a video. It allows the user to interrupt the playback to pause the video, to step through it one frame at a time, and to register other keys/commands that the user may select.

Parameters:
  • delayObj - The "delay object", which is just a dictionary that specifies the wait_time (the delay in ms between frames), and the current_state of either 'PLAYING' or 'PAUSED'