// This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // // Copyright (C) 2019 Intel Corporation #ifndef OPENCV_GAPI_PATTERN_MATCHING_HPP #define OPENCV_GAPI_PATTERN_MATCHING_HPP #include #include #include #include #include "compiler/gmodel.hpp" namespace cv { namespace gimpl { struct SubgraphMatch { using M = std::unordered_map< ade::NodeHandle // Pattern graph node , ade::NodeHandle // Test graph node , ade::HandleHasher >; using S = std::unordered_set< ade::NodeHandle , ade::HandleHasher >; M inputDataNodes; M startOpNodes; M finishOpNodes; M outputDataNodes; std::vector inputTestDataNodes; std::vector outputTestDataNodes; std::list internalLayers; // FIXME: switch to operator bool() instead bool ok() const { return !inputDataNodes.empty() && !startOpNodes.empty() && !finishOpNodes.empty() && !outputDataNodes.empty() && !inputTestDataNodes.empty() && !outputTestDataNodes.empty(); } S nodes() const { S allNodes {}; allNodes.insert(inputTestDataNodes.begin(), inputTestDataNodes.end()); for (const auto& startOpMatch : startOpNodes) { allNodes.insert(startOpMatch.second); } for (const auto& finishOpMatch : finishOpNodes) { allNodes.insert(finishOpMatch.second); } allNodes.insert(outputTestDataNodes.begin(), outputTestDataNodes.end()); allNodes.insert(internalLayers.begin(), internalLayers.end()); return allNodes; } S startOps() { S sOps; for (const auto& opMatch : startOpNodes) { sOps.insert(opMatch.second); } return sOps; } S finishOps() { S fOps; for (const auto& opMatch : finishOpNodes) { fOps.insert(opMatch.second); } return fOps; } std::vector protoIns() { return inputTestDataNodes; } std::vector protoOuts() { return outputTestDataNodes; } }; GAPI_EXPORTS SubgraphMatch findMatches(const cv::gimpl::GModel::Graph& patternGraph, const cv::gimpl::GModel::Graph& compGraph); } //namespace gimpl } //namespace cv #endif // OPENCV_GAPI_PATTERN_MATCHING_HPP