dLife Home Page

dlife.vision.cameras.sources
Class ImageSequenceVideoSource

java.lang.Object
  extended by java.util.Observable
      extended by dlife.vision.VideoSource
          extended by dlife.vision.cameras.sources.ImageSequenceVideoSource

public class ImageSequenceVideoSource
extends VideoSource

An ImageSequenceVideoSource presents all of the images in a specified directory in lexicographical order as a VideoSource. The easiest way to sequence the images in a directory is to prefix their names with a 0-padded numeral (e.g. 001ball.jpg, 002ball.jpg etc...).

Ideally all images in the specified directory are the same size. However, if there are images of different sizes, the width and height of the video for this ImageSequenceVideoSource will be determined by the width and height of the largest image.

Version:
Jun 28, 2009
Author:
Grant Braught, Dickinson College

Field Summary
static int DEFAULT_FRAME_RATE
          Default frame rate for an ImageSequenceVideoSource in frames/second.
 
Fields inherited from class dlife.vision.VideoSource
loop
 
Constructor Summary
ImageSequenceVideoSource()
          Construct a new ImageSequenceVideoSource by allowing the user to select a directory of files using a file chooser dialog.
ImageSequenceVideoSource(String directory)
          Construct a new ImageVideoSequence using all of the image files contained in the specified directory.
 
