dLife Home Page

dlife.vision
Class Camera

java.lang.Object
  extended by java.util.Observable
      extended by dlife.robot.Device
          extended by dlife.vision.Camera
All Implemented Interfaces:
Observer
Direct Known Subclasses:
AiboCamera, ARDroneCamera, DLifeVisionServerCamera, FlukeCamera, HemissonCamera, ImageSequenceCamera, Khepera2Camera, PioneerCamera, SingleImageCamera

public class Camera
extends Device
implements Observer

Base class for creating cameras for different image sources. Users will typically interact with one of the Camera sub-classes defined in dlife.vision.cameras rather than with this class directly.

A Camera provides programmatic control for drawing on the video, controlling the play of the video, and adding and manipulating filters that are applied to the video. It also provides 2 GUI elements when added to a Robot. The Camera GUI displays the raw and filtered video and provides controls for playing/pausing/rewinding/etc and the Filters GUI provides a means for adding/editing/removing filters.

A Camera contains a VideoSource, a FilterManager and a VideoDisplay. Each of these objects can be controlled via its own methods. However, the Camera class contains convenience methods that allow the methods of those objects to be invoked from the Camera object. This is done so that code in a Controller need only interact with the Camera object.

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

Field Summary
static int BOTH_VIDEO
          Constant used by the drawing methods to indicate that the drawing command should be applied to both the raw and filtered video window.
static int FILTERED_VIDEO
          Constant used by the drawing methods to indicate that the drawing commands should be applied to the filtered video window.
static int RAW_VIDEO
          Constant used by the drawing methods to indicate that the drawing commands should be applied to the raw video window.
 
Fields inherited from class dlife.robot.Device
DEFAULT_GUI_UPDATE_DELAY, DEFAULT_READ_DELAY, myRobot, readCount
 
Constructor Summary
Camera(VideoSource src)
          Construct a new Camera that will control, process and display the video from the specified VideoSource.
Camera(VideoSource src, FilterManager mgr, VideoDisplay disp)
          Construct a new Camera using the specified VideoSource, FilterManger and VideoDisplay objects.
 
Method Summary
 void addFilter(Filter f)
          Add the Filter f to the FilterManager for this Camera.
 void clearDrawing(int window)
          Clears everything that has been drawn on the VideoDisplay associated with this Camera.
protected  DeviceDisplay[] createGUIObjects()
          Create the GUI for the Camera.
 void drawCircle(int window, int x, int y, int radius, Color color, boolean filled)
          Draw a circle overlaid on the VideoDisplay associated with this Camera.
 void drawLine(int window, int x1, int y1, int x2, int y2, Color color)
          Draw a line segment overlaid on the VideoDisplay associated with this Camera.
 void drawOval(int window, int x, int y, int width, int height, Color color, boolean filled)
          Draw an oval overlaid on the VideoDisplay associated with this Camera.
 void drawRectangle(int window, int x, int y, int width, int height, Color color, boolean filled)
          Draw a rectangle overlaid on the VideoDisplay associated with this Camera.
 void drawString(int window, String str, int x, int y, Color color)
          Draw a string of text overlaid on the VideoDisplay associated with this Camera.
 void freeze()
          Does nothing.
 FilterManager getFilterManager()
          Get the FilterManager associated with this Camera.
 ArrayList<Filter> getFilters()
          Get the current chain of Filters from the FilterManager associated with this Camera.
 int getHeight()
          Get the height, in pixels, of the video being displayed by this Camera.
 int getSeekLocation()
          Get the current seek location of this Camera.
 VideoDisplay getVideoDisplay()
          Get the VideoDisplay associated with this Camera.
 VideoSource getVideoSource()
          Get the VideoSource associated with this Camera.
 int getWidth()
          Get the width, in pixels, of the video being displayed by this Camera.
 void insertFilter(int index, Filter f)
          Insert the specified Filter at the specified index in the FilterManager associated with this Camera.
 void pause()
          Stops the VideoSource associated with this Camera.
 void play()
          Play the VideoSource associated with this Camera.
 void readStateFromRobot()
          Does nothing.
 void removeFilter(Filter f)
          Remove the specified Filter from the FilterManager associated with this Camera.
 void removeFilter(int index)
          Remove the Filter currently located at the specified index from the FilterManager for this Camera.
 void rewind()
          Rewind the VideoSource associated with this Camera.
 void seek(int location)
          Seek the VideoSource associated with this Camera to the specified location.
 void setFilters(ArrayList<Filter> newFilters)
          Replaces the current list of filters in the FilterManager associated with this Camera with the provided list of Filters.
 void shutDown()
          Shutdown the Camera.
 void startUp()
          Start up the Camera.
 void stepBackward()
          Step the VideoSource associated with this Camera back by one frame.
 void stepForward()
          Advance the VideoSource associated with this Camera by one frame.
 void update(Observable o, Object arg)
          The Camera will be notified each time a new image is available from the VideoSource.
 
