Open video file or a capturing device or a IP video stream for video capturing
successFlag = cap.open(index)
successFlag = cap.open(filename)
successFlag = cap.open(..., 'API',apiPreference)
Input
- index id of the video capturing device to open. To open
default camera using default backend just pass 0.
- 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
).
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.
- or device name (for backends like V4L or gPhoto2)
Output
- successFlag bool, true if the file/camera has been
successfully opened.
Options
- API preferred capture API backend to use. Can be used to
enforce a specific reader implementation if multiple are
available: e.g. 'FFMPEG' or 'Images' or 'DirectShow'. The list
of supported API backends:
- Any Auto detect. This is the default.
- VfW Video For Windows (platform native).
- V4L V4L/V4L2 capturing support via libv4l.
- V4L2 Same as V4L.
- FireWire IEEE 1394 drivers.
- FireWare Same as FireWire.
- IEEE1394 Same as FireWire.
- DC1394 Same as FireWire.
- CMU1394 Same as FireWire.
- QuickTime QuickTime.
- Unicap Unicap drivers.
- DirectShow DirectShow (via videoInput).
- PvAPI PvAPI, Prosilica GigE SDK.
- OpenNI OpenNI (for Kinect).
- OpenNIAsus OpenNI (for Asus Xtion).
- Android Android - not used.
- XIMEA XIMEA Camera API.
- AVFoundation AVFoundation framework for iOS
(OS X Lion will have the same API).
- Giganetix Smartek Giganetix GigEVisionSDK.
- MediaFoundation Microsoft Media Foundation
(via videoInput).
- WinRT Microsoft Windows Runtime using Media
Foundation.
- IntelPerC Intel Perceptual Computing SDK.
- OpenNI2 OpenNI2 (for Kinect).
- OpenNI2Asus OpenNI2 (for Asus Xtion and Occipital
Structure sensors).
- gPhoto2 gPhoto2 connection.
- GStreamer GStreamer.
- FFMPEG Open video file or stream using the FFMPEG
library.
- Images OpenCV Image Sequence (e.g.
img_%02d.jpg
).
- Aravis Aravis GigE SDK.
- MotionJPEG Built-in OpenCV MotionJPEG codec.
- MediaSDK Intel MediaSDK.
The method first calls cv.VideoCapture.release to close the
already opened file or camera.
Example
Use API
option to enforce a specific reader implementation
if multiple are available like 'FFMPEG' or 'Images' or
'DirectShow'. For example, to open camera 1 using the
"MS Media Foundation" API:
cap.open(1, 'API','MediaFoundation')
Note
Backends are available only if they have been built with your
OpenCV binaries.
Check your build to know which APIs are currently available.
To enable/disable APIs, you have to re-configure OpenCV using
the appropriates CMake switches and recompile OpenCV itself.