Commit b34d86ca authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #12548 from alalek:videoio_backend_name

parents 24ab7515 d3eed2cf
...@@ -169,6 +169,7 @@ enum VideoCaptureProperties { ...@@ -169,6 +169,7 @@ enum VideoCaptureProperties {
CAP_PROP_AUTOFOCUS =39, CAP_PROP_AUTOFOCUS =39,
CAP_PROP_SAR_NUM =40, //!< Sample aspect ratio: num/den (num) CAP_PROP_SAR_NUM =40, //!< Sample aspect ratio: num/den (num)
CAP_PROP_SAR_DEN =41, //!< Sample aspect ratio: num/den (den) CAP_PROP_SAR_DEN =41, //!< Sample aspect ratio: num/den (den)
CAP_PROP_BACKEND =42, //!< current backend (enum VideoCaptureAPIs). Read-only property
#ifndef CV_DOXYGEN #ifndef CV_DOXYGEN
CV__CAP_PROP_LATEST CV__CAP_PROP_LATEST
#endif #endif
...@@ -808,6 +809,12 @@ public: ...@@ -808,6 +809,12 @@ public:
*/ */
CV_WRAP virtual bool open(const String& filename, int apiPreference); CV_WRAP virtual bool open(const String& filename, int apiPreference);
/** @brief Returns used backend API name
@note Stream should be opened.
*/
CV_WRAP String getBackendName() const;
protected: protected:
Ptr<CvCapture> cap; Ptr<CvCapture> cap;
Ptr<IVideoCapture> icap; Ptr<IVideoCapture> icap;
...@@ -946,6 +953,12 @@ public: ...@@ -946,6 +953,12 @@ public:
*/ */
CV_WRAP static int fourcc(char c1, char c2, char c3, char c4); CV_WRAP static int fourcc(char c1, char c2, char c3, char c4);
/** @brief Returns used backend API name
@note Stream should be opened.
*/
CV_WRAP String getBackendName() const;
protected: protected:
Ptr<CvVideoWriter> writer; Ptr<CvVideoWriter> writer;
Ptr<IVideoWriter> iwriter; Ptr<IVideoWriter> iwriter;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "opencv2/videoio/registry.hpp"
#include "videoio_registry.hpp" #include "videoio_registry.hpp"
namespace cv { namespace cv {
...@@ -172,6 +173,17 @@ bool VideoCapture::isOpened() const ...@@ -172,6 +173,17 @@ bool VideoCapture::isOpened() const
return !cap.empty(); // legacy interface doesn't support closed files return !cap.empty(); // legacy interface doesn't support closed files
} }
String VideoCapture::getBackendName() const
{
int api = 0;
if (icap)
api = icap->isOpened() ? icap->getCaptureDomain() : 0;
else if (cap)
api = cap->getCaptureDomain();
CV_Assert(api != 0);
return cv::videoio_registry::getBackendName((VideoCaptureAPIs)api);
}
void VideoCapture::release() void VideoCapture::release()
{ {
CV_TRACE_FUNCTION(); CV_TRACE_FUNCTION();
...@@ -260,6 +272,8 @@ VideoCapture& VideoCapture::operator >> (UMat& image) ...@@ -260,6 +272,8 @@ VideoCapture& VideoCapture::operator >> (UMat& image)
bool VideoCapture::set(int propId, double value) bool VideoCapture::set(int propId, double value)
{ {
CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can set read-only property");
if (!icap.empty()) if (!icap.empty())
return icap->setProperty(propId, value); return icap->setProperty(propId, value);
return cvSetCaptureProperty(cap, propId, value) != 0; return cvSetCaptureProperty(cap, propId, value) != 0;
...@@ -267,6 +281,17 @@ bool VideoCapture::set(int propId, double value) ...@@ -267,6 +281,17 @@ bool VideoCapture::set(int propId, double value)
double VideoCapture::get(int propId) const double VideoCapture::get(int propId) const
{ {
if (propId == CAP_PROP_BACKEND)
{
int api = 0;
if (icap)
api = icap->isOpened() ? icap->getCaptureDomain() : 0;
else if (cap)
api = cap->getCaptureDomain();
if (api <= 0)
return -1.0;
return (double)api;
}
if (!icap.empty()) if (!icap.empty())
return icap->getProperty(propId); return icap->getProperty(propId);
return cap ? cap->getProperty(propId) : 0; return cap ? cap->getProperty(propId) : 0;
...@@ -346,6 +371,8 @@ bool VideoWriter::isOpened() const ...@@ -346,6 +371,8 @@ bool VideoWriter::isOpened() const
bool VideoWriter::set(int propId, double value) bool VideoWriter::set(int propId, double value)
{ {
CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can set read-only property");
if (!iwriter.empty()) if (!iwriter.empty())
return iwriter->setProperty(propId, value); return iwriter->setProperty(propId, value);
return false; return false;
...@@ -353,11 +380,33 @@ bool VideoWriter::set(int propId, double value) ...@@ -353,11 +380,33 @@ bool VideoWriter::set(int propId, double value)
double VideoWriter::get(int propId) const double VideoWriter::get(int propId) const
{ {
if (propId == CAP_PROP_BACKEND)
{
int api = 0;
if (iwriter)
api = iwriter->getCaptureDomain();
else if (writer)
api = writer->getCaptureDomain();
if (api <= 0)
return -1.0;
return (double)api;
}
if (!iwriter.empty()) if (!iwriter.empty())
return iwriter->getProperty(propId); return iwriter->getProperty(propId);
return 0.; return 0.;
} }
String VideoWriter::getBackendName() const
{
int api = 0;
if (iwriter)
api = iwriter->getCaptureDomain();
else if (writer)
api = writer->getCaptureDomain();
CV_Assert(api != 0);
return cv::videoio_registry::getBackendName((VideoCaptureAPIs)api);
}
void VideoWriter::write(const Mat& image) void VideoWriter::write(const Mat& image)
{ {
CV_INSTRUMENT_REGION(); CV_INSTRUMENT_REGION();
......
...@@ -174,6 +174,7 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter{ ...@@ -174,6 +174,7 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter{
int is_color=1); int is_color=1);
~CvVideoWriter_AVFoundation(); ~CvVideoWriter_AVFoundation();
bool writeFrame(const IplImage* image); bool writeFrame(const IplImage* image);
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_AVFOUNDATION; }
private: private:
IplImage* argbimage; IplImage* argbimage;
......
...@@ -182,6 +182,7 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter { ...@@ -182,6 +182,7 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter {
int is_color=1); int is_color=1);
~CvVideoWriter_AVFoundation(); ~CvVideoWriter_AVFoundation();
bool writeFrame(const IplImage* image); bool writeFrame(const IplImage* image);
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_AVFOUNDATION; }
private: private:
IplImage* argbimage; IplImage* argbimage;
......
...@@ -1053,7 +1053,7 @@ public: ...@@ -1053,7 +1053,7 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_DC1394; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_DC1394; }
protected: protected:
CvCaptureCAM_DC1394* captureDC1394; CvCaptureCAM_DC1394* captureDC1394;
......
...@@ -211,7 +211,7 @@ public: ...@@ -211,7 +211,7 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_DC1394; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_DC1394; }
protected: protected:
......
...@@ -289,6 +289,8 @@ public: ...@@ -289,6 +289,8 @@ public:
CvVideoWriter_FFMPEG_proxy(const cv::String& filename, int fourcc, double fps, cv::Size frameSize, bool isColor) { ffmpegWriter = 0; open(filename, fourcc, fps, frameSize, isColor); } CvVideoWriter_FFMPEG_proxy(const cv::String& filename, int fourcc, double fps, cv::Size frameSize, bool isColor) { ffmpegWriter = 0; open(filename, fourcc, fps, frameSize, isColor); }
virtual ~CvVideoWriter_FFMPEG_proxy() { close(); } virtual ~CvVideoWriter_FFMPEG_proxy() { close(); }
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_FFMPEG; }
virtual void write(cv::InputArray image ) CV_OVERRIDE virtual void write(cv::InputArray image ) CV_OVERRIDE
{ {
if(!ffmpegWriter) if(!ffmpegWriter)
......
...@@ -144,10 +144,7 @@ public: ...@@ -144,10 +144,7 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual bool retrieveFrame(int, OutputArray) CV_OVERRIDE; virtual bool retrieveFrame(int, OutputArray) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_GPHOTO2; }
{
return CV_CAP_GPHOTO2;
} // Return the type of the capture object: CV_CAP_VFW, etc...
bool open(int index); bool open(int index);
void close(); void close();
......
...@@ -189,7 +189,7 @@ public: ...@@ -189,7 +189,7 @@ public:
virtual double getProperty(int propId) const CV_OVERRIDE; virtual double getProperty(int propId) const CV_OVERRIDE;
virtual bool setProperty(int propId, double value) CV_OVERRIDE; virtual bool setProperty(int propId, double value) CV_OVERRIDE;
virtual bool isOpened() const CV_OVERRIDE; virtual bool isOpened() const CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE; // Return the type of the capture object: CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return cv::CAP_GSTREAMER; }
bool open(int id); bool open(int id);
bool open(const String &filename_); bool open(const String &filename_);
static void newPad(GstElement * /*elem*/, GstPad *pad, gpointer data); static void newPad(GstElement * /*elem*/, GstPad *pad, gpointer data);
...@@ -578,8 +578,6 @@ bool GStreamerCapture::isOpened() const ...@@ -578,8 +578,6 @@ bool GStreamerCapture::isOpened() const
return pipeline != NULL; return pipeline != NULL;
} }
int GStreamerCapture::getCaptureDomain() { return CAP_GSTREAMER; }
/*! /*!
* \brief CvCapture_GStreamer::open Open the given file with gstreamer * \brief CvCapture_GStreamer::open Open the given file with gstreamer
* \param type CvCapture type. One of CV_CAP_GSTREAMER_* * \param type CvCapture type. One of CV_CAP_GSTREAMER_*
...@@ -1233,6 +1231,8 @@ public: ...@@ -1233,6 +1231,8 @@ public:
} }
virtual ~CvVideoWriter_GStreamer() CV_OVERRIDE { close(); } virtual ~CvVideoWriter_GStreamer() CV_OVERRIDE { close(); }
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_GSTREAMER; }
virtual bool open( const char* filename, int fourcc, virtual bool open( const char* filename, int fourcc,
double fps, CvSize frameSize, bool isColor ); double fps, CvSize frameSize, bool isColor );
virtual void close(); virtual void close();
......
...@@ -86,6 +86,7 @@ public: ...@@ -86,6 +86,7 @@ public:
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_IMAGES; }
protected: protected:
char* filename; // actually a printf-pattern char* filename; // actually a printf-pattern
unsigned currentframe; unsigned currentframe;
...@@ -336,6 +337,7 @@ public: ...@@ -336,6 +337,7 @@ public:
virtual bool setProperty( int, double ); // FIXIT doesn't work: IVideoWriter interface only! virtual bool setProperty( int, double ); // FIXIT doesn't work: IVideoWriter interface only!
virtual bool writeFrame( const IplImage* ) CV_OVERRIDE; virtual bool writeFrame( const IplImage* ) CV_OVERRIDE;
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_IMAGES; }
protected: protected:
char* filename; char* filename;
unsigned currentframe; unsigned currentframe;
......
...@@ -1928,6 +1928,8 @@ public: ...@@ -1928,6 +1928,8 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_V4L; }
protected: protected:
CvCaptureCAM_V4L* captureV4L; CvCaptureCAM_V4L* captureV4L;
......
...@@ -26,6 +26,7 @@ public: ...@@ -26,6 +26,7 @@ public:
virtual void write(cv::InputArray input); virtual void write(cv::InputArray input);
static cv::Ptr<VideoWriter_IntelMFX> create(const cv::String& filename, int _fourcc, double fps, cv::Size frameSize, bool isColor); static cv::Ptr<VideoWriter_IntelMFX> create(const cv::String& filename, int _fourcc, double fps, cv::Size frameSize, bool isColor);
virtual int getCaptureDomain() const { return cv::CAP_INTEL_MFX; }
protected: protected:
bool write_one(cv::InputArray bgr); bool write_one(cv::InputArray bgr);
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual bool retrieveFrame(int, OutputArray) CV_OVERRIDE; virtual bool retrieveFrame(int, OutputArray) CV_OVERRIDE;
virtual bool isOpened() const CV_OVERRIDE; virtual bool isOpened() const CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CAP_ANY; } // Return the type of the capture object: CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CAP_OPENCV_MJPEG; }
MotionJpegCapture(const String&); MotionJpegCapture(const String&);
bool open(const String&); bool open(const String&);
......
...@@ -403,6 +403,8 @@ public: ...@@ -403,6 +403,8 @@ public:
} }
~MotionJpegWriter() { close(); } ~MotionJpegWriter() { close(); }
virtual int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_OPENCV_MJPEG; }
void close() void close()
{ {
if( !container.isOpenedStream() ) if( !container.isOpenedStream() )
......
...@@ -701,7 +701,7 @@ public: ...@@ -701,7 +701,7 @@ public:
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual bool retrieveFrame(int, cv::OutputArray) CV_OVERRIDE; virtual bool retrieveFrame(int, cv::OutputArray) CV_OVERRIDE;
virtual bool isOpened() const CV_OVERRIDE { return isOpen; } virtual bool isOpened() const CV_OVERRIDE { return isOpen; }
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_MSMF; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_MSMF; }
protected: protected:
double getFramerate(MediaType MT) const; double getFramerate(MediaType MT) const;
bool configureOutput(UINT32 width, UINT32 height, double prefFramerate, UINT32 aspectRatioN, UINT32 aspectRatioD, int outFormat, bool convertToFormat); bool configureOutput(UINT32 width, UINT32 height, double prefFramerate, UINT32 aspectRatioN, UINT32 aspectRatioD, int outFormat, bool convertToFormat);
...@@ -1955,6 +1955,7 @@ public: ...@@ -1955,6 +1955,7 @@ public:
virtual bool setProperty(int, double) { return false; } virtual bool setProperty(int, double) { return false; }
virtual bool isOpened() const { return initiated; } virtual bool isOpened() const { return initiated; }
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_MSMF; }
private: private:
Media_Foundation& MF; Media_Foundation& MF;
UINT32 videoWidth; UINT32 videoWidth;
......
...@@ -1445,7 +1445,7 @@ public: ...@@ -1445,7 +1445,7 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_QT; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_QT; }
protected: protected:
CvCapture_QT_Movie* captureQT; CvCapture_QT_Movie* captureQT;
...@@ -1580,6 +1580,7 @@ public: ...@@ -1580,6 +1580,7 @@ public:
virtual void close(); virtual void close();
virtual bool writeFrame( const IplImage* ); virtual bool writeFrame( const IplImage* );
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_QT; }
protected: protected:
CvVideoWriter_QT* writerQT; CvVideoWriter_QT* writerQT;
}; };
......
...@@ -198,6 +198,8 @@ public: ...@@ -198,6 +198,8 @@ public:
int is_color=1); int is_color=1);
~CvVideoWriter_QT(); ~CvVideoWriter_QT();
bool writeFrame(const IplImage* image); bool writeFrame(const IplImage* image);
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_QT; }
private: private:
IplImage* argbimage; IplImage* argbimage;
QTMovie* mMovie; QTMovie* mMovie;
......
...@@ -66,7 +66,7 @@ struct CvCapture_Unicap : public CvCapture ...@@ -66,7 +66,7 @@ struct CvCapture_Unicap : public CvCapture
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_UNICAP; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_UNICAP; }
bool shutdownDevice(); bool shutdownDevice();
bool initDevice(); bool initDevice();
......
...@@ -267,6 +267,8 @@ struct buffer ...@@ -267,6 +267,8 @@ struct buffer
struct CvCaptureCAM_V4L CV_FINAL : public CvCapture struct CvCaptureCAM_V4L CV_FINAL : public CvCapture
{ {
int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_V4L; }
int deviceHandle; int deviceHandle;
int bufferIndex; int bufferIndex;
int FirstCapture; int FirstCapture;
......
...@@ -103,7 +103,7 @@ public: ...@@ -103,7 +103,7 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_VFW; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_VFW; }
protected: protected:
void init(); void init();
...@@ -697,6 +697,7 @@ public: ...@@ -697,6 +697,7 @@ public:
virtual void close(); virtual void close();
virtual bool writeFrame( const IplImage* ); virtual bool writeFrame( const IplImage* );
int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_VFW; }
protected: protected:
void init(); void init();
bool createStreams( CvSize frameSize, bool isColor ); bool createStreams( CvSize frameSize, bool isColor );
......
...@@ -55,8 +55,7 @@ namespace cv { ...@@ -55,8 +55,7 @@ namespace cv {
virtual bool grabFrame(); virtual bool grabFrame();
virtual bool retrieveFrame(int channel, cv::OutputArray outArray); virtual bool retrieveFrame(int channel, cv::OutputArray outArray);
// Return the type of the capture object virtual int getCaptureDomain() CV_OVERRIDE { return CAP_WINRT; }
virtual int getCaptureDomain() { return CAP_WINRT; }
virtual bool isOpened() const; virtual bool isOpened() const;
......
...@@ -24,7 +24,7 @@ public: ...@@ -24,7 +24,7 @@ public:
virtual bool setProperty(int, double) CV_OVERRIDE; virtual bool setProperty(int, double) CV_OVERRIDE;
virtual bool grabFrame() CV_OVERRIDE; virtual bool grabFrame() CV_OVERRIDE;
virtual IplImage* retrieveFrame(int) CV_OVERRIDE; virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_XIAPI; } // Return the type of the capture object: CV_CAP_VFW, etc... virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_XIAPI; }
private: private:
bool _open(); bool _open();
......
...@@ -102,6 +102,7 @@ struct CvVideoWriter ...@@ -102,6 +102,7 @@ struct CvVideoWriter
{ {
virtual ~CvVideoWriter() {} virtual ~CvVideoWriter() {}
virtual bool writeFrame(const IplImage*) { return false; } virtual bool writeFrame(const IplImage*) { return false; }
virtual int getCaptureDomain() const { return cv::CAP_ANY; } // Return the type of the capture object: CAP_FFMPEG, etc...
}; };
CvCapture * cvCreateCameraCapture_V4L( int index ); CvCapture * cvCreateCameraCapture_V4L( int index );
...@@ -178,6 +179,8 @@ namespace cv ...@@ -178,6 +179,8 @@ namespace cv
virtual bool isOpened() const = 0; virtual bool isOpened() const = 0;
virtual void write(InputArray) = 0; virtual void write(InputArray) = 0;
virtual int getCaptureDomain() const { return cv::CAP_ANY; } // Return the type of the capture object: CAP_FFMPEG, etc...
}; };
Ptr<IVideoCapture> createMotionJpegCapture(const String& filename); Ptr<IVideoCapture> createMotionJpegCapture(const String& filename);
......
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// Note: all tests here are DISABLED by default due specific requirements.
// Don't use #if 0 - these tests should be tested for compilation at least.
//
// Usage: opencv_test_videoio --gtest_also_run_disabled_tests --gtest_filter=*VideoIO_Camera*<tested case>*
#include "test_precomp.hpp"
namespace opencv_test { namespace {
TEST(DISABLED_VideoIO_Camera, basic)
{
VideoCapture capture(0);
ASSERT_TRUE(capture.isOpened());
std::cout << "Camera 0 via " << capture.getBackendName() << " backend" << std::endl;
std::cout << "Frame width: " << capture.get(CAP_PROP_FRAME_WIDTH) << std::endl;
std::cout << " height: " << capture.get(CAP_PROP_FRAME_HEIGHT) << std::endl;
std::cout << "Capturing FPS: " << capture.get(CAP_PROP_FPS) << std::endl;
const int N = 100;
Mat frame;
int64 time0 = cv::getTickCount();
for (int i = 0; i < N; i++)
{
SCOPED_TRACE(cv::format("frame=%d", i));
capture >> frame;
ASSERT_FALSE(frame.empty());
EXPECT_GT(cvtest::norm(frame, NORM_INF), 0) << "Complete black image has been received";
}
int64 time1 = cv::getTickCount();
printf("Processed %d frames on %.2f FPS\n", N, (N * cv::getTickFrequency()) / (time1 - time0 + 1));
capture.release();
}
}} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment