001// 002// This file is auto-generated. Please don't modify it! 003// 004package org.opencv.videoio; 005 006import java.util.ArrayList; 007import java.util.List; 008import org.opencv.core.Mat; 009import org.opencv.core.MatOfInt; 010import org.opencv.utils.Converters; 011 012// C++: class VideoCapture 013/** 014 * Class for video capturing from video files, image sequences or cameras. 015 * 016 * The class provides C++ API for capturing video from cameras or for reading video files and image sequences. 017 * 018 * Here is how the class can be used: 019 * INCLUDE: samples/cpp/videocapture_basic.cpp 020 * 021 * <b>Note:</b> In REF: videoio_c "C API" the black-box structure {@code CvCapture} is used instead of %VideoCapture. 022 * <b>Note:</b> 023 * <ul> 024 * <li> 025 * (C++) A basic sample on using the %VideoCapture interface can be found at 026 * {@code OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp} 027 * </li> 028 * <li> 029 * (Python) A basic sample on using the %VideoCapture interface can be found at 030 * {@code OPENCV_SOURCE_CODE/samples/python/video.py} 031 * </li> 032 * <li> 033 * (Python) A multi threaded video processing sample can be found at 034 * {@code OPENCV_SOURCE_CODE/samples/python/video_threaded.py} 035 * </li> 036 * <li> 037 * (Python) %VideoCapture sample showcasing some features of the Video4Linux2 backend 038 * {@code OPENCV_SOURCE_CODE/samples/python/video_v4l2.py} 039 * </li> 040 * </ul> 041 */ 042public class VideoCapture { 043 044 protected final long nativeObj; 045 protected VideoCapture(long addr) { nativeObj = addr; } 046 047 public long getNativeObjAddr() { return nativeObj; } 048 049 // internal usage only 050 public static VideoCapture __fromPtr__(long addr) { return new VideoCapture(addr); } 051 052 // 053 // C++: cv::VideoCapture::VideoCapture() 054 // 055 056 /** 057 * Default constructor 058 * <b>Note:</b> In REF: videoio_c "C API", when you finished working with video, release CvCapture structure with 059 * cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the 060 * destructor. 061 */ 062 public VideoCapture() { 063 nativeObj = VideoCapture_0(); 064 } 065 066 067 // 068 // C++: cv::VideoCapture::VideoCapture(String filename, int apiPreference = CAP_ANY) 069 // 070 071 /** 072 * 073 * Opens a video file or a capturing device or an IP video stream for video capturing with API Preference 074 * 075 * @param filename it can be: 076 * <ul> 077 * <li> 078 * name of video file (eg. {@code video.avi}) 079 * </li> 080 * <li> 081 * or image sequence (eg. {@code img_%02d.jpg}, which will read samples like {@code img_00.jpg, img_01.jpg, img_02.jpg, ...}) 082 * </li> 083 * <li> 084 * or URL of video stream (eg. {@code protocol://host:port/script_name?script_params|auth}) 085 * </li> 086 * <li> 087 * or GStreamer pipeline string in gst-launch tool format in case if GStreamer is used as backend 088 * Note that each video stream or IP camera feed has its own URL scheme. Please refer to the 089 * documentation of source stream to know the right URL. 090 * @param apiPreference preferred Capture API backends to use. Can be used to enforce a specific reader 091 * implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. 092 * </li> 093 * </ul> 094 * 095 * SEE: cv::VideoCaptureAPIs 096 */ 097 public VideoCapture(String filename, int apiPreference) { 098 nativeObj = VideoCapture_1(filename, apiPreference); 099 } 100 101 /** 102 * 103 * Opens a video file or a capturing device or an IP video stream for video capturing with API Preference 104 * 105 * @param filename it can be: 106 * <ul> 107 * <li> 108 * name of video file (eg. {@code video.avi}) 109 * </li> 110 * <li> 111 * or image sequence (eg. {@code img_%02d.jpg}, which will read samples like {@code img_00.jpg, img_01.jpg, img_02.jpg, ...}) 112 * </li> 113 * <li> 114 * or URL of video stream (eg. {@code protocol://host:port/script_name?script_params|auth}) 115 * </li> 116 * <li> 117 * or GStreamer pipeline string in gst-launch tool format in case if GStreamer is used as backend 118 * Note that each video stream or IP camera feed has its own URL scheme. Please refer to the 119 * documentation of source stream to know the right URL. 120 * implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. 121 * </li> 122 * </ul> 123 * 124 * SEE: cv::VideoCaptureAPIs 125 */ 126 public VideoCapture(String filename) { 127 nativeObj = VideoCapture_2(filename); 128 } 129 130 131 // 132 // C++: cv::VideoCapture::VideoCapture(String filename, int apiPreference, vector_int params) 133 // 134 135 /** 136 * 137 * Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters 138 * 139 * The {@code params} parameter allows to specify extra parameters encoded as pairs {@code (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)}. 140 * See cv::VideoCaptureProperties 141 * @param filename automatically generated 142 * @param apiPreference automatically generated 143 * @param params automatically generated 144 */ 145 public VideoCapture(String filename, int apiPreference, MatOfInt params) { 146 Mat params_mat = params; 147 nativeObj = VideoCapture_3(filename, apiPreference, params_mat.nativeObj); 148 } 149 150 151 // 152 // C++: cv::VideoCapture::VideoCapture(int index, int apiPreference = CAP_ANY) 153 // 154 155 /** 156 * 157 * Opens a camera for video capturing 158 * 159 * @param index id of the video capturing device to open. To open default camera using default backend just pass 0. 160 * (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY) 161 * @param apiPreference preferred Capture API backends to use. Can be used to enforce a specific reader 162 * implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L. 163 * 164 * SEE: cv::VideoCaptureAPIs 165 */ 166 public VideoCapture(int index, int apiPreference) { 167 nativeObj = VideoCapture_4(index, apiPreference); 168 } 169 170 /** 171 * 172 * Opens a camera for video capturing 173 * 174 * @param index id of the video capturing device to open. To open default camera using default backend just pass 0. 175 * (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY) 176 * implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L. 177 * 178 * SEE: cv::VideoCaptureAPIs 179 */ 180 public VideoCapture(int index) { 181 nativeObj = VideoCapture_5(index); 182 } 183 184 185 // 186 // C++: cv::VideoCapture::VideoCapture(int index, int apiPreference, vector_int params) 187 // 188 189 /** 190 * 191 * Opens a camera for video capturing with API Preference and parameters 192 * 193 * The {@code params} parameter allows to specify extra parameters encoded as pairs {@code (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)}. 194 * See cv::VideoCaptureProperties 195 * @param index automatically generated 196 * @param apiPreference automatically generated 197 * @param params automatically generated 198 */ 199 public VideoCapture(int index, int apiPreference, MatOfInt params) { 200 Mat params_mat = params; 201 nativeObj = VideoCapture_6(index, apiPreference, params_mat.nativeObj); 202 } 203 204 205 // 206 // C++: bool cv::VideoCapture::open(String filename, int apiPreference = CAP_ANY) 207 // 208 209 /** 210 * Opens a video file or a capturing device or an IP video stream for video capturing. 211 * 212 * 213 * 214 * Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY) 215 * @return {@code true} if the file has been successfully opened 216 * 217 * The method first calls VideoCapture::release to close the already opened file or camera. 218 * @param filename automatically generated 219 * @param apiPreference automatically generated 220 */ 221 public boolean open(String filename, int apiPreference) { 222 return open_0(nativeObj, filename, apiPreference); 223 } 224 225 /** 226 * Opens a video file or a capturing device or an IP video stream for video capturing. 227 * 228 * 229 * 230 * Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY) 231 * @return {@code true} if the file has been successfully opened 232 * 233 * The method first calls VideoCapture::release to close the already opened file or camera. 234 * @param filename automatically generated 235 */ 236 public boolean open(String filename) { 237 return open_1(nativeObj, filename); 238 } 239 240 241 // 242 // C++: bool cv::VideoCapture::open(String filename, int apiPreference, vector_int params) 243 // 244 245 /** 246 * Opens a camera for video capturing 247 * 248 * 249 * 250 * The {@code params} parameter allows to specify extra parameters encoded as pairs {@code (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)}. 251 * See cv::VideoCaptureProperties 252 * 253 * @return {@code true} if the file has been successfully opened 254 * 255 * The method first calls VideoCapture::release to close the already opened file or camera. 256 * @param filename automatically generated 257 * @param apiPreference automatically generated 258 * @param params automatically generated 259 */ 260 public boolean open(String filename, int apiPreference, MatOfInt params) { 261 Mat params_mat = params; 262 return open_2(nativeObj, filename, apiPreference, params_mat.nativeObj); 263 } 264 265 266 // 267 // C++: bool cv::VideoCapture::open(int index, int apiPreference = CAP_ANY) 268 // 269 270 /** 271 * Opens a camera for video capturing 272 * 273 * 274 * 275 * Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY) 276 * @return {@code true} if the camera has been successfully opened. 277 * 278 * The method first calls VideoCapture::release to close the already opened file or camera. 279 * @param index automatically generated 280 * @param apiPreference automatically generated 281 */ 282 public boolean open(int index, int apiPreference) { 283 return open_3(nativeObj, index, apiPreference); 284 } 285 286 /** 287 * Opens a camera for video capturing 288 * 289 * 290 * 291 * Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY) 292 * @return {@code true} if the camera has been successfully opened. 293 * 294 * The method first calls VideoCapture::release to close the already opened file or camera. 295 * @param index automatically generated 296 */ 297 public boolean open(int index) { 298 return open_4(nativeObj, index); 299 } 300 301 302 // 303 // C++: bool cv::VideoCapture::open(int index, int apiPreference, vector_int params) 304 // 305 306 /** 307 * Returns true if video capturing has been initialized already. 308 * 309 * 310 * 311 * The {@code params} parameter allows to specify extra parameters encoded as pairs {@code (paramId_1, paramValue_1, paramId_2, paramValue_2, ...)}. 312 * See cv::VideoCaptureProperties 313 * 314 * @return {@code true} if the camera has been successfully opened. 315 * 316 * The method first calls VideoCapture::release to close the already opened file or camera. 317 * @param index automatically generated 318 * @param apiPreference automatically generated 319 * @param params automatically generated 320 */ 321 public boolean open(int index, int apiPreference, MatOfInt params) { 322 Mat params_mat = params; 323 return open_5(nativeObj, index, apiPreference, params_mat.nativeObj); 324 } 325 326 327 // 328 // C++: bool cv::VideoCapture::isOpened() 329 // 330 331 /** 332 * Returns true if video capturing has been initialized already. 333 * 334 * If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns 335 * true. 336 * @return automatically generated 337 */ 338 public boolean isOpened() { 339 return isOpened_0(nativeObj); 340 } 341 342 343 // 344 // C++: void cv::VideoCapture::release() 345 // 346 347 /** 348 * Closes video file or capturing device. 349 * 350 * The method is automatically called by subsequent VideoCapture::open and by VideoCapture 351 * destructor. 352 * 353 * The C function also deallocates memory and clears \*capture pointer. 354 */ 355 public void release() { 356 release_0(nativeObj); 357 } 358 359 360 // 361 // C++: bool cv::VideoCapture::grab() 362 // 363 364 /** 365 * Grabs the next frame from video file or capturing device. 366 * 367 * @return {@code true} (non-zero) in the case of success. 368 * 369 * The method/function grabs the next frame from video file or camera and returns true (non-zero) in 370 * the case of success. 371 * 372 * The primary use of the function is in multi-camera environments, especially when the cameras do not 373 * have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that 374 * call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way 375 * the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames 376 * from different cameras will be closer in time. 377 * 378 * Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the 379 * correct way of retrieving data from it is to call VideoCapture::grab() first and then call 380 * VideoCapture::retrieve() one or more times with different values of the channel parameter. 381 * 382 * REF: tutorial_kinect_openni 383 */ 384 public boolean grab() { 385 return grab_0(nativeObj); 386 } 387 388 389 // 390 // C++: bool cv::VideoCapture::retrieve(Mat& image, int flag = 0) 391 // 392 393 /** 394 * Decodes and returns the grabbed video frame. 395 * 396 * @param flag it could be a frame index or a driver specific flag 397 * @return {@code false} if no frames has been grabbed 398 * 399 * The method decodes and returns the just grabbed frame. If no frames has been grabbed 400 * (camera has been disconnected, or there are no more frames in video file), the method returns false 401 * and the function returns an empty image (with %cv::Mat, test it with Mat::empty()). 402 * 403 * SEE: read() 404 * 405 * <b>Note:</b> In REF: videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video 406 * capturing structure. It is not allowed to modify or release the image! You can copy the frame using 407 * cvCloneImage and then do whatever you want with the copy. 408 * @param image automatically generated 409 */ 410 public boolean retrieve(Mat image, int flag) { 411 return retrieve_0(nativeObj, image.nativeObj, flag); 412 } 413 414 /** 415 * Decodes and returns the grabbed video frame. 416 * 417 * @return {@code false} if no frames has been grabbed 418 * 419 * The method decodes and returns the just grabbed frame. If no frames has been grabbed 420 * (camera has been disconnected, or there are no more frames in video file), the method returns false 421 * and the function returns an empty image (with %cv::Mat, test it with Mat::empty()). 422 * 423 * SEE: read() 424 * 425 * <b>Note:</b> In REF: videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video 426 * capturing structure. It is not allowed to modify or release the image! You can copy the frame using 427 * cvCloneImage and then do whatever you want with the copy. 428 * @param image automatically generated 429 */ 430 public boolean retrieve(Mat image) { 431 return retrieve_1(nativeObj, image.nativeObj); 432 } 433 434 435 // 436 // C++: bool cv::VideoCapture::read(Mat& image) 437 // 438 439 /** 440 * Grabs, decodes and returns the next video frame. 441 * 442 * @return {@code false} if no frames has been grabbed 443 * 444 * The method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the 445 * most convenient method for reading video files or capturing data from decode and returns the just 446 * grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more 447 * frames in video file), the method returns false and the function returns empty image (with %cv::Mat, test it with Mat::empty()). 448 * 449 * <b>Note:</b> In REF: videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video 450 * capturing structure. It is not allowed to modify or release the image! You can copy the frame using 451 * cvCloneImage and then do whatever you want with the copy. 452 * @param image automatically generated 453 */ 454 public boolean read(Mat image) { 455 return read_0(nativeObj, image.nativeObj); 456 } 457 458 459 // 460 // C++: bool cv::VideoCapture::set(int propId, double value) 461 // 462 463 /** 464 * Sets a property in the VideoCapture. 465 * 466 * @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) 467 * or one from REF: videoio_flags_others 468 * @param value Value of the property. 469 * @return {@code true} if the property is supported by backend used by the VideoCapture instance. 470 * <b>Note:</b> Even if it returns {@code true} this doesn't ensure that the property 471 * value has been accepted by the capture device. See note in VideoCapture::get() 472 */ 473 public boolean set(int propId, double value) { 474 return set_0(nativeObj, propId, value); 475 } 476 477 478 // 479 // C++: double cv::VideoCapture::get(int propId) 480 // 481 482 /** 483 * Returns the specified VideoCapture property 484 * 485 * @param propId Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) 486 * or one from REF: videoio_flags_others 487 * @return Value for the specified property. Value 0 is returned when querying a property that is 488 * not supported by the backend used by the VideoCapture instance. 489 * 490 * <b>Note:</b> Reading / writing properties involves many layers. Some unexpected result might happens 491 * along this chain. 492 * <code> 493 * VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware 494 * </code> 495 * The returned value might be different from what really used by the device or it could be encoded 496 * using device dependent rules (eg. steps or percentage). Effective behaviour depends from device 497 * driver and API Backend 498 */ 499 public double get(int propId) { 500 return get_0(nativeObj, propId); 501 } 502 503 504 // 505 // C++: String cv::VideoCapture::getBackendName() 506 // 507 508 /** 509 * Returns used backend API name 510 * 511 * <b>Note:</b> Stream should be opened. 512 * @return automatically generated 513 */ 514 public String getBackendName() { 515 return getBackendName_0(nativeObj); 516 } 517 518 519 // 520 // C++: void cv::VideoCapture::setExceptionMode(bool enable) 521 // 522 523 /** 524 * Switches exceptions mode 525 * 526 * methods raise exceptions if not successful instead of returning an error code 527 * @param enable automatically generated 528 */ 529 public void setExceptionMode(boolean enable) { 530 setExceptionMode_0(nativeObj, enable); 531 } 532 533 534 // 535 // C++: bool cv::VideoCapture::getExceptionMode() 536 // 537 538 public boolean getExceptionMode() { 539 return getExceptionMode_0(nativeObj); 540 } 541 542 543 @Override 544 protected void finalize() throws Throwable { 545 delete(nativeObj); 546 } 547 548 549 550 // C++: cv::VideoCapture::VideoCapture() 551 private static native long VideoCapture_0(); 552 553 // C++: cv::VideoCapture::VideoCapture(String filename, int apiPreference = CAP_ANY) 554 private static native long VideoCapture_1(String filename, int apiPreference); 555 private static native long VideoCapture_2(String filename); 556 557 // C++: cv::VideoCapture::VideoCapture(String filename, int apiPreference, vector_int params) 558 private static native long VideoCapture_3(String filename, int apiPreference, long params_mat_nativeObj); 559 560 // C++: cv::VideoCapture::VideoCapture(int index, int apiPreference = CAP_ANY) 561 private static native long VideoCapture_4(int index, int apiPreference); 562 private static native long VideoCapture_5(int index); 563 564 // C++: cv::VideoCapture::VideoCapture(int index, int apiPreference, vector_int params) 565 private static native long VideoCapture_6(int index, int apiPreference, long params_mat_nativeObj); 566 567 // C++: bool cv::VideoCapture::open(String filename, int apiPreference = CAP_ANY) 568 private static native boolean open_0(long nativeObj, String filename, int apiPreference); 569 private static native boolean open_1(long nativeObj, String filename); 570 571 // C++: bool cv::VideoCapture::open(String filename, int apiPreference, vector_int params) 572 private static native boolean open_2(long nativeObj, String filename, int apiPreference, long params_mat_nativeObj); 573 574 // C++: bool cv::VideoCapture::open(int index, int apiPreference = CAP_ANY) 575 private static native boolean open_3(long nativeObj, int index, int apiPreference); 576 private static native boolean open_4(long nativeObj, int index); 577 578 // C++: bool cv::VideoCapture::open(int index, int apiPreference, vector_int params) 579 private static native boolean open_5(long nativeObj, int index, int apiPreference, long params_mat_nativeObj); 580 581 // C++: bool cv::VideoCapture::isOpened() 582 private static native boolean isOpened_0(long nativeObj); 583 584 // C++: void cv::VideoCapture::release() 585 private static native void release_0(long nativeObj); 586 587 // C++: bool cv::VideoCapture::grab() 588 private static native boolean grab_0(long nativeObj); 589 590 // C++: bool cv::VideoCapture::retrieve(Mat& image, int flag = 0) 591 private static native boolean retrieve_0(long nativeObj, long image_nativeObj, int flag); 592 private static native boolean retrieve_1(long nativeObj, long image_nativeObj); 593 594 // C++: bool cv::VideoCapture::read(Mat& image) 595 private static native boolean read_0(long nativeObj, long image_nativeObj); 596 597 // C++: bool cv::VideoCapture::set(int propId, double value) 598 private static native boolean set_0(long nativeObj, int propId, double value); 599 600 // C++: double cv::VideoCapture::get(int propId) 601 private static native double get_0(long nativeObj, int propId); 602 603 // C++: String cv::VideoCapture::getBackendName() 604 private static native String getBackendName_0(long nativeObj); 605 606 // C++: void cv::VideoCapture::setExceptionMode(bool enable) 607 private static native void setExceptionMode_0(long nativeObj, boolean enable); 608 609 // C++: bool cv::VideoCapture::getExceptionMode() 610 private static native boolean getExceptionMode_0(long nativeObj); 611 612 // native support for java finalize() 613 private static native void delete(long nativeObj); 614 615}