|
OpenCV 2.4.6 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.opencv.highgui.VideoCapture
public class VideoCapture
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
.
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 |
---|
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.
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.
device
- id of the opened video capturing device (i.e. a camera index).
If there is a single camera connected, just pass 0.Method Detail |
---|
public double get(int propId)
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.public java.util.List<Size> getSupportedPreviewSizes()
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
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.
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.
device
- id of the opened video capturing device (i.e. a camera index).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.
image
- a imagepublic 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.
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.
image
- a imagepublic 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.
image
- a imagechannel
- a channelpublic boolean set(int propId, double value)
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.
|
OpenCV 2.4.6 Documentation | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |