python.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. };
  28. using Impl = std::function<cv::GRunArgs(const GPythonContext&)>;
  29. class GAPI_EXPORTS GPythonKernel
  30. {
  31. public:
  32. GPythonKernel() = default;
  33. GPythonKernel(Impl run);
  34. cv::GRunArgs operator()(const GPythonContext& ctx);
  35. private:
  36. Impl m_run;
  37. };
  38. class GAPI_EXPORTS GPythonFunctor : public cv::gapi::GFunctor
  39. {
  40. public:
  41. using Meta = cv::GKernel::M;
  42. GPythonFunctor(const char* id, const Meta &meta, const Impl& impl);
  43. GKernelImpl impl() const override;
  44. gapi::GBackend backend() const override;
  45. private:
  46. GKernelImpl impl_;
  47. };
  48. } // namespace python
  49. } // namespace gapi
  50. } // namespace cv
  51. #endif // OPENCV_GAPI_PYTHON_API_HPP