videoio.hpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #ifndef __OPENCV_VIDEOIO_HPP__
  43. #define __OPENCV_VIDEOIO_HPP__
  44. #include "opencv2/core.hpp"
  45. /**
  46. @defgroup videoio Media I/O
  47. @{
  48. @defgroup videoio_c C API
  49. @defgroup videoio_ios iOS glue
  50. @defgroup videoio_winrt WinRT glue
  51. @}
  52. */
  53. ////////////////////////////////// video io /////////////////////////////////
  54. typedef struct CvCapture CvCapture;
  55. typedef struct CvVideoWriter CvVideoWriter;
  56. namespace cv
  57. {
  58. //! @addtogroup videoio
  59. //! @{
  60. // Camera API
  61. enum { CAP_ANY = 0, // autodetect
  62. CAP_VFW = 200, // platform native
  63. CAP_V4L = 200,
  64. CAP_V4L2 = CAP_V4L,
  65. CAP_FIREWARE = 300, // IEEE 1394 drivers
  66. CAP_FIREWIRE = CAP_FIREWARE,
  67. CAP_IEEE1394 = CAP_FIREWARE,
  68. CAP_DC1394 = CAP_FIREWARE,
  69. CAP_CMU1394 = CAP_FIREWARE,
  70. CAP_QT = 500, // QuickTime
  71. CAP_UNICAP = 600, // Unicap drivers
  72. CAP_DSHOW = 700, // DirectShow (via videoInput)
  73. CAP_PVAPI = 800, // PvAPI, Prosilica GigE SDK
  74. CAP_OPENNI = 900, // OpenNI (for Kinect)
  75. CAP_OPENNI_ASUS = 910, // OpenNI (for Asus Xtion)
  76. CAP_ANDROID = 1000, // Android - not used
  77. CAP_XIAPI = 1100, // XIMEA Camera API
  78. CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API)
  79. CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK
  80. CAP_MSMF = 1400, // Microsoft Media Foundation (via videoInput)
  81. CAP_WINRT = 1410, // Microsoft Windows Runtime using Media Foundation
  82. CAP_INTELPERC = 1500, // Intel Perceptual Computing SDK
  83. CAP_OPENNI2 = 1600, // OpenNI2 (for Kinect)
  84. CAP_OPENNI2_ASUS = 1610, // OpenNI2 (for Asus Xtion and Occipital Structure sensors)
  85. CAP_GPHOTO2 = 1700 // gPhoto2 connection
  86. };
  87. // generic properties (based on DC1394 properties)
  88. enum { CAP_PROP_POS_MSEC =0,
  89. CAP_PROP_POS_FRAMES =1,
  90. CAP_PROP_POS_AVI_RATIO =2,
  91. CAP_PROP_FRAME_WIDTH =3,
  92. CAP_PROP_FRAME_HEIGHT =4,
  93. CAP_PROP_FPS =5,
  94. CAP_PROP_FOURCC =6,
  95. CAP_PROP_FRAME_COUNT =7,
  96. CAP_PROP_FORMAT =8,
  97. CAP_PROP_MODE =9,
  98. CAP_PROP_BRIGHTNESS =10,
  99. CAP_PROP_CONTRAST =11,
  100. CAP_PROP_SATURATION =12,
  101. CAP_PROP_HUE =13,
  102. CAP_PROP_GAIN =14,
  103. CAP_PROP_EXPOSURE =15,
  104. CAP_PROP_CONVERT_RGB =16,
  105. CAP_PROP_WHITE_BALANCE_BLUE_U =17,
  106. CAP_PROP_RECTIFICATION =18,
  107. CAP_PROP_MONOCHROME =19,
  108. CAP_PROP_SHARPNESS =20,
  109. CAP_PROP_AUTO_EXPOSURE =21, // DC1394: exposure control done by camera, user can adjust refernce level using this feature
  110. CAP_PROP_GAMMA =22,
  111. CAP_PROP_TEMPERATURE =23,
  112. CAP_PROP_TRIGGER =24,
  113. CAP_PROP_TRIGGER_DELAY =25,
  114. CAP_PROP_WHITE_BALANCE_RED_V =26,
  115. CAP_PROP_ZOOM =27,
  116. CAP_PROP_FOCUS =28,
  117. CAP_PROP_GUID =29,
  118. CAP_PROP_ISO_SPEED =30,
  119. CAP_PROP_BACKLIGHT =32,
  120. CAP_PROP_PAN =33,
  121. CAP_PROP_TILT =34,
  122. CAP_PROP_ROLL =35,
  123. CAP_PROP_IRIS =36,
  124. CAP_PROP_SETTINGS =37
  125. };
  126. // Generic camera output modes.
  127. // Currently, these are supported through the libv4l interface only.
  128. enum { CAP_MODE_BGR = 0, // BGR24 (default)
  129. CAP_MODE_RGB = 1, // RGB24
  130. CAP_MODE_GRAY = 2, // Y8
  131. CAP_MODE_YUYV = 3 // YUYV
  132. };
  133. // DC1394 only
  134. // modes of the controlling registers (can be: auto, manual, auto single push, absolute Latter allowed with any other mode)
  135. // every feature can have only one mode turned on at a time
  136. enum { CAP_PROP_DC1394_OFF = -4, //turn the feature off (not controlled manually nor automatically)
  137. CAP_PROP_DC1394_MODE_MANUAL = -3, //set automatically when a value of the feature is set by the user
  138. CAP_PROP_DC1394_MODE_AUTO = -2,
  139. CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1,
  140. CAP_PROP_DC1394_MAX = 31
  141. };
  142. // OpenNI map generators
  143. enum { CAP_OPENNI_DEPTH_GENERATOR = 1 << 31,
  144. CAP_OPENNI_IMAGE_GENERATOR = 1 << 30,
  145. CAP_OPENNI_GENERATORS_MASK = CAP_OPENNI_DEPTH_GENERATOR + CAP_OPENNI_IMAGE_GENERATOR
  146. };
  147. // Properties of cameras available through OpenNI interfaces
  148. enum { CAP_PROP_OPENNI_OUTPUT_MODE = 100,
  149. CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm
  150. CAP_PROP_OPENNI_BASELINE = 102, // in mm
  151. CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels
  152. CAP_PROP_OPENNI_REGISTRATION = 104, // flag that synchronizes the remapping depth map to image map
  153. // by changing depth generator's view point (if the flag is "on") or
  154. // sets this view point to its normal one (if the flag is "off").
  155. CAP_PROP_OPENNI_REGISTRATION_ON = CAP_PROP_OPENNI_REGISTRATION,
  156. CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105,
  157. CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106,
  158. CAP_PROP_OPENNI_CIRCLE_BUFFER = 107,
  159. CAP_PROP_OPENNI_MAX_TIME_DURATION = 108,
  160. CAP_PROP_OPENNI_GENERATOR_PRESENT = 109,
  161. CAP_PROP_OPENNI2_SYNC = 110,
  162. CAP_PROP_OPENNI2_MIRROR = 111
  163. };
  164. // OpenNI shortcats
  165. enum { CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT,
  166. CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_OUTPUT_MODE,
  167. CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_BASELINE,
  168. CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_FOCAL_LENGTH,
  169. CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_REGISTRATION,
  170. CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION
  171. };
  172. // OpenNI data given from depth generator
  173. enum { CAP_OPENNI_DEPTH_MAP = 0, // Depth values in mm (CV_16UC1)
  174. CAP_OPENNI_POINT_CLOUD_MAP = 1, // XYZ in meters (CV_32FC3)
  175. CAP_OPENNI_DISPARITY_MAP = 2, // Disparity in pixels (CV_8UC1)
  176. CAP_OPENNI_DISPARITY_MAP_32F = 3, // Disparity in pixels (CV_32FC1)
  177. CAP_OPENNI_VALID_DEPTH_MASK = 4, // CV_8UC1
  178. // Data given from RGB image generator
  179. CAP_OPENNI_BGR_IMAGE = 5,
  180. CAP_OPENNI_GRAY_IMAGE = 6
  181. };
  182. // Supported output modes of OpenNI image generator
  183. enum { CAP_OPENNI_VGA_30HZ = 0,
  184. CAP_OPENNI_SXGA_15HZ = 1,
  185. CAP_OPENNI_SXGA_30HZ = 2,
  186. CAP_OPENNI_QVGA_30HZ = 3,
  187. CAP_OPENNI_QVGA_60HZ = 4
  188. };
  189. // GStreamer
  190. enum { CAP_PROP_GSTREAMER_QUEUE_LENGTH = 200 // default is 1
  191. };
  192. // PVAPI
  193. enum { CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast
  194. CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301, // FrameStartTriggerMode: Determines how a frame is initiated
  195. CAP_PROP_PVAPI_DECIMATIONHORIZONTAL = 302, // Horizontal sub-sampling of the image
  196. CAP_PROP_PVAPI_DECIMATIONVERTICAL = 303, // Vertical sub-sampling of the image
  197. CAP_PROP_PVAPI_BINNINGX = 304, // Horizontal binning factor
  198. CAP_PROP_PVAPI_BINNINGY = 305, // Vertical binning factor
  199. CAP_PROP_PVAPI_PIXELFORMAT = 306 // Pixel format
  200. };
  201. // PVAPI: FrameStartTriggerMode
  202. enum { CAP_PVAPI_FSTRIGMODE_FREERUN = 0, // Freerun
  203. CAP_PVAPI_FSTRIGMODE_SYNCIN1 = 1, // SyncIn1
  204. CAP_PVAPI_FSTRIGMODE_SYNCIN2 = 2, // SyncIn2
  205. CAP_PVAPI_FSTRIGMODE_FIXEDRATE = 3, // FixedRate
  206. CAP_PVAPI_FSTRIGMODE_SOFTWARE = 4 // Software
  207. };
  208. // PVAPI: DecimationHorizontal, DecimationVertical
  209. enum { CAP_PVAPI_DECIMATION_OFF = 1, // Off
  210. CAP_PVAPI_DECIMATION_2OUTOF4 = 2, // 2 out of 4 decimation
  211. CAP_PVAPI_DECIMATION_2OUTOF8 = 4, // 2 out of 8 decimation
  212. CAP_PVAPI_DECIMATION_2OUTOF16 = 8 // 2 out of 16 decimation
  213. };
  214. // PVAPI: PixelFormat
  215. enum { CAP_PVAPI_PIXELFORMAT_MONO8 = 1, // Mono8
  216. CAP_PVAPI_PIXELFORMAT_MONO16 = 2, // Mono16
  217. CAP_PVAPI_PIXELFORMAT_BAYER8 = 3, // Bayer8
  218. CAP_PVAPI_PIXELFORMAT_BAYER16 = 4, // Bayer16
  219. CAP_PVAPI_PIXELFORMAT_RGB24 = 5, // Rgb24
  220. CAP_PVAPI_PIXELFORMAT_BGR24 = 6, // Bgr24
  221. CAP_PVAPI_PIXELFORMAT_RGBA32 = 7, // Rgba32
  222. CAP_PVAPI_PIXELFORMAT_BGRA32 = 8, // Bgra32
  223. };
  224. // Properties of cameras available through XIMEA SDK interface
  225. enum { CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping.
  226. CAP_PROP_XI_DATA_FORMAT = 401, // Output data format.
  227. CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels).
  228. CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels).
  229. CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger.
  230. CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE.
  231. CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input
  232. CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode
  233. CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level
  234. CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output
  235. CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode
  236. CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED
  237. CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality
  238. CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition)
  239. CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance
  240. CAP_PROP_XI_AEAG = 415, // Automatic exposure/gain
  241. CAP_PROP_XI_EXP_PRIORITY = 416, // Exposure priority (0.5 - exposure 50%, gain 50%).
  242. CAP_PROP_XI_AE_MAX_LIMIT = 417, // Maximum limit of exposure in AEAG procedure
  243. CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure
  244. CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %)
  245. CAP_PROP_XI_TIMEOUT = 420 // Image capture timeout in milliseconds
  246. };
  247. // Properties of cameras available through AVFOUNDATION interface
  248. enum { CAP_PROP_IOS_DEVICE_FOCUS = 9001,
  249. CAP_PROP_IOS_DEVICE_EXPOSURE = 9002,
  250. CAP_PROP_IOS_DEVICE_FLASH = 9003,
  251. CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004,
  252. CAP_PROP_IOS_DEVICE_TORCH = 9005
  253. };
  254. // Properties of cameras available through Smartek Giganetix Ethernet Vision interface
  255. /* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */
  256. enum { CAP_PROP_GIGA_FRAME_OFFSET_X = 10001,
  257. CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002,
  258. CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003,
  259. CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004,
  260. CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005,
  261. CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006
  262. };
  263. enum { CAP_PROP_INTELPERC_PROFILE_COUNT = 11001,
  264. CAP_PROP_INTELPERC_PROFILE_IDX = 11002,
  265. CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003,
  266. CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004,
  267. CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005,
  268. CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006,
  269. CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007
  270. };
  271. // Intel PerC streams
  272. enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29,
  273. CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28,
  274. CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR
  275. };
  276. enum { CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth.
  277. CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates.
  278. CAP_INTELPERC_IR_MAP = 2, // Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam.
  279. CAP_INTELPERC_IMAGE = 3
  280. };
  281. enum { VIDEOWRITER_PROP_QUALITY = 1, // Quality (0..100%) of the videostream encoded
  282. VIDEOWRITER_PROP_FRAMEBYTES = 2, // (Read-only): Size of just encoded video frame
  283. };
  284. // gPhoto2 properties, if propertyId is less than 0 then work on widget with that __additive inversed__ camera setting ID
  285. // Get IDs by using CAP_PROP_GPHOTO2_WIDGET_ENUMERATE.
  286. // @see CvCaptureCAM_GPHOTO2 for more info
  287. enum { CAP_PROP_GPHOTO2_PREVIEW = 17001, // Capture only preview from liveview mode.
  288. CAP_PROP_GPHOTO2_WIDGET_ENUMERATE = 17002, // Readonly, returns (const char *).
  289. CAP_PROP_GPHOTO2_RELOAD_CONFIG = 17003, // Trigger, only by set. Reload camera settings.
  290. CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE = 17004, // Reload all settings on set.
  291. CAP_PROP_GPHOTO2_COLLECT_MSGS = 17005, // Collect messages with details.
  292. CAP_PROP_GPHOTO2_FLUSH_MSGS = 17006, // Readonly, returns (const char *).
  293. CAP_PROP_SPEED = 17007, // Exposure speed. Can be readonly, depends on camera program.
  294. CAP_PROP_APERTURE = 17008, // Aperture. Can be readonly, depends on camera program.
  295. CAP_PROP_EXPOSUREPROGRAM = 17009, // Camera exposure program.
  296. CAP_PROP_VIEWFINDER = 17010 // Enter liveview mode.
  297. };
  298. //enum {
  299. class IVideoCapture;
  300. /** @brief Class for video capturing from video files, image sequences or cameras. The class provides C++ API
  301. for capturing video from cameras or for reading video files and image sequences. Here is how the
  302. class can be used: :
  303. @code
  304. #include "opencv2/opencv.hpp"
  305. using namespace cv;
  306. int main(int, char**)
  307. {
  308. VideoCapture cap(0); // open the default camera
  309. if(!cap.isOpened()) // check if we succeeded
  310. return -1;
  311. Mat edges;
  312. namedWindow("edges",1);
  313. for(;;)
  314. {
  315. Mat frame;
  316. cap >> frame; // get a new frame from camera
  317. cvtColor(frame, edges, COLOR_BGR2GRAY);
  318. GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
  319. Canny(edges, edges, 0, 30, 3);
  320. imshow("edges", edges);
  321. if(waitKey(30) >= 0) break;
  322. }
  323. // the camera will be deinitialized automatically in VideoCapture destructor
  324. return 0;
  325. }
  326. @endcode
  327. @note In C API the black-box structure CvCapture is used instead of VideoCapture.
  328. @note
  329. - A basic sample on using the VideoCapture interface can be found at
  330. opencv_source_code/samples/cpp/starter_video.cpp
  331. - Another basic video processing sample can be found at
  332. opencv_source_code/samples/cpp/video_dmtx.cpp
  333. - (Python) A basic sample on using the VideoCapture interface can be found at
  334. opencv_source_code/samples/python2/video.py
  335. - (Python) Another basic video processing sample can be found at
  336. opencv_source_code/samples/python2/video_dmtx.py
  337. - (Python) A multi threaded video processing sample can be found at
  338. opencv_source_code/samples/python2/video_threaded.py
  339. */
  340. class CV_EXPORTS_W VideoCapture
  341. {
  342. public:
  343. /** @brief
  344. @note In C API, when you finished working with video, release CvCapture structure with
  345. cvReleaseCapture(), or use Ptr\<CvCapture\> that calls cvReleaseCapture() automatically in the
  346. destructor.
  347. */
  348. CV_WRAP VideoCapture();
  349. /** @overload
  350. @param filename name of the opened video file (eg. video.avi) or image sequence (eg.
  351. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  352. */
  353. CV_WRAP VideoCapture(const String& filename);
  354. /** @overload
  355. @param device id of the opened video capturing device (i.e. a camera index). If there is a single
  356. camera connected, just pass 0.
  357. */
  358. CV_WRAP VideoCapture(int device);
  359. virtual ~VideoCapture();
  360. /** @brief Open video file or a capturing device for video capturing
  361. @param filename name of the opened video file (eg. video.avi) or image sequence (eg.
  362. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  363. The methods first call VideoCapture::release to close the already opened file or camera.
  364. */
  365. CV_WRAP virtual bool open(const String& filename);
  366. /** @overload
  367. @param device id of the opened video capturing device (i.e. a camera index).
  368. */
  369. CV_WRAP virtual bool open(int device);
  370. /** @brief Returns true if video capturing has been initialized already.
  371. If the previous call to VideoCapture constructor or VideoCapture::open succeeded, the method returns
  372. true.
  373. */
  374. CV_WRAP virtual bool isOpened() const;
  375. /** @brief Closes video file or capturing device.
  376. The methods are automatically called by subsequent VideoCapture::open and by VideoCapture
  377. destructor.
  378. The C function also deallocates memory and clears \*capture pointer.
  379. */
  380. CV_WRAP virtual void release();
  381. /** @brief Grabs the next frame from video file or capturing device.
  382. The methods/functions grab the next frame from video file or camera and return true (non-zero) in
  383. the case of success.
  384. The primary use of the function is in multi-camera environments, especially when the cameras do not
  385. have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that
  386. call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way
  387. the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames
  388. from different cameras will be closer in time.
  389. Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the
  390. correct way of retrieving data from it is to call VideoCapture::grab first and then call
  391. VideoCapture::retrieve one or more times with different values of the channel parameter. See
  392. <https://github.com/Itseez/opencv/tree/master/samples/cpp/openni_capture.cpp>
  393. */
  394. CV_WRAP virtual bool grab();
  395. /** @brief Decodes and returns the grabbed video frame.
  396. The methods/functions decode and return the just grabbed frame. If no frames has been grabbed
  397. (camera has been disconnected, or there are no more frames in video file), the methods return false
  398. and the functions return NULL pointer.
  399. @note OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video
  400. capturing structure. It is not allowed to modify or release the image! You can copy the frame using
  401. :ocvcvCloneImage and then do whatever you want with the copy.
  402. */
  403. CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0);
  404. virtual VideoCapture& operator >> (CV_OUT Mat& image);
  405. virtual VideoCapture& operator >> (CV_OUT UMat& image);
  406. /** @brief Grabs, decodes and returns the next video frame.
  407. The methods/functions combine VideoCapture::grab and VideoCapture::retrieve in one call. This is the
  408. most convenient method for reading video files or capturing data from decode and return the just
  409. grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more
  410. frames in video file), the methods return false and the functions return NULL pointer.
  411. @note OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video
  412. capturing structure. It is not allowed to modify or release the image! You can copy the frame using
  413. :ocvcvCloneImage and then do whatever you want with the copy.
  414. */
  415. CV_WRAP virtual bool read(OutputArray image);
  416. /** @brief Sets a property in the VideoCapture.
  417. @param propId Property identifier. It can be one of the following:
  418. - **CAP_PROP_POS_MSEC** Current position of the video file in milliseconds.
  419. - **CAP_PROP_POS_FRAMES** 0-based index of the frame to be decoded/captured next.
  420. - **CAP_PROP_POS_AVI_RATIO** Relative position of the video file: 0 - start of the
  421. film, 1 - end of the film.
  422. - **CAP_PROP_FRAME_WIDTH** Width of the frames in the video stream.
  423. - **CAP_PROP_FRAME_HEIGHT** Height of the frames in the video stream.
  424. - **CAP_PROP_FPS** Frame rate.
  425. - **CAP_PROP_FOURCC** 4-character code of codec.
  426. - **CAP_PROP_FRAME_COUNT** Number of frames in the video file.
  427. - **CAP_PROP_FORMAT** Format of the Mat objects returned by retrieve() .
  428. - **CAP_PROP_MODE** Backend-specific value indicating the current capture mode.
  429. - **CAP_PROP_BRIGHTNESS** Brightness of the image (only for cameras).
  430. - **CAP_PROP_CONTRAST** Contrast of the image (only for cameras).
  431. - **CAP_PROP_SATURATION** Saturation of the image (only for cameras).
  432. - **CAP_PROP_HUE** Hue of the image (only for cameras).
  433. - **CAP_PROP_GAIN** Gain of the image (only for cameras).
  434. - **CAP_PROP_EXPOSURE** Exposure (only for cameras).
  435. - **CAP_PROP_CONVERT_RGB** Boolean flags indicating whether images should be converted
  436. to RGB.
  437. - **CAP_PROP_WHITE_BALANCE** Currently unsupported
  438. - **CAP_PROP_RECTIFICATION** Rectification flag for stereo cameras (note: only supported
  439. by DC1394 v 2.x backend currently)
  440. @param value Value of the property.
  441. */
  442. CV_WRAP virtual bool set(int propId, double value);
  443. /** @brief Returns the specified VideoCapture property
  444. @param propId Property identifier. It can be one of the following:
  445. - **CAP_PROP_POS_MSEC** Current position of the video file in milliseconds or video
  446. capture timestamp.
  447. - **CAP_PROP_POS_FRAMES** 0-based index of the frame to be decoded/captured next.
  448. - **CAP_PROP_POS_AVI_RATIO** Relative position of the video file: 0 - start of the
  449. film, 1 - end of the film.
  450. - **CAP_PROP_FRAME_WIDTH** Width of the frames in the video stream.
  451. - **CAP_PROP_FRAME_HEIGHT** Height of the frames in the video stream.
  452. - **CAP_PROP_FPS** Frame rate.
  453. - **CAP_PROP_FOURCC** 4-character code of codec.
  454. - **CAP_PROP_FRAME_COUNT** Number of frames in the video file.
  455. - **CAP_PROP_FORMAT** Format of the Mat objects returned by retrieve() .
  456. - **CAP_PROP_MODE** Backend-specific value indicating the current capture mode.
  457. - **CAP_PROP_BRIGHTNESS** Brightness of the image (only for cameras).
  458. - **CAP_PROP_CONTRAST** Contrast of the image (only for cameras).
  459. - **CAP_PROP_SATURATION** Saturation of the image (only for cameras).
  460. - **CAP_PROP_HUE** Hue of the image (only for cameras).
  461. - **CAP_PROP_GAIN** Gain of the image (only for cameras).
  462. - **CAP_PROP_EXPOSURE** Exposure (only for cameras).
  463. - **CAP_PROP_CONVERT_RGB** Boolean flags indicating whether images should be converted
  464. to RGB.
  465. - **CAP_PROP_WHITE_BALANCE** Currently not supported
  466. - **CAP_PROP_RECTIFICATION** Rectification flag for stereo cameras (note: only supported
  467. by DC1394 v 2.x backend currently)
  468. @note When querying a property that is not supported by the backend used by the VideoCapture
  469. class, value 0 is returned.
  470. */
  471. CV_WRAP virtual double get(int propId) const;
  472. protected:
  473. Ptr<CvCapture> cap;
  474. Ptr<IVideoCapture> icap;
  475. };
  476. class IVideoWriter;
  477. /** @brief Video writer class.
  478. */
  479. class CV_EXPORTS_W VideoWriter
  480. {
  481. public:
  482. /** @brief VideoWriter constructors
  483. The constructors/functions initialize video writers. On Linux FFMPEG is used to write videos; on
  484. Windows FFMPEG or VFW is used; on MacOSX QTKit is used.
  485. */
  486. CV_WRAP VideoWriter();
  487. /** @overload
  488. @param filename Name of the output video file.
  489. @param fourcc 4-character code of codec used to compress the frames. For example,
  490. VideoWriter::fourcc('P','I','M','1') is a MPEG-1 codec, VideoWriter::fourcc('M','J','P','G') is a
  491. motion-jpeg codec etc. List of codes can be obtained at [Video Codecs by
  492. FOURCC](http://www.fourcc.org/codecs.php) page.
  493. @param fps Framerate of the created video stream.
  494. @param frameSize Size of the video frames.
  495. @param isColor If it is not zero, the encoder will expect and encode color frames, otherwise it
  496. will work with grayscale frames (the flag is currently supported on Windows only).
  497. */
  498. CV_WRAP VideoWriter(const String& filename, int fourcc, double fps,
  499. Size frameSize, bool isColor = true);
  500. virtual ~VideoWriter();
  501. /** @brief Initializes or reinitializes video writer.
  502. The method opens video writer. Parameters are the same as in the constructor
  503. VideoWriter::VideoWriter.
  504. */
  505. CV_WRAP virtual bool open(const String& filename, int fourcc, double fps,
  506. Size frameSize, bool isColor = true);
  507. /** @brief Returns true if video writer has been successfully initialized.
  508. */
  509. CV_WRAP virtual bool isOpened() const;
  510. /** @brief Closes the video writer.
  511. The methods are automatically called by subsequent VideoWriter::open and by the VideoWriter
  512. destructor.
  513. */
  514. CV_WRAP virtual void release();
  515. virtual VideoWriter& operator << (const Mat& image);
  516. /** @brief Writes the next video frame
  517. @param image The written frame
  518. The functions/methods write the specified image to video file. It must have the same size as has
  519. been specified when opening the video writer.
  520. */
  521. CV_WRAP virtual void write(const Mat& image);
  522. /** @brief Sets a property in the VideoWriter.
  523. @param propId Property identifier. It can be one of the following:
  524. - **VIDEOWRITER_PROP_QUALITY** Quality (0..100%) of the videostream encoded. Can be adjusted dynamically in some codecs.
  525. @param value Value of the property.
  526. */
  527. CV_WRAP virtual bool set(int propId, double value);
  528. /** @brief Returns the specified VideoWriter property
  529. @param propId Property identifier. It can be one of the following:
  530. - **VIDEOWRITER_PROP_QUALITY** Current quality of the encoded videostream.
  531. - **VIDEOWRITER_PROP_FRAMEBYTES** (Read-only) Size of just encoded video frame; note that the encoding order may be different from representation order.
  532. @note When querying a property that is not supported by the backend used by the VideoWriter
  533. class, value 0 is returned.
  534. */
  535. CV_WRAP virtual double get(int propId) const;
  536. /** @brief Concatenates 4 chars to a fourcc code
  537. This static method constructs the fourcc code of the codec to be used in the constructor
  538. VideoWriter::VideoWriter or VideoWriter::open.
  539. */
  540. CV_WRAP static int fourcc(char c1, char c2, char c3, char c4);
  541. protected:
  542. Ptr<CvVideoWriter> writer;
  543. Ptr<IVideoWriter> iwriter;
  544. static Ptr<IVideoWriter> create(const String& filename, int fourcc, double fps,
  545. Size frameSize, bool isColor = true);
  546. };
  547. template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
  548. template<> CV_EXPORTS void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const;
  549. //! @} videoio
  550. } // cv
  551. #endif //__OPENCV_VIDEOIO_HPP__