github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/infer/parsers.hpp (about)

     1  // This file is part of OpenCV project.
     2  // It is subject to the license terms in the LICENSE file found in the top-level directory
     3  // of this distribution and at http://opencv.org/license.html.
     4  //
     5  // Copyright (C) 2020 Intel Corporation
     6  
     7  
     8  #ifndef OPENCV_GAPI_PARSERS_HPP
     9  #define OPENCV_GAPI_PARSERS_HPP
    10  
    11  #include <utility> // std::tuple
    12  
    13  #include <opencv2/gapi/gmat.hpp>
    14  #include <opencv2/gapi/gkernel.hpp>
    15  
    16  namespace cv { namespace gapi {
    17  namespace nn {
    18  namespace parsers {
    19      using GRects      = GArray<Rect>;
    20      using GDetections = std::tuple<GArray<Rect>, GArray<int>>;
    21  
    22      G_TYPED_KERNEL(GParseSSDBL, <GDetections(GMat, GOpaque<Size>, float, int)>,
    23                     "org.opencv.nn.parsers.parseSSD_BL") {
    24          static std::tuple<GArrayDesc,GArrayDesc> outMeta(const GMatDesc&, const GOpaqueDesc&, float, int) {
    25              return std::make_tuple(empty_array_desc(), empty_array_desc());
    26          }
    27      };
    28  
    29      G_TYPED_KERNEL(GParseSSD, <GRects(GMat, GOpaque<Size>, float, bool, bool)>,
    30                     "org.opencv.nn.parsers.parseSSD") {
    31          static GArrayDesc outMeta(const GMatDesc&, const GOpaqueDesc&, float, bool, bool) {
    32              return empty_array_desc();
    33          }
    34      };
    35  
    36      G_TYPED_KERNEL(GParseYolo, <GDetections(GMat, GOpaque<Size>, float, float, std::vector<float>)>,
    37                     "org.opencv.nn.parsers.parseYolo") {
    38          static std::tuple<GArrayDesc, GArrayDesc> outMeta(const GMatDesc&, const GOpaqueDesc&,
    39                                                            float, float, const std::vector<float>&) {
    40              return std::make_tuple(empty_array_desc(), empty_array_desc());
    41          }
    42          static const std::vector<float>& defaultAnchors() {
    43              static std::vector<float> anchors {
    44                  0.57273f, 0.677385f, 1.87446f, 2.06253f, 3.33843f, 5.47434f, 7.88282f, 3.52778f, 9.77052f, 9.16828f
    45              };
    46              return anchors;
    47          }
    48      };
    49  } // namespace parsers
    50  } // namespace nn
    51  
    52  /** @brief Parses output of SSD network.
    53  
    54  Extracts detection information (box, confidence, label) from SSD output and
    55  filters it by given confidence and label.
    56  
    57  @note Function textual ID is "org.opencv.nn.parsers.parseSSD_BL"
    58  
    59  @param in Input CV_32F tensor with {1,1,N,7} dimensions.
    60  @param inSz Size to project detected boxes to (size of the input image).
    61  @param confidenceThreshold If confidence of the
    62  detection is smaller than confidence threshold, detection is rejected.
    63  @param filterLabel If provided (!= -1), only detections with
    64  given label will get to the output.
    65  @return a tuple with a vector of detected boxes and a vector of appropriate labels.
    66  */
    67  GAPI_EXPORTS_W std::tuple<GArray<Rect>, GArray<int>> parseSSD(const GMat& in,
    68                                                                const GOpaque<Size>& inSz,
    69                                                                const float confidenceThreshold = 0.5f,
    70                                                                const int   filterLabel = -1);
    71  
    72  /** @brief Parses output of SSD network.
    73  
    74  Extracts detection information (box, confidence) from SSD output and
    75  filters it by given confidence and by going out of bounds.
    76  
    77  @note Function textual ID is "org.opencv.nn.parsers.parseSSD"
    78  
    79  @param in Input CV_32F tensor with {1,1,N,7} dimensions.
    80  @param inSz Size to project detected boxes to (size of the input image).
    81  @param confidenceThreshold If confidence of the
    82  detection is smaller than confidence threshold, detection is rejected.
    83  @param alignmentToSquare If provided true, bounding boxes are extended to squares.
    84  The center of the rectangle remains unchanged, the side of the square is
    85  the larger side of the rectangle.
    86  @param filterOutOfBounds If provided true, out-of-frame boxes are filtered.
    87  @return a vector of detected bounding boxes.
    88  */
    89  GAPI_EXPORTS_W GArray<Rect> parseSSD(const GMat& in,
    90                                       const GOpaque<Size>& inSz,
    91                                       const float confidenceThreshold,
    92                                       const bool alignmentToSquare,
    93                                       const bool filterOutOfBounds);
    94  
    95  /** @brief Parses output of Yolo network.
    96  
    97  Extracts detection information (box, confidence, label) from Yolo output,
    98  filters it by given confidence and performs non-maximum supression for overlapping boxes.
    99  
   100  @note Function textual ID is "org.opencv.nn.parsers.parseYolo"
   101  
   102  @param in Input CV_32F tensor with {1,13,13,N} dimensions, N should satisfy:
   103  \f[\texttt{N} = (\texttt{num_classes} + \texttt{5}) * \texttt{5},\f]
   104  where num_classes - a number of classes Yolo network was trained with.
   105  @param inSz Size to project detected boxes to (size of the input image).
   106  @param confidenceThreshold If confidence of the
   107  detection is smaller than confidence threshold, detection is rejected.
   108  @param nmsThreshold Non-maximum supression threshold which controls minimum
   109  relative box intersection area required for rejecting the box with a smaller confidence.
   110  If 1.f, nms is not performed and no boxes are rejected.
   111  @param anchors Anchors Yolo network was trained with.
   112  @note The default anchor values are specified for YOLO v2 Tiny as described in Intel Open Model Zoo
   113  <a href="https://github.com/openvinotoolkit/open_model_zoo/blob/master/models/public/yolo-v2-tiny-tf/yolo-v2-tiny-tf.md">documentation</a>.
   114  @return a tuple with a vector of detected boxes and a vector of appropriate labels.
   115  */
   116  GAPI_EXPORTS_W std::tuple<GArray<Rect>, GArray<int>> parseYolo(const GMat& in,
   117                                                                 const GOpaque<Size>& inSz,
   118                                                                 const float confidenceThreshold = 0.5f,
   119                                                                 const float nmsThreshold = 0.5f,
   120                                                                 const std::vector<float>& anchors
   121                                                                     = nn::parsers::GParseYolo::defaultAnchors());
   122  
   123  } // namespace gapi
   124  } // namespace cv
   125  
   126  // Reimport parseSSD & parseYolo under their initial namespace
   127  namespace cv {
   128  namespace gapi {
   129  namespace streaming {
   130  
   131  using cv::gapi::parseSSD;
   132  using cv::gapi::parseYolo;
   133  
   134  } // namespace streaming
   135  } // namespace gapi
   136  } // namespace cv
   137  
   138  #endif // OPENCV_GAPI_PARSERS_HPP