Merge pull request #19341 from mpashchenkov:mp/ocv-gapi-parsessd-fix
authorMaxim Pashchenkov <maxim.pashchenkov@intel.com>
Tue, 15 Jun 2021 19:02:17 +0000 (22:02 +0300)
committerGitHub <noreply@github.com>
Tue, 15 Jun 2021 19:02:17 +0000 (19:02 +0000)
G-API: Removing ParseSSD overload.

* Removed specialization.

* Removed united

modules/gapi/include/opencv2/gapi/infer/parsers.hpp
modules/gapi/src/backends/cpu/gcpucore.cpp
modules/gapi/src/backends/cpu/gnnparsers.cpp
modules/gapi/src/backends/cpu/gnnparsers.hpp

index 3225c73831e24188fdaebdf84d32548bbb62af82..22c8701a6c2e1accc2f95d7d3d7f533040cb5f16 100644 (file)
@@ -69,7 +69,8 @@ GAPI_EXPORTS std::tuple<GArray<Rect>, GArray<int>> parseSSD(const GMat& in,
                                                             const float confidenceThreshold = 0.5f,
                                                             const int   filterLabel = -1);
 
-/** @overload
+/** @brief Parses output of SSD network.
+
 Extracts detection information (box, confidence) from SSD output and
 filters it by given confidence and by going out of bounds.
 
@@ -87,9 +88,9 @@ the larger side of the rectangle.
 */
 GAPI_EXPORTS_W GArray<Rect> parseSSD(const GMat& in,
                                      const GOpaque<Size>& inSz,
-                                     const float confidenceThreshold = 0.5f,
-                                     const bool alignmentToSquare = false,
-                                     const bool filterOutOfBounds = false);
+                                     const float confidenceThreshold,
+                                     const bool alignmentToSquare,
+                                     const bool filterOutOfBounds);
 
 /** @brief Parses output of Yolo network.
 
index 168a2f9833c0bcb74a8ec93f6cd1b2d6cd2896e5..1f7dfb234ff80f1d8190cfddfdfe7aac685068c9 100644 (file)
@@ -652,7 +652,12 @@ GAPI_OCV_KERNEL(GCPUParseSSDBL, cv::gapi::nn::parsers::GParseSSDBL)
                     std::vector<cv::Rect>& out_boxes,
                     std::vector<int>&      out_labels)
     {
-        cv::parseSSDBL(in_ssd_result, in_size, confidence_threshold, filter_label, out_boxes, out_labels);
+        cv::ParseSSD(in_ssd_result, in_size,
+                     confidence_threshold,
+                     filter_label,
+                     false,
+                     false,
+                     out_boxes, out_labels);
     }
 };
 
@@ -665,7 +670,13 @@ GAPI_OCV_KERNEL(GOCVParseSSD, cv::gapi::nn::parsers::GParseSSD)
                     const bool      filter_out_of_bounds,
                     std::vector<cv::Rect>& out_boxes)
     {
-        cv::parseSSD(in_ssd_result, in_size, confidence_threshold, alignment_to_square, filter_out_of_bounds, out_boxes);
+        std::vector<int> unused_labels;
+        cv::ParseSSD(in_ssd_result, in_size,
+                     confidence_threshold,
+                     -1,
+                     alignment_to_square,
+                     filter_out_of_bounds,
+                     out_boxes, unused_labels);
     }
 };
 
index a5e4bf5f856d3c156ea65851ef17089905a43a4a..26de960b7f7766cbac53e486873a8009a0c56484 100644 (file)
@@ -170,48 +170,18 @@ private:
 } // namespace nn
 } // namespace gapi
 
-void parseSSDBL(const cv::Mat&  in_ssd_result,
-                const cv::Size& in_size,
-                const float     confidence_threshold,
-                const int       filter_label,
-                std::vector<cv::Rect>& out_boxes,
-                std::vector<int>&      out_labels)
-{
-    cv::gapi::nn::SSDParser parser(in_ssd_result.size, in_size, in_ssd_result.ptr<float>());
-    out_boxes.clear();
-    out_labels.clear();
-    cv::Rect rc;
-    float image_id, confidence;
-    int label;
-    const size_t range = parser.getMaxProposals();
-    for (size_t i = 0; i < range; ++i)
-    {
-        std::tie(rc, image_id, confidence, label) = parser.extract(i);
-
-        if (image_id < 0.f)
-        {
-            break;    // marks end-of-detections
-        }
-
-        if (confidence < confidence_threshold ||
-            (filter_label != -1 && label != filter_label))
-        {
-            continue; // filter out object classes if filter is specified
-        }             // and skip objects with low confidence
-        out_boxes.emplace_back(rc & parser.getSurface());
-        out_labels.emplace_back(label);
-    }
-}
-
-void parseSSD(const cv::Mat&  in_ssd_result,
+void ParseSSD(const cv::Mat&  in_ssd_result,
               const cv::Size& in_size,
               const float     confidence_threshold,
+              const int       filter_label,
               const bool      alignment_to_square,
               const bool      filter_out_of_bounds,
-              std::vector<cv::Rect>& out_boxes)
+              std::vector<cv::Rect>& out_boxes,
+              std::vector<int>&      out_labels)
 {
     cv::gapi::nn::SSDParser parser(in_ssd_result.size, in_size, in_ssd_result.ptr<float>());
     out_boxes.clear();
+    out_labels.clear();
     cv::Rect rc;
     float image_id, confidence;
     int label;
@@ -228,12 +198,14 @@ void parseSSD(const cv::Mat&  in_ssd_result,
         {
             continue; // skip objects with low confidence
         }
-
+        if((filter_label != -1) && (label != filter_label))
+        {
+            continue; // filter out object classes if filter is specified
+        }
         if (alignment_to_square)
         {
             parser.adjustBoundingBox(rc);
         }
-
         const auto clipped_rc = rc & parser.getSurface();
         if (filter_out_of_bounds)
         {
@@ -243,6 +215,7 @@ void parseSSD(const cv::Mat&  in_ssd_result,
             }
         }
         out_boxes.emplace_back(clipped_rc);
+        out_labels.emplace_back(label);
     }
 }
 
index 2ae66937056902ee5374bbf12431d9f1566604e6..28b6128f0c7e24b445bc4d2153cc59a4f5b4f3d7 100644 (file)
 
 namespace cv
 {
-void parseSSDBL(const cv::Mat&  in_ssd_result,
-                const cv::Size& in_size,
-                const float     confidence_threshold,
-                const int       filter_label,
-                std::vector<cv::Rect>& out_boxes,
-                std::vector<int>&      out_labels);
-
-void parseSSD(const cv::Mat&  in_ssd_result,
+void ParseSSD(const cv::Mat&  in_ssd_result,
               const cv::Size& in_size,
               const float     confidence_threshold,
+              const int       filter_label,
               const bool      alignment_to_square,
               const bool      filter_out_of_bounds,
-              std::vector<cv::Rect>& out_boxes);
+              std::vector<cv::Rect>& out_boxes,
+              std::vector<int>&      out_labels);
 
 void parseYolo(const cv::Mat&  in_yolo_result,
                const cv::Size& in_size,