Method Summary
 boolean canLoop()
          An ImageSequenceVideoSource can be looped.
 boolean canPause()
          An ImageSequenceVideoSource can be paused when it is playing.
 boolean canPlay()
          An ImageSequenceVideoSource can be played any time that it is not currently playing if it is looping.
 boolean canRewind()
          An ImageSequenceVideoSource can be rewound if is not playing and it is not already at the first frame.
 boolean canSeek()
          An ImageSequenceVideoSource can seek any time that it is not playing.
 boolean canStepBackward()
          An ImageSequenceVideoSource can step backward if it is not playing and it is not already at the start.
 boolean canStepForward()
          An ImageSequenceVideoSource can step forward if it is not playing and it is not already at the end.
 void connect()
          Read the images from the files and setup the initial state of the ImageSequenceVideoSource.
 void disconnect()
          Disconnect from the ImageSequenceVideoSource.
 int getCurrentFrame()
          Return the current frame (i.e.
 int getFrameCount()
          Get the number of frames in this ImageSequenceVideoSource.
 int getFrameRate()
          Get the current frame rate for this ImageSequenceVideoSource.
 VideoSourceGUI getGUI()
          Get the GUI for this ImageSequenceVideoSource.
 int getHeight()
          Get the height of the video for this ImageSequenceVideoSource.
 int getSeekLocation()
          Return the current seek location of this ImageSequenceVideoSource.
 BufferedImage getVideoFrame()
          Get the image representing the current frame of video.
 int getWidth()
          Get the width of the video for this ImageSequenceVideoSource.
static void main(String[] args)
          Little test method that creates and displays a Camera (and all of the GUI parts) using an ImageSequenceVideoSource as the video source.
 void pause()
          Pause the video.
 void play()
          Play the video.
 void rewind()
          Rewind the video to the first frame and seek location 0.
 void seek(int location)
          Seek this video to the specified location.
 void setFrameRate(int fps)
          Change the frame rate for this ImageSequenceVideoSource.
 void stepBackward()
          Step the video backward by one frame.
 void stepForward()
          Step the video forward by one frame.
 
Methods inherited from class dlife.vision.VideoSource
isLooping, setLoop
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FRAME_RATE

public static final int DEFAULT_FRAME_RATE
Default frame rate for an ImageSequenceVideoSource in frames/second.

See Also:
Constant Field Values
Constructor Detail

ImageSequenceVideoSource

public ImageSequenceVideoSource()
                         throws VideoSourceCreationFailedException
Construct a new ImageSequenceVideoSource by allowing the user to select a directory of files using a file chooser dialog.

Throws:
VideoSourceCreationFailedException - if user cancels the creation.

ImageSequenceVideoSource

public ImageSequenceVideoSource(String directory)
                         throws VideoSourceCreationFailedException
Construct a new ImageVideoSequence using all of the image files contained in the specified directory.

Parameters:
directory - the absolute path to the directory containing the image files to be used.
Throws:
VideoSourceCreationFailedException - if the specified directory cannot be found.
Method Detail

connect

public void connect()
             throws VideoSourceConnectionException
Read the images from the files and setup the initial state of the ImageSequenceVideoSource.

Specified by:
connect in class VideoSource
Throws:
VideoSourceConnectionException - if any of the files cannot be read.

disconnect

public void disconnect()
Disconnect from the ImageSequenceVideoSource. This method does nothing.

Specified by:
disconnect in class VideoSource

getGUI

public VideoSourceGUI getGUI()
Get the GUI for this ImageSequenceVideoSource. The GUI will be a VideoPlayerGUI that has a seek bar, buttons for rewind, step back, step forward, play and also a loop control.

Specified by:
getGUI in class VideoSource
Returns:
a VideoPlayerGUI for controlling the VideoSource.

setFrameRate

public void setFrameRate(int fps)
Change the frame rate for this ImageSequenceVideoSource.

Parameters:
fps - number of frames per second to display.

getFrameRate

public int getFrameRate()
Get the current frame rate for this ImageSequenceVideoSource.

Returns:
the current frame rate in frames per second (fps).

getFrameCount

public int getFrameCount()
Get the number of frames in this ImageSequenceVideoSource.

Returns:
the number of frames or 0 if this ImageSequenceVideoSource has not been connected.

getWidth

public int getWidth()
Get the width of the video for this ImageSequenceVideoSource. The width of the video is set to be the width of the widest image.

Specified by:
getWidth in class VideoSource
Returns:
the width of the video or -1 if this ImageSequenceVideoSource has not been connected.

getHeight

public int getHeight()
Get the height of the video for this ImageSequenceVideoSource. The height of the video is set to be the height of the tallest image.

Specified by:
getHeight in class VideoSource
Returns:
the height of the video or -1 if this ImageSequenceVideoSource has not been connected.

canLoop

public boolean canLoop()
An ImageSequenceVideoSource can be looped.

Specified by:
canLoop in class VideoSource
Returns:
true

canPause

public boolean canPause()
An ImageSequenceVideoSource can be paused when it is playing.

Specified by:
canPause in class VideoSource
Returns:
true if the video can currently be paused.

canPlay

public boolean canPlay()
An ImageSequenceVideoSource can be played any time that it is not currently playing if it is looping. If it is not looping then it can be played any time it is not playing and not on the last frame.

Specified by:
canPlay in class VideoSource
Returns:
true if the video can currently be played.

canRewind

public boolean canRewind()
An ImageSequenceVideoSource can be rewound if is not playing and it is not already at the first frame.

Specified by:
canRewind in class VideoSource
Returns:
true if the video can currently be rewound.

canSeek

public boolean canSeek()
An ImageSequenceVideoSource can seek any time that it is not playing.

Specified by:
canSeek in class VideoSource
Returns:
true if the video can currently be seeked.

canStepBackward

public boolean canStepBackward()
An ImageSequenceVideoSource can step backward if it is not playing and it is not already at the start.

Specified by:
canStepBackward in class VideoSource
Returns:
true if the video can currently be stepped backward.

canStepForward

public boolean canStepForward()
An ImageSequenceVideoSource can step forward if it is not playing and it is not already at the end.

Specified by:
canStepForward in class VideoSource
Returns:
true if the video can currently be stepped forward.

getSeekLocation

public int getSeekLocation()
Return the current seek location of this ImageSequenceVideoSource.

Specified by:
getSeekLocation in class VideoSource
Returns:
the seek location.

getCurrentFrame

public int getCurrentFrame()
Return the current frame (i.e. image number) of the video.

Returns:
the frame number.

seek

public void seek(int location)
Seek this video to the specified location. If the video cannot currently be seeked then the seek location is not changed. If the value of location is not in the range [0...100] it will be set to the closest value in that range.

Specified by:
seek in class VideoSource
Parameters:
location - the new seek location.

stepForward

public void stepForward()
Step the video forward by one frame. If the video cannot currently be stepped forward then this method has no effect.

Specified by:
stepForward in class VideoSource

stepBackward

public void stepBackward()
Step the video backward by one frame. If the video cannot currently be stepped backward then this method has no effect.

Specified by:
stepBackward in class VideoSource

rewind

public void rewind()
Rewind the video to the first frame and seek location 0. If the video cannot currently be rewound then this method has no effect.

Specified by:
rewind in class VideoSource

pause

public void pause()
Pause the video. If the video cannot currently be paused then this method has no effect.

Specified by:
pause in class VideoSource

play

public void play()
Play the video. If the video cannot currently be played then this method has no effect.

Specified by:
play in class VideoSource

getVideoFrame

public BufferedImage getVideoFrame()
Get the image representing the current frame of video.

Specified by:
getVideoFrame in class VideoSource
Returns:
the current frame.

main

public static void main(String[] args)
Little test method that creates and displays a Camera (and all of the GUI parts) using an ImageSequenceVideoSource as the video source. The user is asked to select a directory containing the images to use.

Parameters:
args - none

dLife Home Page