Methods inherited from class dlife.robot.Device
getAutoRead, getGUI, getGUIUpdateDelay, getReadDelay, getRobot, getSensorReadCount, getSensorReadRate, setAutoRead, setGUIUpdateDelay, setReadDelay, setRobot, startAutoReadTimer, stopAutoReadTimer
 
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

RAW_VIDEO

public static int RAW_VIDEO
Constant used by the drawing methods to indicate that the drawing commands should be applied to the raw video window.


FILTERED_VIDEO

public static int FILTERED_VIDEO
Constant used by the drawing methods to indicate that the drawing commands should be applied to the filtered video window.


BOTH_VIDEO

public static int BOTH_VIDEO
Constant used by the drawing methods to indicate that the drawing command should be applied to both the raw and filtered video window.

Constructor Detail

Camera

public Camera(VideoSource src)
Construct a new Camera that will control, process and display the video from the specified VideoSource.

Parameters:
src - the VideoSource for this Camera.

Camera

public Camera(VideoSource src,
              FilterManager mgr,
              VideoDisplay disp)
Construct a new Camera using the specified VideoSource, FilterManger and VideoDisplay objects. This constructor handles the process of establishing the proper Observable/Observer relationships between these three components. This constructor is included primarily for testing purposes but may find other uses.

Parameters:
src - the VideoSource.
mgr - the FilterManager.
disp - the VideoDisplay.
Method Detail

startUp

public void startUp()
Start up the Camera. This includes connecting to the VideoSource, creating a new VideoDisplay and a new FilterManager and invoking play() on the VideoSource. Appropriate observer/observable relationships are also established among the VideoSource, VideoDisplay and FilterManager as well.

Overrides:
startUp in class Device

shutDown

public void shutDown()
Shutdown the Camera. This method invokes pause() followed by disconnect() on the VideoSource.

Overrides:
shutDown in class Device

freeze

public void freeze()
Does nothing.

Specified by:
freeze in class Device

readStateFromRobot

public void readStateFromRobot()
Does nothing.

Specified by:
readStateFromRobot in class Device

createGUIObjects

protected DeviceDisplay[] createGUIObjects()
Create the GUI for the Camera.

Specified by:
createGUIObjects in class Device
Returns:
a reference to the GUI.

getVideoSource

public VideoSource getVideoSource()
Get the VideoSource associated with this Camera.

Returns:
the VideoSource.

getFilterManager

public FilterManager getFilterManager()
Get the FilterManager associated with this Camera.

Returns:
the FilterManager.

getVideoDisplay

public VideoDisplay getVideoDisplay()
Get the VideoDisplay associated with this Camera.

Returns:
the VideoDisplay.

update

public void update(Observable o,
                   Object arg)
