python.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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) 2021 Intel Corporation
  6. #ifndef OPENCV_GAPI_PYTHON_API_HPP
  7. #define OPENCV_GAPI_PYTHON_API_HPP
  8. #include <opencv2/gapi/gkernel.hpp> // GKernelPackage
  9. #include <opencv2/gapi/own/exports.hpp> // GAPI_EXPORTS
  10. namespace cv {
  11. namespace gapi {
  12. /**
  13. * @brief This namespace contains G-API Python backend functions,
  14. * structures, and symbols.
  15. *
  16. * This functionality is required to enable G-API custom operations
  17. * and kernels when using G-API from Python, no need to use it in the
  18. * C++ form.
  19. */
  20. namespace python {
  21. GAPI_EXPORTS cv::gapi::GBackend backend();
  22. struct GPythonContext
  23. {
  24. const cv::GArgs &ins;
  25. const cv::GMetaArgs &in_metas;
  26. const cv::GTypesInfo &out_info;
  27. cv::optional<cv::GArg> m_state;
  28. };
  29. using Impl = std::function<cv::GRunArgs(const GPythonContext&)>;
  30. using Setup = std::function<cv::GArg(const GMetaArgs&, const GArgs&)>;
  31. class GAPI_EXPORTS GPythonKernel
  32. {
  33. public:
  34. GPythonKernel() = default;
  35. GPythonKernel(Impl run, Setup setup);
  36. Impl run;
  37. Setup setup = nullptr;
  38. bool is_stateful = false;
  39. };
  40. class GAPI_EXPORTS GPythonFunctor : public cv::gapi::GFunctor
  41. {
  42. public:
  43. using Meta = cv::GKernel::M;
  44. GPythonFunctor(const char* id, const Meta& meta, const Impl& impl,
  45. const Setup& setup = nullptr);
  46. GKernelImpl impl() const override;
  47. gapi::GBackend backend() const override;
  48. private:
  49. GKernelImpl impl_;
  50. };
  51. } // namespace python
  52. } // namespace gapi
  53. } // namespace cv
  54. #endif // OPENCV_GAPI_PYTHON_API_HPP