Module Opencv.Video_capture
val video_capture1 : unit -> t
Usage:
video_capture1 ()
Default constructor Note: In videoio_c "C API", when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr\<CvCapture\> that calls cvReleaseCapture() automatically in the destructor.
val video_capture2 : ?api_preference:int -> string -> t
Usage:
video_capture2 ?api_preference filename
Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
- Parameter:
filename
: it can be: - name of video file (eg.
video.avi
) - or image sequence (eg.
img_%02d.jpg
, which will read samples likeimg_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.
- Parameter:
api_preference
: 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.
See also: cv::VideoCaptureAPIs
- Parameter:
val video_capture3 : ?api_preference:int -> int -> t
Usage:
video_capture3 ?api_preference index
Opens a camera for video capturing
- Parameter:
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) - Parameter:
api_preference
: 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.
See also: cv::VideoCaptureAPIs
- Parameter:
val open1 : ?api_preference:int -> t -> string -> bool
Usage:
open1 ?api_preference __self filename
Opens a video file or a capturing device or an IP video stream for video capturing.
Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)
- Returns:
true
if the file has been successfully opened
The method first calls VideoCapture::release to close the already opened file or camera.
- Returns:
val open2 : ?api_preference:int -> t -> int -> bool
Usage:
open2 ?api_preference __self index
Opens a camera for video capturing
Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
- Returns:
true
if the camera has been successfully opened.
The method first calls VideoCapture::release to close the already opened file or camera.
- Returns:
val is_opened : t -> bool
Usage:
is_opened __self
Returns true if video capturing has been initialized already.
If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns true.
val release : t -> unit
Usage:
release __self
Closes video file or capturing device.
The method is automatically called by subsequent VideoCapture::open and by VideoCapture destructor.
The C function also deallocates memory and clears \*capture pointer.
val grab : t -> bool
Usage:
grab __self
Grabs the next frame from video file or capturing device.
- Returns:
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.
tutorial_kinect_openni
- Returns:
val retrieve : ?image:Cvdata.t -> ?flag:int -> t -> Cvdata.t * bool
Usage:
retrieve ?image ?flag __self
Decodes and returns the grabbed video frame.
- Parameter:
:return image the video frame is returned here. If no frames has been grabbed the image will be empty.
- Parameter:
flag
: it could be a frame index or a driver specific flag - Returns:
false
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()).
See also: read()
Note: In 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.
- Parameter:
val read : ?image:Cvdata.t -> t -> Cvdata.t * bool
Usage:
read ?image __self
Grabs, decodes and returns the next video frame.
- Parameter:
:return image the video frame is returned here. If no frames has been grabbed the image will be empty.
- Returns:
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 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.
- Parameter:
val set : t -> int -> float -> bool
Usage:
set __self prop_id value
Sets a property in the VideoCapture.
- Parameter:
prop_id
: Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from videoio_flags_others - Parameter:
value
: Value of the property. - Returns:
true
if the property is supported by backend used by the VideoCapture instance. Note: Even if it returnstrue
this doesn't ensure that the property value has been accepted by the capture device. See note in VideoCapture::get()
- Parameter:
val get : t -> int -> float
Usage:
get __self prop_id
Returns the specified VideoCapture property
- Parameter:
prop_id
: Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from videoio_flags_others - Returns: Value for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoCapture instance.
Note: Reading / writing properties involves many layers. Some unexpected result might happens along this chain.
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
- Parameter:
val get_backend_name : t -> string
Usage:
get_backend_name __self
Returns used backend API name
Note: Stream should be opened.
val set_exception_mode : t -> bool -> unit
Usage:
set_exception_mode __self enable
Switches exceptions mode * * methods raise exceptions if not successful instead of returning an error code
val get_exception_mode : t -> bool
Usage:
get_exception_mode __self