github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/fluid/gfluidbuffer.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) 2018 Intel Corporation
     6  
     7  
     8  #ifndef OPENCV_GAPI_FLUID_BUFFER_HPP
     9  #define OPENCV_GAPI_FLUID_BUFFER_HPP
    10  
    11  #include <list>
    12  #include <numeric> // accumulate
    13  #include <ostream> // ostream
    14  #include <cstdint> // uint8_t
    15  
    16  #include <opencv2/gapi/opencv_includes.hpp>
    17  #include <opencv2/gapi/gmat.hpp>
    18  
    19  #include <opencv2/gapi/util/optional.hpp>
    20  
    21  namespace cv {
    22  namespace gapi {
    23  namespace fluid {
    24  
    25  struct Border
    26  {
    27      // This constructor is required to support existing kernels which are part of G-API
    28      Border(int _type, cv::Scalar _val) : type(_type), value(_val) {};
    29  
    30      int type;
    31      cv::Scalar value;
    32  };
    33  
    34  using BorderOpt = util::optional<Border>;
    35  
    36  bool operator == (const Border& b1, const Border& b2);
    37  
    38  class GAPI_EXPORTS Buffer;
    39  
    40  class GAPI_EXPORTS View
    41  {
    42  public:
    43      struct Cache
    44      {
    45          std::vector<const uint8_t*> m_linePtrs;
    46          GMatDesc m_desc;
    47          int m_border_size = 0;
    48  
    49          inline const uint8_t* linePtr(int index) const
    50          {
    51              // "out_of_window" check:
    52              // user must not request the lines which are outside of specified kernel window
    53              GAPI_DbgAssert(index >= -m_border_size
    54                          && index <  -m_border_size + static_cast<int>(m_linePtrs.size()));
    55              return m_linePtrs[index + m_border_size];
    56          }
    57      };
    58  
    59      const inline uint8_t* InLineB(int index) const // -(w-1)/2...0...+(w-1)/2 for Filters
    60      {
    61          return m_cache->linePtr(index);
    62      }
    63  
    64      template<typename T> const inline T* InLine(int i) const
    65      {
    66          const uint8_t* ptr = this->InLineB(i);
    67          return reinterpret_cast<const T*>(ptr);
    68      }
    69  
    70      inline operator bool() const { return m_priv != nullptr; }
    71      bool ready() const;
    72      inline int length() const { return m_cache->m_desc.size.width; }
    73      int y() const;
    74  
    75      inline const GMatDesc& meta() const { return m_cache->m_desc; }
    76  
    77      class GAPI_EXPORTS Priv;      // internal use only
    78      Priv& priv();               // internal use only
    79      const Priv& priv() const;   // internal use only
    80  
    81      View();
    82      View(std::unique_ptr<Priv>&& p);
    83      View(View&& v);
    84      View& operator=(View&& v);
    85      ~View();
    86  
    87  private:
    88      std::unique_ptr<Priv> m_priv;
    89      const Cache* m_cache = nullptr;
    90  };
    91  
    92  class GAPI_EXPORTS Buffer
    93  {
    94  public:
    95      struct Cache
    96      {
    97          std::vector<uint8_t*> m_linePtrs;
    98          GMatDesc m_desc;
    99      };
   100  
   101      // Default constructor (executable creation stage,
   102      // all following initialization performed in Priv::init())
   103      Buffer();
   104      // Scratch constructor (user kernels)
   105      Buffer(const cv::GMatDesc &desc);
   106  
   107      // Constructor for intermediate buffers (for tests)
   108      Buffer(const cv::GMatDesc &desc,
   109             int max_line_consumption, int border_size,
   110             int skew,
   111             int wlpi,
   112             BorderOpt border);
   113      // Constructor for in/out buffers (for tests)
   114      Buffer(const cv::Mat &data, bool is_input);
   115      ~Buffer();
   116      Buffer& operator=(Buffer&&);
   117  
   118      inline uint8_t* OutLineB(int index = 0)
   119      {
   120          return m_cache->m_linePtrs[index];
   121      }
   122  
   123      template<typename T> inline T* OutLine(int index = 0)
   124      {
   125          uint8_t* ptr = this->OutLineB(index);
   126          return reinterpret_cast<T*>(ptr);
   127      }
   128  
   129      int y() const;
   130  
   131      int linesReady() const;
   132      void debug(std::ostream &os) const;
   133      inline int length() const { return m_cache->m_desc.size.width; }
   134      int lpi() const;  // LPI for WRITER
   135  
   136      inline const GMatDesc& meta() const { return m_cache->m_desc; }
   137  
   138      View mkView(int borderSize, bool ownStorage);
   139      void addView(const View* v);
   140  
   141      class GAPI_EXPORTS Priv;      // internal use only
   142      Priv& priv();               // internal use only
   143      const Priv& priv() const;   // internal use only
   144  
   145  private:
   146      std::unique_ptr<Priv> m_priv;
   147      const Cache* m_cache;
   148  };
   149  
   150  } // namespace cv::gapi::fluid
   151  } // namespace cv::gapi
   152  } // namespace cv
   153  
   154  #endif // OPENCV_GAPI_FLUID_BUFFER_HPP