videoio: CAP_PROP_BACKEND property interface
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 18 Sep 2018 16:25:01 +0000 (16:25 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 18 Sep 2018 16:25:01 +0000 (16:25 +0000)
modules/videoio/include/opencv2/videoio.hpp
modules/videoio/src/cap.cpp

index 92af74a..cfa2774 100644 (file)
@@ -169,6 +169,7 @@ enum VideoCaptureProperties {
        CAP_PROP_AUTOFOCUS     =39,
        CAP_PROP_SAR_NUM       =40, //!< Sample aspect ratio: num/den (num)
        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
        CV__CAP_PROP_LATEST
 #endif
index 6c1ad19..ff0bc6f 100644 (file)
@@ -272,6 +272,8 @@ VideoCapture& VideoCapture::operator >> (UMat& image)
 
 bool VideoCapture::set(int propId, double value)
 {
+    CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can set read-only property");
+
     if (!icap.empty())
         return icap->setProperty(propId, value);
     return cvSetCaptureProperty(cap, propId, value) != 0;
@@ -279,6 +281,17 @@ bool VideoCapture::set(int propId, double value)
 
 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())
         return icap->getProperty(propId);
     return cap ? cap->getProperty(propId) : 0;
@@ -358,6 +371,8 @@ bool VideoWriter::isOpened() const
 
 bool VideoWriter::set(int propId, double value)
 {
+    CV_CheckNE(propId, (int)CAP_PROP_BACKEND, "Can set read-only property");
+
     if (!iwriter.empty())
         return iwriter->setProperty(propId, value);
     return false;
@@ -365,6 +380,17 @@ bool VideoWriter::set(int propId, double value)
 
 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())
         return iwriter->getProperty(propId);
     return 0.;