OpenCV 2.4.2

org.opencv.highgui
Class VideoCapture

java.lang.Object
  extended by org.opencv.highgui.VideoCapture

public class VideoCapture
extends java.lang.Object

Class for video capturing from video files or cameras. The class provides C++ API for capturing video from cameras or for reading video files. Here is how the class can be used:

Note: In C API the black-box structure CvCapture is used instead of VideoCapture.

See Also:
org.opencv.highgui.VideoCapture

Field Summary
protected  long nativeObj
           
 
Constructor Summary
  VideoCapture()
          VideoCapture constructors.
  VideoCapture(int device)
          VideoCapture constructors.
protected VideoCapture(long addr)
           
 
Method Summary
protected  void finalize()
           
 double get(int propId)
          Returns the specified "VideoCapture" property Note: When querying a property that is not supported by the backend used by the "VideoCapture" class, value 0 is returned.
 java.util.List<Size> getSupportedPreviewSizes()
           
 boolean grab()
          Grabs the next frame from video file or capturing device.
 boolean isOpened()
          Returns true if video capturing has been initialized already.
 boolean open(int device)
          Open video file or a capturing device for video capturing The methods first call "VideoCapture.release" to close the already opened file or camera.
 boolean read(Mat image)
          Grabs, decodes and returns the next video frame.
 void release()
          Closes video file or capturing device.
 boolean retrieve(Mat image)
          Decodes and returns the grabbed video frame.
 boolean retrieve(Mat image, int channel)
          Decodes and returns the grabbed video frame.
 boolean set(int propId, double value)
          Sets a property in the "VideoCapture".
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nativeObj

protected final long nativeObj
Constructor Detail

VideoCapture

public VideoCapture()

VideoCapture constructors.

Note: In C API, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr that calls cvReleaseCapture() automatically in the destructor.

See Also:
org.opencv.highgui.VideoCapture.VideoCapture

VideoCapture

public VideoCapture(int device)

VideoCapture constructors.

Note: In C API, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr that calls cvReleaseCapture() automatically in the destructor.

Parameters:
device - id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0.
See Also:
org.opencv.highgui.VideoCapture.VideoCapture

VideoCapture

protected VideoCapture(long addr)
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

get

public double get(int propId)
Returns the specified "VideoCapture" property Note: When querying a property that is not supported by the backend used by the "VideoCapture" class, value 0 is returned.

Parameters:
propId - Property identifier. It can be one of the following: * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream. * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
See Also:
org.opencv.highgui.VideoCapture.get

getSupportedPreviewSizes

public java.util.List<Size> getSupportedPreviewSizes()

grab

public boolean grab()

Grabs the next frame from video file or capturing device.

The methods/functions grab the next frame from video file or camera and return true (non-zero) in the case of success.

The primary use of the function is in multi-camera environments, especially when the cameras do not have hardware synchronization. That is, you call VideoCapture.grab() for each camera and after that call the slower method VideoCapture.retrieve() to decode and get frame from each camera. This way the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames from different cameras will be closer in time.

Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the correct way of retrieving data from it is to call "VideoCapture.grab" first and then call "VideoCapture.retrieve" one or more times with different values of the channel parameter. See http://code.opencv.org/svn/opencv/trunk/opencv/samples/cpp/kinect_maps.cpp

See Also:
org.opencv.highgui.VideoCapture.grab

isOpened

public boolean isOpened()

Returns true if video capturing has been initialized already.

If the previous call to VideoCapture constructor or VideoCapture.open succeeded, the method returns true.

See Also:
org.opencv.highgui.VideoCapture.isOpened

open

public boolean open(int device)

Open video file or a capturing device for video capturing

The methods first call "VideoCapture.release" to close the already opened file or camera.

Parameters:
device - id of the opened video capturing device (i.e. a camera index).
See Also:
org.opencv.highgui.VideoCapture.open

read

public boolean read(Mat image)

Grabs, decodes and returns the next video frame.

The methods/functions combine "VideoCapture.grab" and "VideoCapture.retrieve" in one call. This is the most convenient method for reading video files or capturing data from decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

Note: OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using "cvCloneImage" and then do whatever you want with the copy.

Parameters:
image - a image
See Also:
org.opencv.highgui.VideoCapture.read

release

public void release()

Closes video file or capturing device.

The methods are automatically called by subsequent "VideoCapture.open" and by VideoCapture destructor.

The C function also deallocates memory and clears *capture pointer.

See Also:
org.opencv.highgui.VideoCapture.release

retrieve

public boolean retrieve(Mat image)

Decodes and returns the grabbed video frame.

The methods/functions decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

Note: OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using "cvCloneImage" and then do whatever you want with the copy.

Parameters:
image - a image
See Also:
org.opencv.highgui.VideoCapture.retrieve

retrieve

public boolean retrieve(Mat image,
                        int channel)

Decodes and returns the grabbed video frame.

The methods/functions decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

Note: OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using "cvCloneImage" and then do whatever you want with the copy.

Parameters:
image - a image
channel - a channel
See Also:
org.opencv.highgui.VideoCapture.retrieve

set

public boolean set(int propId,
                   double value)
Sets a property in the "VideoCapture".

Parameters:
propId - Property identifier. It can be one of the following: * CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream. * CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
value - Value of the property.
See Also:
org.opencv.highgui.VideoCapture.set

Official OpenCV 2.4 Documentation