ca.mcgill.cim.sre.cv4hci
Class VideoCapture

java.lang.Object
  extended by ca.mcgill.cim.sre.cv4hci.VideoCapture
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable

public class VideoCapture
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

VideoCapture is a wrapper class for the HighGUI capture API of OpenCV. It comes with a few additional features, such as a maximum width for captured images and an automatic shrinking of captured images that are larger than this maximum. It can also flip images, effectively rotating the camera 180 degrees. It also keeps in memory a status of its performance in frames per second (FPS). One can serialize it as well to keep capture source information such as the camera number and the video filename.

The run() method is used to grab images, and notifications are sent to objects who have registered with the StateMonitor. Use an instance of this class as a parameter to a Thread object. The capture will then take place automatically on another thread.

Since:
1.0
See Also:
Serialized Form

Constructor Summary
VideoCapture(java.io.File videoFile)
          VideoCapture constructor specifiying the video file to capture from.
VideoCapture(java.io.File videoFile, int maximumWidth)
          VideoCapture constructor specifiying the video file to capture from and the maximum width of captured images.
VideoCapture(int cameraNumber)
          VideoCapture constructor specifiying the camera number to capture from.
VideoCapture(int cameraNumber, int maximumWidth)
          VideoCapture constructor specifiying the camera number to capture from and the maximum width of captured images.
VideoCapture(java.lang.String videoFile)
          VideoCapture constructor specifiying the video filename to capture from.
VideoCapture(java.lang.String videoFile, int maximumWidth)
          VideoCapture constructor specifiying the video filename to capture from and the maximum width of captured images.
 
Method Summary
 int getCameraNumber()
          Gets the camera number this object was constructed with.
 double getFPS()
          Gets the current performance of the capture in frames per second.
 java.util.Observable getStateMonitor()
          Gets the StateMonitor (an Observable object) with which other objects implementing the Observer interface can register with.
 java.lang.String getVideoFile()
          Gets the video filename we are capturing from.
 boolean isFlip()
          Gets the flip (like a 180 degree rotation) property of this object.
 void run()
          Runs the capture in an internal loop.
 void setFlip(boolean doFlip)
          Sets the flip (like a 180 degree rotation) property of this object.
 void stop()
          Stops the capture loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VideoCapture

public VideoCapture(int cameraNumber)
VideoCapture constructor specifiying the camera number to capture from.


VideoCapture

public VideoCapture(java.lang.String videoFile)
VideoCapture constructor specifiying the video filename to capture from.


VideoCapture

public VideoCapture(java.io.File videoFile)
VideoCapture constructor specifiying the video file to capture from.


VideoCapture

public VideoCapture(int cameraNumber,
                    int maximumWidth)
VideoCapture constructor specifiying the camera number to capture from and the maximum width of captured images.


VideoCapture

public VideoCapture(java.lang.String videoFile,
                    int maximumWidth)
VideoCapture constructor specifiying the video filename to capture from and the maximum width of captured images.


VideoCapture

public VideoCapture(java.io.File videoFile,
                    int maximumWidth)
VideoCapture constructor specifiying the video file to capture from and the maximum width of captured images.

Method Detail

setFlip

public void setFlip(boolean doFlip)
Sets the flip (like a 180 degree rotation) property of this object. All captured images will be flipped if set to true.

Parameters:
doFlip - if true, flip the captured images

isFlip

public boolean isFlip()
Gets the flip (like a 180 degree rotation) property of this object.

Returns:
true, if this object is flipping captured images

getCameraNumber

public int getCameraNumber()
Gets the camera number this object was constructed with. This will be -1 if we are capturing from a file.

Returns:
the camera number

getVideoFile

public java.lang.String getVideoFile()
Gets the video filename we are capturing from. This will be null if we are capturing from a camera.

Returns:
the video filename

getFPS

public double getFPS()
Gets the current performance of the capture in frames per second.

Returns:
the current performance in frames per second.

getStateMonitor

public java.util.Observable getStateMonitor()
Gets the StateMonitor (an Observable object) with which other objects implementing the Observer interface can register with. When a new image is captured, these objects will be notified. The argument object of the update method called on the Observers is of class IplImage.

Returns:
the StateMonitor

stop

public void stop()
Stops the capture loop. After the next image, no more images will be captured until run() is called again.


run

public void run()
Runs the capture in an internal loop. Made to be used with a Thread object. Will return when stop() is called, or when the end of the file is reached, or when an error occurs. It will display in a Swing dialog box errors that occur.

Specified by:
run in interface java.lang.Runnable