The Camera will be notified each time a new image is available from the VideoSource. The VideoSource also notifies its observers each time its state changes (e.g. play/pause/rewind etc...). The Camera is also notified each time the chain of filters changes or one of the individual filters changes.

When notified the Camera will get that image, pass it through the filter chain and then display both the raw and filtered images in the VideoDisplay.

Specified by:
update in interface Observer

play

public void play()
Play the VideoSource associated with this Camera. Note: Not all VideoSources support this operation.

See Also:
VideoSource.play()

pause

public void pause()
Stops the VideoSource associated with this Camera. Note: Not all VideoSources support this operation.

See Also:
VideoSource.pause()

rewind

public void rewind()
Rewind the VideoSource associated with this Camera. Note: Not all VideoSources support this operation.

See Also:
VideoSource.rewind()

stepForward

public void stepForward()
Advance the VideoSource associated with this Camera by one frame. Note: Not all VideoSources support this operation.

See Also:
VideoSource.stepForward()

stepBackward

public void stepBackward()
Step the VideoSource associated with this Camera back by one frame. Note: Not all VideoSources support this operation.

See Also:
VideoSource.stepBackward()

seek

public void seek(int location)
Seek the VideoSource associated with this Camera to the specified location. The location is specified as a percentage of the whole video from the start. E.g. a location of 25 is 1/4 of the way into the video. Note: Not all VideoSources support this operation.

Parameters:
location - the location to which to seek.
See Also:
VideoSource.seek(int location)

getSeekLocation

public int getSeekLocation()
Get the current seek location of this Camera. The location is specified as a percentage of the whole video from the start. E.g. a location of 25 is 1/4 of the way into the video.

Returns:
the current seek location or -1 if this Camera cannot seek.
See Also:
VideoSource.getSeekLocation()

getWidth

public int getWidth()
Get the width, in pixels, of the video being displayed by this Camera.

Returns:
the width of the video.
See Also:
VideoSource.getWidth()

getHeight

public int getHeight()
Get the height, in pixels, of the video being displayed by this Camera.

Returns:
the height of the video.
See Also:
VideoSource.getHeight()

addFilter

public void addFilter(Filter f)
Add the Filter f to the FilterManager for this Camera.

Parameters:
f - the filter to add.
See Also:
FilterManager.addFilter(Filter)

removeFilter

public void removeFilter(int index)
Remove the Filter currently located at the specified index from the FilterManager for this Camera. All of the Filters at higher indices are bumped down by one to fill the opening.

Parameters:
index - the index from which to remove the Filter.
See Also:
FilterManager.removeFilter(int)

removeFilter

public void removeFilter(Filter f)
Remove the specified Filter from the FilterManager associated with this Camera. The Filter f must be the same Filter object that was added to the FilterManager (i.e. == is used to find the matching Filter to remove). If more than one instance of the f have been added, only the first instance (lowest index) is removed.

Parameters:
f - the Filter to remove.
See Also:
FilterManager.removeFilter(Filter)

insertFilter

public void insertFilter(int index,
                         Filter f)
Insert the specified Filter at the specified index in the FilterManager associated with this Camera. All Filters at index and above are bumped up one to make room for the new Filter.

Parameters:
index - the index at which to insert f.
f - the Filter to insert.
See Also:
FilterManager.insertFilter(int, Filter)

getFilters

public ArrayList<Filter> getFilters()
Get the current chain of Filters from the FilterManager associated with this Camera. The ArrayList returned contains all of the Filters in the chain. The filter at the 0th index is the first in the chain and the filters are applied in order by increasing index.

The returned list of Filters is a shallow copy of the actual list maintained by the FilterManager. Thus, changing the behavior of the Filter objects in the returned list will change the filtering that is performed. However, changing the order or adding or removing filters from the list will have no effect on the filtering performed.

Returns:
the chain of Filters in an ArrayList.
See Also:
FilterManager.getFilters()

setFilters

public void setFilters(ArrayList<Filter> newFilters)
Replaces the current list of filters in the FilterManager associated with this Camera with the provided list of Filters. This method provide a convenient way to swap sets of filters to detect different objects in a stream. All Observers are notified of the change.

Parameters:
newFilters - the new set of filters to use.
See Also:
FilterManager.setFilters(ArrayList)

drawRectangle

public void drawRectangle(int window,
                          int x,
                          int y,
                          int width,
                          int height,
                          Color color,
                          boolean filled)
Draw a rectangle overlaid on the VideoDisplay associated with this Camera. Note that the rectangle is drawn overlaid on the video image and thus does not affect the actual image or interact with the filtering.

Parameters:
window - either RAW_VIDEO, FILTERED_VIDEO or BOTH_VIDEO indicating the window on which to draw the rectangle.
x - x coordinate of upper left corner of the rectangle.
y - y coordinate of the upper left corner of the rectangle.
width - width of the rectangle.
height - height of the rectangle.
color - color of the line (and fill) of the rectangle.
filled - true to fill in the rectangle.

drawOval

public void drawOval(int window,
                     int x,
                     int y,
                     int width,
                     int height,
                     Color color,
                     boolean filled)
Draw an oval overlaid on the VideoDisplay associated with this Camera. Note that the oval is drawn overlaid on the video image and thus does not affect the actual image or interact with the filtering.

Parameters:
window - either RAW_VIDEO, FILTERED_VIDEO or BOTH_VIDEO indicating the window on which to draw the oval.
x - x coordinate of the upper left corner of the oval's bounding box.
y - y coordinate of the upper right corner of the oval's bounding box.
width - width of the oval's bounding box.
height - height of the oval's bounding box.
color - color of the line (and fill) of the oval.
filled - true to fill in the oval.

drawCircle

public void drawCircle(int window,
                       int x,
                       int y,
                       int radius,
                       Color color,
                       boolean filled)
Draw a circle overlaid on the VideoDisplay associated with this Camera. This is just a convenience method that draws an appropriate oval on the overlay. Note that the circle is drawn overlaid on the video image and thus does not affect the actual image or interact with the filtering.

Parameters:
window - either RAW_VIDEO, FILTERED_VIDEO or BOTH_VIDEO indicating the window on which to draw the circle.
x - x coordinate of the center of the circle.
y - y coordinate of the center of the circle.
radius - radius of the circle.
color - color of the line (and fill) of the circle.
filled - true to fill the circle.

drawLine

public void drawLine(int window,
                     int x1,
                     int y1,
                     int x2,
                     int y2,
                     Color color)
Draw a line segment overlaid on the VideoDisplay associated with this Camera. Note that the line segment is drawn overlaid on the video image and thus does not affect the actual image or interact with the filtering.

Parameters:
window - either RAW_VIDEO, FILTERED_VIDEO or BOTH_VIDEO indicating the window on which to draw the line segment.
x1 - x coordinate of one end point of the line segment.
y1 - y coordinate of one end point of the line segment.
x2 - x coordinate of the other end point of the line segment.
y2 - y coordinate of the other end point of the line segment.
color - the color of the line.

drawString

public void drawString(int window,
                       String str,
                       int x,
                       int y,
                       Color color)
Draw a string of text overlaid on the VideoDisplay associated with this Camera. Note that the string is drawn overlaid on the video image and thus does not affect the actual image or interact with the filtering.

Parameters:
window - either RAW_VIDEO, FILTERED_VIDEO or BOTH_VIDEO indicating the window on which to draw the string.
str - the string to add.
x - x coordinate of the baseline of the first character.
y - y coordinate of the baseline of the first character.
color - the color of the text.

clearDrawing

public void clearDrawing(int window)
Clears everything that has been drawn on the VideoDisplay associated with this Camera.

Parameters:
window - either RAW_VIDEO, FILTERED_VIDEO or BOTH_VIDEO indicating which window should be cleared.

dLife Home Page