github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/gcompiled.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-2020 Intel Corporation
     6  
     7  
     8  #ifndef OPENCV_GAPI_GCOMPILED_HPP
     9  #define OPENCV_GAPI_GCOMPILED_HPP
    10  
    11  #include <vector>
    12  
    13  #include <opencv2/gapi/opencv_includes.hpp>
    14  #include <opencv2/gapi/own/assert.hpp>
    15  #include <opencv2/gapi/garg.hpp>
    16  
    17  namespace cv {
    18  
    19  // This class represents a compiled computation.
    20  // In theory (and ideally), it can be used w/o the rest of APIs.
    21  // In theory (and ideally), it can be serialized/deserialized.
    22  // It can enable scenarious like deployment to an autonomous devince, FuSa, etc.
    23  //
    24  // Currently GCompiled assumes all GMats you used to pass data to G-API
    25  // are valid and not destroyed while you use a GCompiled object.
    26  //
    27  // FIXME: In future, there should be a way to name I/O objects and specify it
    28  // to GCompiled externally (for example, when it is loaded on the target system).
    29  
    30  /**
    31   * \addtogroup gapi_main_classes
    32   * @{
    33   */
    34  /**
    35   * @brief Represents a compiled computation (graph). Can only be used
    36   * with image / data formats & resolutions it was compiled for, with
    37   * some exceptions.
    38   *
    39   * This class represents a product of graph compilation (calling
    40   * cv::GComputation::compile()). Objects of this class actually do
    41   * data processing, and graph execution is incapsulated into objects
    42   * of this class. Execution model itself depends on kernels and
    43   * backends which were using during the compilation, see @ref
    44   * gapi_compile_args for details.
    45   *
    46   * In a general case, GCompiled objects can be applied to data only in
    47   * that formats/resolutions they were compiled for (see @ref
    48   * gapi_meta_args). However, if the underlying backends allow, a
    49   * compiled object can be _reshaped_ to handle data (images) of
    50   * different resolution, though formats and types must remain the same.
    51   *
    52   * GCompiled is very similar to `std::function<>` in its semantics --
    53   * running it looks like a function call in the user code.
    54   *
    55   * At the moment, GCompiled objects are not reentrant -- generally,
    56   * the objects are stateful since graph execution itself is a stateful
    57   * process and this state is now maintained in GCompiled's own memory
    58   * (not on the process stack).
    59   *
    60   * At the same time, two different GCompiled objects produced from the
    61   * single cv::GComputation are completely independent and can be used
    62   * concurrently.
    63   *
    64   * @sa GStreamingCompiled
    65   */
    66  class GAPI_EXPORTS GCompiled
    67  {
    68  public:
    69      /// @private
    70      class GAPI_EXPORTS Priv;
    71  
    72      /**
    73       * @brief Constructs an empty object
    74       */
    75      GCompiled();
    76  
    77      /**
    78       * @brief Run the compiled computation, a generic version.
    79       *
    80       * @param ins vector of inputs to process.
    81       * @param outs vector of outputs to produce.
    82       *
    83       * Input/output vectors must have the same number of elements as
    84       * defined in the cv::GComputation protocol (at the moment of its
    85       * construction). Shapes of elements also must conform to protocol
    86       * (e.g. cv::Mat needs to be passed where cv::GMat has been
    87       * declared as input, and so on). Run-time exception is generated
    88       * otherwise.
    89       *
    90       * Objects in output vector may remain empty (like cv::Mat) --
    91       * G-API will automatically initialize output objects to proper formats.
    92       *
    93       * @note Don't construct GRunArgs/GRunArgsP objects manually, use
    94       * cv::gin()/cv::gout() wrappers instead.
    95       */
    96      void operator() (GRunArgs &&ins, GRunArgsP &&outs);          // Generic arg-to-arg
    97  #if !defined(GAPI_STANDALONE)
    98  
    99      /**
   100       * @brief Execute an unary computation
   101       *
   102       * @overload
   103       * @param in input cv::Mat for unary computation
   104       * @param out output cv::Mat for unary computation
   105       * process.
   106       */
   107      void operator() (cv::Mat in, cv::Mat &out);                  // Unary overload
   108  
   109      /**
   110       * @brief Execute an unary computation
   111       *
   112       * @overload
   113       * @param in input cv::Mat for unary computation
   114       * @param out output cv::Scalar for unary computation
   115       * process.
   116       */
   117      void operator() (cv::Mat in, cv::Scalar &out);               // Unary overload (scalar)
   118  
   119      /**
   120       * @brief Execute a binary computation
   121       *
   122       * @overload
   123       * @param in1 first input cv::Mat for binary computation
   124       * @param in2 second input cv::Mat for binary computation
   125       * @param out output cv::Mat for binary computation
   126       * process.
   127       */
   128      void operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out);    // Binary overload
   129  
   130      /**
   131       * @brief Execute an binary computation
   132       *
   133       * @overload
   134       * @param in1 first input cv::Mat for binary computation
   135       * @param in2 second input cv::Mat for binary computation
   136       * @param out output cv::Scalar for binary computation
   137       * process.
   138       */
   139      void operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out); // Binary overload (scalar)
   140  
   141      /**
   142       * @brief Execute a computation with arbitrary number of
   143       * inputs/outputs.
   144       *
   145       * @overload
   146       * @param ins vector of input cv::Mat objects to process by the
   147       * computation.
   148       * @param outs vector of output cv::Mat objects to produce by the
   149       * computation.
   150       *
   151       * Numbers of elements in ins/outs vectors must match numbers of
   152       * inputs/outputs which were used to define the source GComputation.
   153       */
   154      void operator() (const std::vector<cv::Mat> &ins,            // Compatibility overload
   155                       const std::vector<cv::Mat> &outs);
   156  #endif  // !defined(GAPI_STANDALONE)
   157      /// @private
   158      Priv& priv();
   159  
   160      /**
   161       * @brief Check if compiled object is valid (non-empty)
   162       *
   163       * @return true if the object is runnable (valid), false otherwise
   164       */
   165      explicit operator bool () const;
   166  
   167      /**
   168       * @brief Vector of metadata this graph was compiled for.
   169       *
   170       * @return Unless _reshape_ is not supported, return value is the
   171       * same vector which was passed to cv::GComputation::compile() to
   172       * produce this compiled object. Otherwise, it is the latest
   173       * metadata vector passed to reshape() (if that call was
   174       * successful).
   175       */
   176      const GMetaArgs& metas() const; // Meta passed to compile()
   177  
   178      /**
   179       * @brief Vector of metadata descriptions of graph outputs
   180       *
   181       * @return vector with formats/resolutions of graph's output
   182       * objects, auto-inferred from input metadata vector by
   183       * operations which form this computation.
   184       *
   185       * @note GCompiled objects produced from the same
   186       * cv::GComputiation graph with different input metas may return
   187       * different values in this vector.
   188       */
   189      const GMetaArgs& outMetas() const;
   190  
   191      /**
   192       * @brief Check if the underlying backends support reshape or not.
   193       *
   194       * @return true if supported, false otherwise.
   195       */
   196      bool canReshape() const;
   197  
   198      /**
   199       * @brief Reshape a compiled graph to support new image
   200       * resolutions.
   201       *
   202       * Throws an exception if an error occurs.
   203       *
   204       * @param inMetas new metadata to reshape on. Vector size and
   205       * metadata shapes must match the computation's protocol.
   206       * @param args compilation arguments to use.
   207       */
   208      // FIXME: Why it requires compile args?
   209      void reshape(const GMetaArgs& inMetas, const GCompileArgs& args);
   210  
   211      /**
   212       * @brief Prepare inner kernels states for a new video-stream.
   213       *
   214       * GCompiled objects may be used to process video streams frame by frame.
   215       * In this case, a GCompiled is called on every image frame individually.
   216       * Starting OpenCV 4.4, some kernels in the graph may have their internal
   217       * states (see GAPI_OCV_KERNEL_ST for the OpenCV backend).
   218       * In this case, if user starts processing another video stream with
   219       * this GCompiled, this method needs to be called to let kernels re-initialize
   220       * their internal states to a new video stream.
   221       */
   222      void prepareForNewStream();
   223  
   224  protected:
   225      /// @private
   226      std::shared_ptr<Priv> m_priv;
   227  };
   228  /** @} */
   229  
   230  }
   231  
   232  #endif // OPENCV_GAPI_GCOMPILED_HPP