videoio: added '.getBackendName()' method
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sat, 15 Sep 2018 20:54:03 +0000 (20:54 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 18 Sep 2018 16:19:19 +0000 (16:19 +0000)
23 files changed:
modules/videoio/include/opencv2/videoio.hpp
modules/videoio/src/cap.cpp
modules/videoio/src/cap_avfoundation.mm
modules/videoio/src/cap_avfoundation_mac.mm
modules/videoio/src/cap_dc1394.cpp
modules/videoio/src/cap_dc1394_v2.cpp
modules/videoio/src/cap_ffmpeg.cpp
modules/videoio/src/cap_gphoto2.cpp
modules/videoio/src/cap_gstreamer.cpp
modules/videoio/src/cap_images.cpp
modules/videoio/src/cap_libv4l.cpp
modules/videoio/src/cap_mfx_writer.hpp
modules/videoio/src/cap_mjpeg_decoder.cpp
modules/videoio/src/cap_mjpeg_encoder.cpp
modules/videoio/src/cap_msmf.cpp
modules/videoio/src/cap_qt.cpp
modules/videoio/src/cap_qtkit.mm
modules/videoio/src/cap_unicap.cpp
modules/videoio/src/cap_v4l.cpp
modules/videoio/src/cap_vfw.cpp
modules/videoio/src/cap_winrt_capture.hpp
modules/videoio/src/cap_ximea.cpp
modules/videoio/src/precomp.hpp

index bb4e398..92af74a 100644 (file)
@@ -808,6 +808,12 @@ public:
     */
     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:
     Ptr<CvCapture> cap;
     Ptr<IVideoCapture> icap;
@@ -946,6 +952,12 @@ public:
      */
     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:
     Ptr<CvVideoWriter> writer;
     Ptr<IVideoWriter> iwriter;
index f633ff8..6c1ad19 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "precomp.hpp"
 
+#include "opencv2/videoio/registry.hpp"
 #include "videoio_registry.hpp"
 
 namespace cv {
@@ -172,6 +173,17 @@ bool VideoCapture::isOpened() const
     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()
 {
     CV_TRACE_FUNCTION();
@@ -358,6 +370,17 @@ double VideoWriter::get(int propId) const
     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)
 {
     CV_INSTRUMENT_REGION();
index 0866782..cb0fbb0 100644 (file)
@@ -174,6 +174,7 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter{
                 int is_color=1);
         ~CvVideoWriter_AVFoundation();
         bool writeFrame(const IplImage* image);
+        int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_AVFOUNDATION; }
     private:
         IplImage* argbimage;
 
index b8d9fb4..e822c7d 100644 (file)
@@ -182,6 +182,7 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter {
                 int is_color=1);
         ~CvVideoWriter_AVFoundation();
         bool writeFrame(const IplImage* image);
+        int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_AVFOUNDATION; }
     private:
         IplImage* argbimage;
 
index 7ba1713..368bf3a 100644 (file)
@@ -1053,7 +1053,7 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() 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:
 
     CvCaptureCAM_DC1394* captureDC1394;
index d3cb2f5..45ff438 100644 (file)
@@ -211,7 +211,7 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() 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:
index 14353ad..df7e446 100644 (file)
@@ -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); }
     virtual ~CvVideoWriter_FFMPEG_proxy() { close(); }
 
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_FFMPEG; }
+
     virtual void write(cv::InputArray image ) CV_OVERRIDE
     {
         if(!ffmpegWriter)
index 7a6b64d..cab67b2 100644 (file)
@@ -144,10 +144,7 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() CV_OVERRIDE;
     virtual bool retrieveFrame(int, OutputArray) CV_OVERRIDE;
-    virtual int getCaptureDomain() CV_OVERRIDE
-    {
-        return CV_CAP_GPHOTO2;
-    } // Return the type of the capture object: CV_CAP_VFW, etc...
+    virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_GPHOTO2; }
 
     bool open(int index);
     void close();
index 2c9570e..23d39d2 100644 (file)
@@ -189,7 +189,7 @@ public:
     virtual double getProperty(int propId) const CV_OVERRIDE;
     virtual bool setProperty(int propId, double value) 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(const String &filename_);
     static void newPad(GstElement * /*elem*/, GstPad     *pad, gpointer    data);
@@ -578,8 +578,6 @@ bool GStreamerCapture::isOpened() const
     return pipeline != NULL;
 }
 
