public class VideoCapture extends Video<MBFImage>
Video
that can capture live video streams
from a webcam or other video device. On OSX and Windows, this is completely
dependency-free and no extra software needs to be installed. On linux you
need to have video4linux installed.
Environment variables
System properties
DEFAULT_DEVICE_NUMBER_PROPERTY
can be used to set the default
capture device and can either be a device number, or device identifer string.
See VideoCapture(int, int)
for more details.Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DEVICE_NUMBER_PROPERTY
The property key for overriding the default device number.
|
currentFrame
Constructor and Description |
---|
VideoCapture(int width,
int height)
Construct a VideoCapture instance with the requested width and height.
|
VideoCapture(int width,
int height,
Device device)
Construct a VideoCapture instance with the requested width and height
using the specified video device.
|
VideoCapture(int width,
int height,
double fps,
Device device)
Construct a VideoCapture instance with the requested width and height
using the specified video device.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the video object
|
long |
countFrames()
Return the number of frames in the whole video.
|
protected void |
finalize() |
MBFImage |
getCurrentFrame()
Get the current frame
|
double |
getFPS()
Get the frame rate
|
int |
getHeight()
Get the height of the video frame.
|
MBFImage |
getNextFrame()
Get the next frame.
|
long |
getTimeStamp()
Get the timestamp of the current frame in milliseconds
|
static List<Device> |
getVideoDevices()
Get a list of all compatible video devices attached to the machine.
|
int |
getWidth()
Get the width of the video frame
|
boolean |
hasNextFrame()
Returns whether this video has another frame to provide.
|
static void |
main(String[] args)
Test main method.
|
void |
reset()
Reset the video - putting the frame counter back to the start.
|
void |
setCurrentFrameIndex(long newFrame)
Set the current frame index (i.e.
|
void |
setFPS(double fps)
Set the number of frames per second.
|
protected boolean |
startSession(int requestedWidth,
int requestedHeight,
double requestedFPS) |
protected boolean |
startSession(int requestedWidth,
int requestedHeight,
double requestedFPS,
Device device) |
void |
stopCapture()
Stop the video capture system.
|
getCurrentFrameIndex, iterator, seek
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static final String DEFAULT_DEVICE_NUMBER_PROPERTY
public VideoCapture(int width, int height) throws VideoCaptureException
getWidth()
and
getHeight()
methods.
The default device is usually the first device listed by
getVideoDevices()
, however this is down to the underlying native
libraries and operating system. The
DEFAULT_DEVICE_NUMBER_PROPERTY
system property allows the
selection of the default device to be overridden. The property value can
be an integer representing the index of the default device in the list
produced by DEFAULT_DEVICE_NUMBER_PROPERTY
or a String
that includes part of the device identifier. In the case of a String
value, the device with the identifier that first contains the value is
selected.
width
- the requested video widthheight
- the requested video heightVideoCaptureException
- if no webcam is found, or there is a problem opening itpublic VideoCapture(int width, int height, Device device) throws VideoCaptureException
getWidth()
and
getHeight()
methods.width
- the requested video width.height
- the requested video height.device
- the requested video device.VideoCaptureException
- if there is a problem opening the webcampublic VideoCapture(int width, int height, double fps, Device device) throws VideoCaptureException
getWidth()
and
getHeight()
methods.width
- the requested video width.height
- the requested video height.fps
- the requested frame ratedevice
- the requested video device.VideoCaptureException
- if there is a problem opening the webcampublic static List<Device> getVideoDevices()
protected boolean startSession(int requestedWidth, int requestedHeight, double requestedFPS, Device device)
protected boolean startSession(int requestedWidth, int requestedHeight, double requestedFPS)
public void stopCapture()
public MBFImage getCurrentFrame()
Video
getCurrentFrame
in class Video<MBFImage>
public MBFImage getNextFrame()
getNextFrame
in class Video<MBFImage>
RuntimeException
- wrapping a VideoCaptureException
with the message
"Timed out waiting for next frame" if there is a timeout
waiting for the next frame. This could potentially be caught
and ignored (i.e. the frame is dropped).RuntimeException
- wrapping a VideoCaptureException
with the message
"Error occurred getting next frame" if there is an error the
next frame. Currently this can only occur on linux.public boolean hasNextFrame()
Video
hasNextFrame
in class Video<MBFImage>
public long countFrames()
Video
countFrames
in class Video<MBFImage>
public static void main(String[] args) throws VideoCaptureException
args
- ignored.VideoCaptureException
public int getWidth()
getWidth
in class Video<MBFImage>
Video.getWidth()
public int getHeight()
getHeight
in class Video<MBFImage>
Video.getHeight()
public void reset()
Video
public long getTimeStamp()
getTimeStamp
in class Video<MBFImage>
Video.getTimeStamp()
public void setCurrentFrameIndex(long newFrame)
Video
setCurrentFrameIndex
in class Video<MBFImage>
newFrame
- the new indexpublic double getFPS()
getFPS
in class Video<MBFImage>
Video.getFPS()
public void setFPS(double fps)
fps
- The number of frames per second.