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