-int GStreamerCapture::getCaptureDomain() { return CAP_GSTREAMER; }
-
 /*!
  * \brief CvCapture_GStreamer::open Open the given file with gstreamer
  * \param type CvCapture type. One of CV_CAP_GSTREAMER_*
@@ -1233,6 +1231,8 @@ public:
     }
     virtual ~CvVideoWriter_GStreamer() CV_OVERRIDE { close(); }
 
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_GSTREAMER; }
+
     virtual bool open( const char* filename, int fourcc,
                        double fps, CvSize frameSize, bool isColor );
     virtual void close();
index 9d4d0fc..0e3c8f2 100644 (file)
@@ -86,6 +86,7 @@ public:
     virtual bool grabFrame() CV_OVERRIDE;
     virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
 
+    int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_IMAGES; }
 protected:
     char*  filename; // actually a printf-pattern
     unsigned currentframe;
@@ -336,6 +337,7 @@ public:
     virtual bool setProperty( int, double ); // FIXIT doesn't work: IVideoWriter interface only!
     virtual bool writeFrame( const IplImage* ) CV_OVERRIDE;
 
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_IMAGES; }
 protected:
     char* filename;
     unsigned currentframe;
index 4e1927f..bfc68fe 100644 (file)
@@ -1928,6 +1928,8 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() CV_OVERRIDE;
     virtual IplImage* retrieveFrame(int) CV_OVERRIDE;
+
+    int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_V4L; }
 protected:
 
     CvCaptureCAM_V4L* captureV4L;
index 6a60960..26b1d0d 100644 (file)
@@ -26,6 +26,7 @@ public:
     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);
 
+    virtual int getCaptureDomain() const { return cv::CAP_INTEL_MFX; }
 protected:
     bool write_one(cv::InputArray bgr);
 
index 02400fd..116f118 100644 (file)
@@ -54,7 +54,7 @@ public:
     virtual bool grabFrame() CV_OVERRIDE;
     virtual bool retrieveFrame(int, OutputArray) 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&);
 
     bool open(const String&);
index b3d9b8f..7f4c8a6 100644 (file)
@@ -403,6 +403,8 @@ public:
     }
     ~MotionJpegWriter() { close(); }
 
+    virtual int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_OPENCV_MJPEG; }
+
     void close()
     {
         if( !container.isOpenedStream() )
index a540238..9fa84a1 100644 (file)
@@ -701,7 +701,7 @@ public:
     virtual bool grabFrame() CV_OVERRIDE;
     virtual bool retrieveFrame(int, cv::OutputArray) CV_OVERRIDE;
     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:
     double getFramerate(MediaType MT) const;
     bool configureOutput(UINT32 width, UINT32 height, double prefFramerate, UINT32 aspectRatioN, UINT32 aspectRatioD, int outFormat, bool convertToFormat);
@@ -1955,6 +1955,7 @@ public:
     virtual bool setProperty(int, double) { return false; }
     virtual bool isOpened() const { return initiated; }
 
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_MSMF; }
 private:
     Media_Foundation& MF;
     UINT32 videoWidth;
index cb416e6..8acc5d5 100644 (file)
@@ -1445,7 +1445,7 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() 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:
 
     CvCapture_QT_Movie* captureQT;
@@ -1580,6 +1580,7 @@ public:
     virtual void close();
     virtual bool writeFrame( const IplImage* );
 
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_QT; }
 protected:
     CvVideoWriter_QT* writerQT;
 };
index d998b4c..e198f3f 100644 (file)
@@ -198,6 +198,8 @@ public:
                    int is_color=1);
     ~CvVideoWriter_QT();
     bool writeFrame(const IplImage* image);
+
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_QT; }
 private:
     IplImage* argbimage;
     QTMovie* mMovie;
index f369197..77a622c 100644 (file)
@@ -66,7 +66,7 @@ struct CvCapture_Unicap : public CvCapture
   virtual bool setProperty(int, double) CV_OVERRIDE;
   virtual bool grabFrame() 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 initDevice();
index 16b59f1..35a948d 100644 (file)
@@ -267,6 +267,8 @@ struct buffer
 
 struct CvCaptureCAM_V4L CV_FINAL : public CvCapture
 {
+    int getCaptureDomain() /*const*/ CV_OVERRIDE { return cv::CAP_V4L; }
+
     int deviceHandle;
     int bufferIndex;
     int FirstCapture;
index f62baf4..46ae9d5 100644 (file)
@@ -103,7 +103,7 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() 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:
     void init();
@@ -697,6 +697,7 @@ public:
     virtual void close();
     virtual bool writeFrame( const IplImage* );
 
+    int getCaptureDomain() const CV_OVERRIDE { return cv::CAP_VFW; }
 protected:
     void init();
     bool createStreams( CvSize frameSize, bool isColor );
index ab93d09..476a854 100644 (file)
@@ -55,8 +55,7 @@ namespace cv {
         virtual bool grabFrame();
         virtual bool retrieveFrame(int channel, cv::OutputArray outArray);
 
-        // Return the type of the capture object
-        virtual int getCaptureDomain() { return CAP_WINRT; }
+        virtual int getCaptureDomain() CV_OVERRIDE { return CAP_WINRT; }
 
         virtual bool isOpened() const;
 
index afc0887..0dd3e93 100644 (file)
@@ -24,7 +24,7 @@ public:
     virtual bool setProperty(int, double) CV_OVERRIDE;
     virtual bool grabFrame() 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:
     bool _open();
index a664aa7..06f7e4a 100644 (file)
@@ -102,6 +102,7 @@ struct CvVideoWriter
 {
     virtual ~CvVideoWriter() {}
     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 );
@@ -178,6 +179,8 @@ namespace cv
 
         virtual bool isOpened() const = 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);