OpenCV 2.4.4

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:

#include "opencv2/opencv.hpp"

// C++ code:

using namespace cv;

int main(int, char)

VideoCapture cap(0); // open the default camera

if(!cap.isOpened()) // check if we succeeded

return -1;

Mat edges;

namedWindow("edges",1);

for(;;)

Mat frame;

cap >> frame; // get a new frame from camera

cvtColor(frame, edges, CV_BGR2GRAY);

GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);

Canny(edges, edges, 0, 30, 3);

imshow("edges", edges);

if(waitKey(30) >= 0) break;

// the camera will be deinitialized automatically in VideoCapture destructor

return 0;

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

See Also:
org.opencv.highgui.VideoCapture

Constructor Summary
VideoCapture()
          VideoCapture constructors.
VideoCapture(int device)
          VideoCapture constructors.
 
Method Summary
 double get(int propId)
          Returns the specified "VideoCapture" property.
 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
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Method Detail

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/projects/opencv/repository/revisions/master/entry/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

OpenCV 2.4.4 Documentation