2010-05-12 01:44:00 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Intel License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
2014-02-17 21:50:15 +08:00
|
|
|
#include "cap_intelperc.hpp"
|
2014-07-08 16:21:54 +08:00
|
|
|
#include "cap_dshow.hpp"
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2015-05-15 21:28:47 +08:00
|
|
|
// All WinRT versions older than 8.0 should provide classes used for video support
|
2015-12-18 04:15:59 +08:00
|
|
|
#if defined(WINRT) && !defined(WINRT_8_0) && defined(__cplusplus_winrt)
|
2015-05-15 21:28:47 +08:00
|
|
|
# include "cap_winrt_capture.hpp"
|
|
|
|
# include "cap_winrt_bridge.hpp"
|
|
|
|
# define WINRT_VIDEO
|
|
|
|
#endif
|
|
|
|
|
2010-07-17 06:38:57 +08:00
|
|
|
#if defined _M_X64 && defined _MSC_VER && !defined CV_ICC
|
2010-05-12 01:44:00 +08:00
|
|
|
#pragma optimize("",off)
|
2012-06-12 22:46:12 +08:00
|
|
|
#pragma warning(disable: 4748)
|
2010-05-12 01:44:00 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
|
2013-08-13 20:47:18 +08:00
|
|
|
template<> void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const
|
2010-05-12 01:44:00 +08:00
|
|
|
{ cvReleaseCapture(&obj); }
|
|
|
|
|
2013-08-13 20:47:18 +08:00
|
|
|
template<> void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const
|
2010-05-12 01:44:00 +08:00
|
|
|
{ cvReleaseVideoWriter(&obj); }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************* Reading AVIs & Camera data **************************/
|
|
|
|
|
2014-12-11 01:17:35 +08:00
|
|
|
static inline double icvGetCaptureProperty( const CvCapture* capture, int id )
|
|
|
|
{
|
|
|
|
return capture ? capture->getProperty(id) : 0;
|
|
|
|
}
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
CV_IMPL void cvReleaseCapture( CvCapture** pcapture )
|
|
|
|
{
|
|
|
|
if( pcapture && *pcapture )
|
|
|
|
{
|
|
|
|
delete *pcapture;
|
|
|
|
*pcapture = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL IplImage* cvQueryFrame( CvCapture* capture )
|
|
|
|
{
|
2011-05-30 05:02:53 +08:00
|
|
|
if(!capture)
|
|
|
|
return 0;
|
|
|
|
if(!capture->grabFrame())
|
|
|
|
return 0;
|
|
|
|
return capture->retrieveFrame(0);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CV_IMPL int cvGrabFrame( CvCapture* capture )
|
|
|
|
{
|
|
|
|
return capture ? capture->grabFrame() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL IplImage* cvRetrieveFrame( CvCapture* capture, int idx )
|
|
|
|
{
|
|
|
|
return capture ? capture->retrieveFrame(idx) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL double cvGetCaptureProperty( CvCapture* capture, int id )
|
|
|
|
{
|
2014-12-11 01:17:35 +08:00
|
|
|
return icvGetCaptureProperty(capture, id);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL int cvSetCaptureProperty( CvCapture* capture, int id, double value )
|
|
|
|
{
|
|
|
|
return capture ? capture->setProperty(id, value) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL int cvGetCaptureDomain( CvCapture* capture)
|
|
|
|
{
|
|
|
|
return capture ? capture->getCaptureDomain() : 0;
|
|
|
|
}
|
|
|
|
|
2016-04-04 19:09:04 +08:00
|
|
|
static bool get_capture_debug_flag()
|
|
|
|
{
|
|
|
|
static bool initialized = false;
|
|
|
|
static bool flag = false;
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
#ifndef NO_GETENV
|
|
|
|
flag = getenv("OPENCV_VIDEOCAPTURE_DEBUG") ? true : false; // TODO Use getBoolParameter
|
|
|
|
#endif
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TRY_OPEN(capture, backend_func) \
|
|
|
|
{ \
|
|
|
|
if (!capture) \
|
|
|
|
try { \
|
|
|
|
if (get_capture_debug_flag()) fprintf(stderr, "VIDEOIO(%s): trying ...\n", #backend_func); \
|
|
|
|
capture = backend_func; \
|
|
|
|
if (get_capture_debug_flag()) fprintf(stderr, "VIDEOIO(%s): result=%p ...\n", #backend_func, capture); \
|
|
|
|
} catch (const cv::Exception& e) { \
|
|
|
|
fprintf(stderr, "VIDEOIO(%s): raised OpenCV exception:\n\n%s\n", #backend_func, e.what()); \
|
|
|
|
} catch (const std::exception& e) { \
|
|
|
|
fprintf(stderr, "VIDEOIO(%s): raised C++ exception:\n\n%s\n", #backend_func, e.what()); \
|
|
|
|
} catch (...) { \
|
|
|
|
fprintf(stderr, "VIDEOIO(%s): raised unknown C++ exception!\n\n", #backend_func); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Camera dispatching method: index is the camera number.
|
|
|
|
* If given an index from 0 to 99, it tries to find the first
|
|
|
|
* API that can access a given camera index.
|
|
|
|
* Add multiples of 100 to select an API.
|
|
|
|
*/
|
|
|
|
CV_IMPL CvCapture * cvCreateCameraCapture (int index)
|
|
|
|
{
|
|
|
|
// interpret preferred interface (0 = autodetect)
|
|
|
|
int pref = (index / 100) * 100;
|
|
|
|
|
2015-08-14 19:40:24 +08:00
|
|
|
// remove pref from index
|
|
|
|
index -= pref;
|
|
|
|
|
2015-06-26 18:18:11 +08:00
|
|
|
// local variable to memorize the captured device
|
|
|
|
CvCapture *capture = 0;
|
|
|
|
|
|
|
|
switch (pref)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2015-06-26 18:18:11 +08:00
|
|
|
default:
|
|
|
|
// user specified an API we do not know
|
|
|
|
// bail out to let the user know that it is not available
|
|
|
|
if (pref) break;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-05-22 19:21:23 +08:00
|
|
|
#ifdef HAVE_MSMF
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_MSMF:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_MSMF(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_TYZX
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_STEREO:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_TYZX(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_VFW:
|
2013-07-09 20:07:55 +08:00
|
|
|
#ifdef HAVE_VFW
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_VFW(index))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2016-04-04 19:09:04 +08:00
|
|
|
|
2012-09-17 18:03:35 +08:00
|
|
|
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_V4L(index))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2016-11-30 03:31:34 +08:00
|
|
|
if (pref) break; // CV_CAP_VFW
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_GSTREAMER
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, reinterpret_cast<char *>(index)))
|
2015-06-26 18:18:11 +08:00
|
|
|
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L, reinterpret_cast<char *>(index)))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_FIREWIRE:
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_DC1394_2
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_DC1394_2(index))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_DC1394
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_DC1394(index))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CMU1394
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_CMU(index))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_GSTREAMER) && 0
|
2015-06-26 18:18:11 +08:00
|
|
|
// Re-enable again when gstreamer 1394 support will land in the backend code
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_1394, 0))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2016-04-04 19:09:04 +08:00
|
|
|
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break; // CV_CAP_FIREWIRE
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_MIL
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_MIL:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_MIL(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-08-14 19:33:47 +08:00
|
|
|
#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_QT:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_QT(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_UNICAP
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_UNICAP:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_Unicap(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_PVAPI
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_PVAPI:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_PvAPI(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2011-01-22 01:00:08 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_OPENNI
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_OPENNI:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_OpenNI(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2011-04-06 22:31:03 +08:00
|
|
|
|
2014-07-01 16:07:01 +08:00
|
|
|
#ifdef HAVE_OPENNI2
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_OPENNI2:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_OpenNI2(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2014-07-01 16:07:01 +08:00
|
|
|
#endif
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_XIMEA
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_XIAPI:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_XIMEA(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2011-08-23 19:19:58 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_AVFOUNDATION:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_AVFoundation(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2013-02-01 20:40:02 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_GIGE_API
|
2015-06-26 18:18:11 +08:00
|
|
|
case CV_CAP_GIGANETIX:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_Giganetix(index))
|
2015-06-26 18:18:11 +08:00
|
|
|
if (pref) break; // CV_CAP_GIGANETIX
|
2013-02-01 20:40:02 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2016-10-08 03:55:49 +08:00
|
|
|
#ifdef HAVE_ARAVIS_API
|
|
|
|
case CV_CAP_ARAVIS:
|
|
|
|
TRY_OPEN(capture, cvCreateCameraCapture_Aravis(index))
|
|
|
|
if (pref) break;
|
|
|
|
#endif
|
2016-10-08 04:22:46 +08:00
|
|
|
}
|
2016-10-08 03:55:49 +08:00
|
|
|
|
2015-06-26 18:18:11 +08:00
|
|
|
return capture;
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Videoreader dispatching method: it tries to find the first
|
|
|
|
* API that can access a given filename.
|
|
|
|
*/
|
2015-05-12 23:43:28 +08:00
|
|
|
CV_IMPL CvCapture * cvCreateFileCaptureWithPreference (const char * filename, int apiPreference)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
|
|
|
CvCapture * result = 0;
|
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
switch(apiPreference) {
|
|
|
|
default:
|
2015-06-26 18:04:56 +08:00
|
|
|
// user specified an API we do not know
|
|
|
|
// bail out to let the user know that it is not available
|
|
|
|
if (apiPreference) break;
|
|
|
|
|
2014-09-29 06:39:35 +08:00
|
|
|
#ifdef HAVE_FFMPEG
|
2015-06-26 18:04:56 +08:00
|
|
|
case CV_CAP_FFMPEG:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_FFMPEG_proxy (filename))
|
2015-06-26 18:04:56 +08:00
|
|
|
if (apiPreference) break;
|
2014-09-29 06:39:35 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
|
|
|
|
case CV_CAP_VFW:
|
2016-11-30 03:31:34 +08:00
|
|
|
#ifdef HAVE_VFW
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_VFW (filename))
|
2013-05-14 20:17:34 +08:00
|
|
|
#endif
|
2016-11-30 03:31:34 +08:00
|
|
|
|
2016-04-12 13:00:37 +08:00
|
|
|
#if defined HAVE_LIBV4L || defined HAVE_CAMV4L || defined HAVE_CAMV4L2 || defined HAVE_VIDEOIO
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateCameraCapture_V4L(filename))
|
2016-04-12 13:00:37 +08:00
|
|
|
#endif
|
2016-11-30 03:31:34 +08:00
|
|
|
if (apiPreference) break;
|
2015-06-26 18:04:56 +08:00
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
case CV_CAP_MSMF:
|
2013-05-22 19:21:23 +08:00
|
|
|
#ifdef HAVE_MSMF
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_MSMF (filename))
|
2013-05-14 20:17:34 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_XINE
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_XINE (filename))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
if (apiPreference) break;
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_GSTREAMER
|
2015-06-26 18:04:56 +08:00
|
|
|
case CV_CAP_GSTREAMER:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename))
|
2015-06-26 18:04:56 +08:00
|
|
|
if (apiPreference) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
|
2013-08-14 19:33:47 +08:00
|
|
|
#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
|
2015-06-26 18:04:56 +08:00
|
|
|
case CV_CAP_QT:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_QT (filename))
|
2015-06-26 18:04:56 +08:00
|
|
|
if (apiPreference) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2015-06-26 18:04:56 +08:00
|
|
|
case CV_CAP_AVFOUNDATION:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_AVFoundation (filename))
|
2015-06-26 18:04:56 +08:00
|
|
|
if (apiPreference) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
#ifdef HAVE_OPENNI
|
2015-06-26 18:04:56 +08:00
|
|
|
case CV_CAP_OPENNI:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_OpenNI (filename))
|
2015-06-26 18:04:56 +08:00
|
|
|
if (apiPreference) break;
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2015-06-26 18:04:56 +08:00
|
|
|
|
2016-09-15 20:20:02 +08:00
|
|
|
#ifdef HAVE_OPENNI2
|
|
|
|
case CV_CAP_OPENNI2:
|
|
|
|
TRY_OPEN(result, cvCreateFileCapture_OpenNI2 (filename))
|
|
|
|
if (apiPreference) break;
|
|
|
|
#endif
|
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
case CV_CAP_IMAGES:
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateFileCapture_Images (filename))
|
2015-05-12 23:43:28 +08:00
|
|
|
}
|
2010-05-12 01:44:00 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
|
|
|
|
{
|
|
|
|
return cvCreateFileCaptureWithPreference(filename, CV_CAP_ANY);
|
|
|
|
}
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
/**
|
|
|
|
* Videowriter dispatching method: it tries to find the first
|
|
|
|
* API that can write a given stream.
|
|
|
|
*/
|
|
|
|
CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
|
|
|
|
double fps, CvSize frameSize, int is_color )
|
|
|
|
{
|
2016-04-04 19:09:04 +08:00
|
|
|
// If none of the writers is used
|
|
|
|
// these statements suppress 'unused parameter' warnings.
|
|
|
|
CV_UNUSED(frameSize);
|
|
|
|
CV_UNUSED(is_color);
|
|
|
|
|
2012-06-08 01:21:29 +08:00
|
|
|
//CV_FUNCNAME( "cvCreateVideoWriter" );
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-06-08 01:21:29 +08:00
|
|
|
CvVideoWriter *result = 0;
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-06-08 01:21:29 +08:00
|
|
|
if(!fourcc || !fps)
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_Images(filename))
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2014-09-29 06:39:35 +08:00
|
|
|
#ifdef HAVE_FFMPEG
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_FFMPEG_proxy (filename, fourcc, fps, frameSize, is_color))
|
2014-09-29 06:39:35 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-05-06 18:36:51 +08:00
|
|
|
#ifdef HAVE_VFW
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_VFW(filename, fourcc, fps, frameSize, is_color))
|
2013-05-06 18:36:51 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_MSMF
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_MSMF(filename, fourcc, fps, frameSize, is_color))
|
2013-05-06 18:36:51 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-06-08 01:21:29 +08:00
|
|
|
/* #ifdef HAVE_XINE
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color))
|
2012-06-08 01:21:29 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
*/
|
2012-06-08 01:21:29 +08:00
|
|
|
#ifdef HAVE_AVFOUNDATION
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_AVFoundation(filename, fourcc, fps, frameSize, is_color))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2013-08-14 19:33:47 +08:00
|
|
|
#if defined(HAVE_QUICKTIME) || defined(HAVE_QTKIT)
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color))
|
2012-04-30 22:33:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_GSTREAMER
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_GStreamer(filename, fourcc, fps, frameSize, is_color))
|
2014-09-29 06:39:35 +08:00
|
|
|
#endif
|
|
|
|
|
2016-04-04 19:09:04 +08:00
|
|
|
TRY_OPEN(result, cvCreateVideoWriter_Images(filename))
|
2010-05-12 01:44:00 +08:00
|
|
|
|
2012-06-08 01:21:29 +08:00
|
|
|
return result;
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL int cvWriteFrame( CvVideoWriter* writer, const IplImage* image )
|
|
|
|
{
|
|
|
|
return writer ? writer->writeFrame(image) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** pwriter )
|
|
|
|
{
|
|
|
|
if( pwriter && *pwriter )
|
|
|
|
{
|
|
|
|
delete *pwriter;
|
|
|
|
*pwriter = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
|
2015-03-26 05:39:29 +08:00
|
|
|
static Ptr<IVideoCapture> IVideoCapture_create(int index)
|
|
|
|
{
|
|
|
|
int domains[] =
|
|
|
|
{
|
|
|
|
#ifdef HAVE_DSHOW
|
|
|
|
CV_CAP_DSHOW,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_INTELPERC
|
|
|
|
CV_CAP_INTELPERC,
|
2015-05-15 21:28:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef WINRT_VIDEO
|
|
|
|
CAP_WINRT,
|
2015-05-21 06:41:39 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GPHOTO2
|
|
|
|
CV_CAP_GPHOTO2,
|
2015-03-26 05:39:29 +08:00
|
|
|
#endif
|
|
|
|
-1, -1
|
|
|
|
};
|
|
|
|
|
|
|
|
// interpret preferred interface (0 = autodetect)
|
|
|
|
int pref = (index / 100) * 100;
|
|
|
|
if (pref)
|
|
|
|
{
|
|
|
|
domains[0]=pref;
|
|
|
|
index %= 100;
|
|
|
|
domains[1]=-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try every possibly installed camera API
|
|
|
|
for (int i = 0; domains[i] >= 0; i++)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_DSHOW) || \
|
|
|
|
defined(HAVE_INTELPERC) || \
|
2015-05-21 06:41:39 +08:00
|
|
|
defined(WINRT_VIDEO) || \
|
|
|
|
defined(HAVE_GPHOTO2) || \
|
2015-03-26 05:39:29 +08:00
|
|
|
(0)
|
|
|
|
Ptr<IVideoCapture> capture;
|
|
|
|
|
|
|
|
switch (domains[i])
|
|
|
|
{
|
|
|
|
#ifdef HAVE_DSHOW
|
|
|
|
case CV_CAP_DSHOW:
|
|
|
|
capture = makePtr<VideoCapture_DShow>(index);
|
|
|
|
break; // CV_CAP_DSHOW
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_INTELPERC
|
|
|
|
case CV_CAP_INTELPERC:
|
|
|
|
capture = makePtr<VideoCapture_IntelPerC>();
|
|
|
|
break; // CV_CAP_INTEL_PERC
|
2015-05-15 21:28:47 +08:00
|
|
|
#endif
|
|
|
|
#ifdef WINRT_VIDEO
|
|
|
|
case CAP_WINRT:
|
|
|
|
capture = Ptr<IVideoCapture>(new cv::VideoCapture_WinRT(index));
|
|
|
|
if (capture)
|
|
|
|
return capture;
|
|
|
|
break; // CAP_WINRT
|
2015-05-21 06:41:39 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GPHOTO2
|
|
|
|
case CV_CAP_GPHOTO2:
|
|
|
|
capture = createGPhoto2Capture(index);
|
|
|
|
break;
|
2015-03-26 05:39:29 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (capture && capture->isOpened())
|
|
|
|
return capture;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// failed open a camera
|
|
|
|
return Ptr<IVideoCapture>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-23 19:40:44 +08:00
|
|
|
static Ptr<IVideoCapture> IVideoCapture_create(const String& filename)
|
2015-04-06 23:19:22 +08:00
|
|
|
{
|
2015-05-21 06:41:39 +08:00
|
|
|
int domains[] =
|
|
|
|
{
|
|
|
|
CV_CAP_ANY,
|
|
|
|
#ifdef HAVE_GPHOTO2
|
|
|
|
CV_CAP_GPHOTO2,
|
|
|
|
#endif
|
|
|
|
-1, -1
|
|
|
|
};
|
2015-04-06 23:19:22 +08:00
|
|
|
|
2015-05-21 06:41:39 +08:00
|
|
|
// try every possibly installed camera API
|
|
|
|
for (int i = 0; domains[i] >= 0; i++)
|
2015-04-06 23:19:22 +08:00
|
|
|
{
|
2015-05-21 06:41:39 +08:00
|
|
|
Ptr<IVideoCapture> capture;
|
|
|
|
|
|
|
|
switch (domains[i])
|
|
|
|
{
|
|
|
|
case CV_CAP_ANY:
|
|
|
|
capture = createMotionJpegCapture(filename);
|
|
|
|
break;
|
|
|
|
#ifdef HAVE_GPHOTO2
|
|
|
|
case CV_CAP_GPHOTO2:
|
|
|
|
capture = createGPhoto2Capture(filename);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
2015-04-06 23:19:22 +08:00
|
|
|
|
2015-05-21 06:41:39 +08:00
|
|
|
if (capture && capture->isOpened())
|
|
|
|
{
|
|
|
|
return capture;
|
|
|
|
}
|
|
|
|
}
|
2015-04-06 23:19:22 +08:00
|
|
|
// failed open a camera
|
|
|
|
return Ptr<IVideoCapture>();
|
|
|
|
}
|
|
|
|
|
2015-03-26 05:39:29 +08:00
|
|
|
static Ptr<IVideoWriter> IVideoWriter_create(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
|
|
|
{
|
|
|
|
Ptr<IVideoWriter> iwriter;
|
|
|
|
if( _fourcc == CV_FOURCC('M', 'J', 'P', 'G') )
|
|
|
|
iwriter = createMotionJpegWriter(filename, fps, frameSize, isColor);
|
|
|
|
return iwriter;
|
|
|
|
}
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
VideoCapture::VideoCapture()
|
|
|
|
{}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
VideoCapture::VideoCapture(const String& filename, int apiPreference)
|
|
|
|
{
|
|
|
|
open(filename, apiPreference);
|
|
|
|
}
|
|
|
|
|
2013-03-23 00:37:49 +08:00
|
|
|
VideoCapture::VideoCapture(const String& filename)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2015-05-12 23:43:28 +08:00
|
|
|
open(filename, CAP_ANY);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
VideoCapture::VideoCapture(int index)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2015-05-12 23:43:28 +08:00
|
|
|
open(index);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoCapture::~VideoCapture()
|
|
|
|
{
|
2014-02-17 21:50:15 +08:00
|
|
|
icap.release();
|
2010-05-12 01:44:00 +08:00
|
|
|
cap.release();
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
bool VideoCapture::open(const String& filename, int apiPreference)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2013-07-10 21:43:47 +08:00
|
|
|
if (isOpened()) release();
|
2015-04-06 23:19:22 +08:00
|
|
|
icap = IVideoCapture_create(filename);
|
|
|
|
if (!icap.empty())
|
|
|
|
return true;
|
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
cap.reset(cvCreateFileCaptureWithPreference(filename.c_str(), apiPreference));
|
2010-05-12 01:44:00 +08:00
|
|
|
return isOpened();
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
bool VideoCapture::open(const String& filename)
|
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2015-05-12 23:43:28 +08:00
|
|
|
return open(filename, CAP_ANY);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoCapture::open(int index)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2013-07-10 21:43:47 +08:00
|
|
|
if (isOpened()) release();
|
2015-05-12 23:43:28 +08:00
|
|
|
icap = IVideoCapture_create(index);
|
2014-02-17 21:50:15 +08:00
|
|
|
if (!icap.empty())
|
|
|
|
return true;
|
2015-05-12 23:43:28 +08:00
|
|
|
cap.reset(cvCreateCameraCapture(index));
|
2010-05-12 01:44:00 +08:00
|
|
|
return isOpened();
|
|
|
|
}
|
2016-11-09 19:19:57 +08:00
|
|
|
bool VideoCapture::open(int cameraNum, int apiPreference)
|
|
|
|
{
|
|
|
|
cameraNum = cameraNum + apiPreference;
|
|
|
|
return open(cameraNum);
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2014-02-17 21:50:15 +08:00
|
|
|
bool VideoCapture::isOpened() const
|
|
|
|
{
|
|
|
|
return (!cap.empty() || !icap.empty());
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
void VideoCapture::release()
|
|
|
|
{
|
2014-02-17 21:50:15 +08:00
|
|
|
icap.release();
|
2010-05-12 01:44:00 +08:00
|
|
|
cap.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoCapture::grab()
|
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2014-02-17 21:50:15 +08:00
|
|
|
if (!icap.empty())
|
|
|
|
return icap->grabFrame();
|
2010-05-12 01:44:00 +08:00
|
|
|
return cvGrabFrame(cap) != 0;
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
bool VideoCapture::retrieve(OutputArray image, int channel)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2014-02-17 21:50:15 +08:00
|
|
|
if (!icap.empty())
|
|
|
|
return icap->retrieveFrame(channel, image);
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
IplImage* _img = cvRetrieveFrame(cap, channel);
|
|
|
|
if( !_img )
|
|
|
|
{
|
|
|
|
image.release();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(_img->origin == IPL_ORIGIN_TL)
|
2013-11-11 20:55:36 +08:00
|
|
|
cv::cvarrToMat(_img).copyTo(image);
|
2010-05-12 01:44:00 +08:00
|
|
|
else
|
|
|
|
{
|
2013-03-29 01:01:12 +08:00
|
|
|
Mat temp = cv::cvarrToMat(_img);
|
2010-05-12 01:44:00 +08:00
|
|
|
flip(temp, image, 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-03 01:58:22 +08:00
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
bool VideoCapture::read(OutputArray image)
|
2010-11-03 01:58:22 +08:00
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2012-06-01 16:55:16 +08:00
|
|
|
if(grab())
|
|
|
|
retrieve(image);
|
2012-05-06 01:28:05 +08:00
|
|
|
else
|
|
|
|
image.release();
|
2010-11-03 01:58:22 +08:00
|
|
|
return !image.empty();
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
VideoCapture& VideoCapture::operator >> (Mat& image)
|
|
|
|
{
|
2015-05-15 21:28:47 +08:00
|
|
|
#ifdef WINRT_VIDEO
|
|
|
|
if (grab())
|
|
|
|
{
|
|
|
|
if (retrieve(image))
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(VideoioBridge::getInstance().inputBufferMutex);
|
|
|
|
VideoioBridge& bridge = VideoioBridge::getInstance();
|
|
|
|
|
|
|
|
// double buffering
|
|
|
|
bridge.swapInputBuffers();
|
|
|
|
auto p = bridge.frontInputPtr;
|
|
|
|
|
|
|
|
bridge.bIsFrameNew = false;
|
|
|
|
|
|
|
|
// needed here because setting Mat 'image' is not allowed by OutputArray in read()
|
2015-05-18 20:21:49 +08:00
|
|
|
Mat m(bridge.getHeight(), bridge.getWidth(), CV_8UC3, p);
|
2015-05-15 21:28:47 +08:00
|
|
|
image = m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2012-05-22 15:58:31 +08:00
|
|
|
read(image);
|
2015-05-15 21:28:47 +08:00
|
|
|
#endif
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
return *this;
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
VideoCapture& VideoCapture::operator >> (UMat& image)
|
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2013-11-19 00:48:00 +08:00
|
|
|
read(image);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
bool VideoCapture::set(int propId, double value)
|
|
|
|
{
|
2014-02-17 21:50:15 +08:00
|
|
|
if (!icap.empty())
|
|
|
|
return icap->setProperty(propId, value);
|
2010-05-12 01:44:00 +08:00
|
|
|
return cvSetCaptureProperty(cap, propId, value) != 0;
|
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2014-12-11 01:17:35 +08:00
|
|
|
double VideoCapture::get(int propId) const
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2014-02-17 21:50:15 +08:00
|
|
|
if (!icap.empty())
|
|
|
|
return icap->getProperty(propId);
|
2014-12-11 01:17:35 +08:00
|
|
|
return icvGetCaptureProperty(cap, propId);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
2014-02-17 21:50:15 +08:00
|
|
|
|
2010-05-12 01:44:00 +08:00
|
|
|
VideoWriter::VideoWriter()
|
|
|
|
{}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2013-04-08 02:45:38 +08:00
|
|
|
VideoWriter::VideoWriter(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2013-04-08 02:45:38 +08:00
|
|
|
open(filename, _fourcc, fps, frameSize, isColor);
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
void VideoWriter::release()
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2015-03-26 05:39:29 +08:00
|
|
|
iwriter.release();
|
2010-05-12 01:44:00 +08:00
|
|
|
writer.release();
|
2012-06-08 01:21:29 +08:00
|
|
|
}
|
|
|
|
|
2012-04-14 05:50:59 +08:00
|
|
|
VideoWriter::~VideoWriter()
|
|
|
|
{
|
|
|
|
release();
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2013-04-08 02:45:38 +08:00
|
|
|
bool VideoWriter::open(const String& filename, int _fourcc, double fps, Size frameSize, bool isColor)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2015-03-26 05:39:29 +08:00
|
|
|
if (isOpened()) release();
|
|
|
|
iwriter = IVideoWriter_create(filename, _fourcc, fps, frameSize, isColor);
|
|
|
|
if (!iwriter.empty())
|
|
|
|
return true;
|
2013-08-13 20:47:18 +08:00
|
|
|
writer.reset(cvCreateVideoWriter(filename.c_str(), _fourcc, fps, frameSize, isColor));
|
2010-05-12 01:44:00 +08:00
|
|
|
return isOpened();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoWriter::isOpened() const
|
|
|
|
{
|
2015-03-26 05:39:29 +08:00
|
|
|
return !iwriter.empty() || !writer.empty();
|
2012-06-08 01:21:29 +08:00
|
|
|
}
|
2010-11-03 01:58:22 +08:00
|
|
|
|
2015-03-27 20:15:59 +08:00
|
|
|
|
|
|
|
bool VideoWriter::set(int propId, double value)
|
|
|
|
{
|
|
|
|
if (!iwriter.empty())
|
|
|
|
return iwriter->setProperty(propId, value);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double VideoWriter::get(int propId) const
|
|
|
|
{
|
|
|
|
if (!iwriter.empty())
|
|
|
|
return iwriter->getProperty(propId);
|
|
|
|
return 0.;
|
|
|
|
}
|
|
|
|
|
2010-11-03 01:58:22 +08:00
|
|
|
void VideoWriter::write(const Mat& image)
|
2010-05-12 01:44:00 +08:00
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2015-03-26 05:39:29 +08:00
|
|
|
if( iwriter )
|
|
|
|
iwriter->write(image);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IplImage _img = image;
|
|
|
|
cvWriteFrame(writer, &_img);
|
|
|
|
}
|
2010-11-03 01:58:22 +08:00
|
|
|
}
|
2012-06-08 01:21:29 +08:00
|
|
|
|
2010-11-03 01:58:22 +08:00
|
|
|
VideoWriter& VideoWriter::operator << (const Mat& image)
|
|
|
|
{
|
2016-08-18 14:53:00 +08:00
|
|
|
CV_INSTRUMENT_REGION()
|
|
|
|
|
2010-11-03 01:58:22 +08:00
|
|
|
write(image);
|
2012-06-08 01:21:29 +08:00
|
|
|
return *this;
|
2010-05-12 01:44:00 +08:00
|
|
|
}
|
|
|
|
|
2013-04-08 02:45:38 +08:00
|
|
|
int VideoWriter::fourcc(char c1, char c2, char c3, char c4)
|
|
|
|
{
|
|
|
|
return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24);
|
|
|
|
}
|
|
|
|
|
2015-05-21 06:41:39 +08:00
|
|
|
}
|