@Namespace(value="cv") @NoOffset @Properties(inherit=opencv_videoio.class) public class VideoCapture extends Pointer
/** \brief Class for video capturing from video files, image sequences or cameras.
The class provides C++ API for capturing video from cameras or for reading video files and image sequences.
Here is how the class can be used: \include samples/cpp/videocapture_basic.cpp
\note In \ref videoio_c "C API" the black-box structure CvCapture
is used instead of %VideoCapture.
\note
- (C++) A basic sample on using the %VideoCapture interface can be found at
OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp
- (Python) A basic sample on using the %VideoCapture interface can be found at
OPENCV_SOURCE_CODE/samples/python/video.py
- (Python) A multi threaded video processing sample can be found at
OPENCV_SOURCE_CODE/samples/python/video_threaded.py
- (Python) %VideoCapture sample showcasing some features of the Video4Linux2 backend
OPENCV_SOURCE_CODE/samples/python/video_v4l2.py
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
VideoCapture()
\brief Default constructor
\note In \ref videoio_c "C API", when you finished working with video, release CvCapture structure with
cvReleaseCapture(), or use Ptr\
|
VideoCapture(BytePointer filename) |
VideoCapture(BytePointer filename,
int apiPreference)
\overload
\brief Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
|
VideoCapture(int index) |
VideoCapture(int index,
int apiPreference)
\overload
\brief Opens a camera for video capturing
|
VideoCapture(Pointer p)
Pointer cast constructor.
|
VideoCapture(String filename) |
VideoCapture(String filename,
int apiPreference) |
Modifier and Type | Method and Description |
---|---|
double |
get(int propId)
\brief Returns the specified VideoCapture property
|
BytePointer |
getBackendName()
\brief Returns used backend API name
|
boolean |
getExceptionMode()
query if exception mode is active
|
boolean |
grab()
\brief Grabs the next frame from video file or capturing device.
|
boolean |
isOpened()
\brief Returns true if video capturing has been initialized already.
|
boolean |
open(BytePointer filename) |
boolean |
open(BytePointer filename,
int apiPreference)
\brief Opens a video file or a capturing device or an IP video stream for video capturing.
|
boolean |
open(int index) |
boolean |
open(int index,
int apiPreference)
\brief Opens a camera for video capturing
|
boolean |
open(String filename) |
boolean |
open(String filename,
int apiPreference) |
boolean |
read(GpuMat image) |
boolean |
read(Mat image)
\brief Grabs, decodes and returns the next video frame.
|
boolean |
read(UMat image) |
void |
release()
\brief Closes video file or capturing device.
|
boolean |
retrieve(GpuMat image) |
boolean |
retrieve(GpuMat image,
int flag) |
boolean |
retrieve(Mat image) |
boolean |
retrieve(Mat image,
int flag)
\brief Decodes and returns the grabbed video frame.
|
boolean |
retrieve(UMat image) |
boolean |
retrieve(UMat image,
int flag) |
boolean |
set(int propId,
double value)
\brief Sets a property in the VideoCapture.
|
void |
setExceptionMode(boolean enable)
Switches exceptions mode
methods raise exceptions if not successful instead of returning an error code
|
VideoCapture |
shiftRight(Mat image)
\brief Stream operator to read the next video frame.
|
VideoCapture |
shiftRight(UMat image)
\overload
|
static boolean |
waitAny(VideoCapture streams,
int[] readyIndex) |
static boolean |
waitAny(VideoCapture streams,
int[] readyIndex,
long timeoutNs) |
static boolean |
waitAny(VideoCapture streams,
IntBuffer readyIndex) |
static boolean |
waitAny(VideoCapture streams,
IntBuffer readyIndex,
long timeoutNs) |
static boolean |
waitAny(VideoCapture streams,
IntPointer readyIndex) |
static boolean |
waitAny(VideoCapture streams,
IntPointer readyIndex,
long timeoutNs)
\brief Wait for ready frames from VideoCapture.
|
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zero
public VideoCapture(Pointer p)
Pointer.Pointer(Pointer)
.public VideoCapture()
public VideoCapture(@opencv_core.Str BytePointer filename, int apiPreference)
filename
- it can be:
- name of video file (eg. video.avi
)
- or image sequence (eg. img_%02d.jpg
, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...
)
- or URL of video stream (eg. protocol://host:port/script_name?script_params|auth
)
- or GStreamer pipeline string in gst-launch tool format in case if GStreamer is used as backend
Note that each video stream or IP camera feed has its own URL scheme. Please refer to the
documentation of source stream to know the right URL.apiPreference
- preferred Capture API backends to use. Can be used to enforce a specific reader
implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW.
cv::VideoCaptureAPIs
public VideoCapture(@opencv_core.Str BytePointer filename)
public VideoCapture(@opencv_core.Str String filename, int apiPreference)
public VideoCapture(@opencv_core.Str String filename)
public VideoCapture(int index, int apiPreference)
index
- id of the video capturing device to open. To open default camera using default backend just pass 0.
(to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY)apiPreference
- preferred Capture API backends to use. Can be used to enforce a specific reader
implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L.
cv::VideoCaptureAPIs
public VideoCapture(int index)
@Cast(value="bool") public boolean open(@opencv_core.Str BytePointer filename, int apiPreference)
\overload
Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)
true
if the file has been successfully opened
The method first calls VideoCapture::release to close the already opened file or camera.
@Cast(value="bool") public boolean open(@opencv_core.Str BytePointer filename)
@Cast(value="bool") public boolean open(@opencv_core.Str String filename, int apiPreference)
@Cast(value="bool") public boolean open(@opencv_core.Str String filename)
@Cast(value="bool") public boolean open(int index, int apiPreference)
\overload
Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
true
if the camera has been successfully opened.
The method first calls VideoCapture::release to close the already opened file or camera.
@Cast(value="bool") public boolean isOpened()
If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns true.
public void release()
The method is automatically called by subsequent VideoCapture::open and by VideoCapture destructor.
The C function also deallocates memory and clears \*capture pointer.
@Cast(value="bool") public boolean grab()
true
(non-zero) in the case of success.
The method/function grabs the next frame from video file or camera and returns 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.
\ref tutorial_kinect_openni
@Cast(value="bool") public boolean retrieve(@ByVal Mat image, int flag)
image
- [out] the video frame is returned here. If no frames has been grabbed the image will be empty.flag
- it could be a frame index or a driver specific flagfalse
if no frames has been grabbed
The method decodes and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns an empty image (with %cv::Mat, test it with Mat::empty()).
\note In \ref videoio_c "C API", 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.
@ByRef @Name(value="operator >>") public VideoCapture shiftRight(@ByRef Mat image)
read()
@ByRef @Name(value="operator >>") public VideoCapture shiftRight(@ByRef UMat image)
read()
@Cast(value="bool") public boolean read(@ByVal Mat image)
image
- [out] the video frame is returned here. If no frames has been grabbed the image will be empty.false
if no frames has been grabbed
The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()).
\note In \ref videoio_c "C API", 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.
@Cast(value="bool") public boolean set(int propId, double value)
propId
- Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)
or one from \ref videoio_flags_othersvalue
- Value of the property.true
if the property is supported by backend used by the VideoCapture instance.
\note Even if it returns true
this doesn't ensure that the property
value has been accepted by the capture device. See note in VideoCapture::get()public double get(int propId)
propId
- Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)
or one from \ref videoio_flags_others\note Reading / writing properties involves many layers. Some unexpected result might happens along this chain.
{.txt}
VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware
The returned value might be different from what really used by the device or it could be encoded
using device dependent rules (eg. steps or percentage). Effective behaviour depends from device
driver and API Backend
@opencv_core.Str public BytePointer getBackendName()
\note Stream should be opened.
public void setExceptionMode(@Cast(value="bool") boolean enable)
@Cast(value="bool") public boolean getExceptionMode()
@Cast(value="bool") public static boolean waitAny(@StdVector VideoCapture streams, @StdVector IntPointer readyIndex, @Cast(value="int64") long timeoutNs)
streams
- input video streamsreadyIndex
- stream indexes with grabbed frames (ready to use .retrieve() to fetch actual frame)timeoutNs
- number of nanoseconds (0 - infinite)true
if streamReady is not empty
Exception
- %Exception on stream errors (check .isOpened() to filter out malformed streams) or VideoCapture type is not supported
The primary use of the function is in multi-camera environments. The method fills the ready state vector, grabbs video frame, if camera is ready.
After this call use VideoCapture::retrieve() to decode and fetch frame data.
@Cast(value="bool") public static boolean waitAny(@StdVector VideoCapture streams, @StdVector IntPointer readyIndex)
@Cast(value="bool") public static boolean waitAny(@StdVector VideoCapture streams, @StdVector IntBuffer readyIndex, @Cast(value="int64") long timeoutNs)
@Cast(value="bool") public static boolean waitAny(@StdVector VideoCapture streams, @StdVector IntBuffer readyIndex)
@Cast(value="bool") public static boolean waitAny(@StdVector VideoCapture streams, @StdVector int[] readyIndex, @Cast(value="int64") long timeoutNs)
@Cast(value="bool") public static boolean waitAny(@StdVector VideoCapture streams, @StdVector int[] readyIndex)
Copyright © 2020. All rights reserved.