mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-20 12:55:15 +08:00

Migrate G-API module from main repo to opencv_contrib #3827 Related to https://github.com/opencv/opencv/pull/26469 Required https://github.com/opencv/opencv/pull/26527 CI: https://github.com/opencv/ci-gha-workflow/pull/201 TODO: - [x] Python types generator fix - [x] CI update ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
// 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) 2018 Intel Corporation
|
|
|
|
|
|
#include "../test_precomp.hpp"
|
|
#include "../gapi_mock_kernels.hpp"
|
|
|
|
#include "compiler/gmodel.hpp"
|
|
#include "compiler/gcompiler.hpp"
|
|
|
|
namespace opencv_test {
|
|
|
|
namespace {
|
|
|
|
struct MockMeta
|
|
{
|
|
static const char* name() { return "MockMeta"; }
|
|
};
|
|
|
|
class GMockBackendImpl final: public cv::gapi::GBackend::Priv
|
|
{
|
|
virtual void unpackKernel(ade::Graph &,
|
|
const ade::NodeHandle &,
|
|
const cv::GKernelImpl &) override
|
|
{
|
|
// Do nothing here
|
|
}
|
|
|
|
virtual EPtr compile(const ade::Graph &,
|
|
const cv::GCompileArgs &,
|
|
const std::vector<ade::NodeHandle> &) const override
|
|
{
|
|
// Do nothing here as well
|
|
return {};
|
|
}
|
|
|
|
virtual void addBackendPasses(ade::ExecutionEngineSetupContext &ectx) override
|
|
{
|
|
ectx.addPass("transform", "set_mock_meta", [](ade::passes::PassContext &ctx) {
|
|
ade::TypedGraph<MockMeta> me(ctx.graph);
|
|
for (const auto &nh : me.nodes())
|
|
{
|
|
me.metadata(nh).set(MockMeta{});
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
static cv::gapi::GBackend mock_backend(std::make_shared<GMockBackendImpl>());
|
|
|
|
GAPI_OCV_KERNEL(MockFoo, I::Foo)
|
|
{
|
|
static void run(const cv::Mat &, cv::Mat &) { /*Do nothing*/ }
|
|
static cv::gapi::GBackend backend() { return mock_backend; } // FIXME: Must be removed
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
TEST(GBackend, CustomPassesExecuted)
|
|
{
|
|
cv::GMat in;
|
|
cv::GMat out = I::Foo::on(in);
|
|
cv::GComputation c(in, out);
|
|
|
|
// Prepare compilation parameters manually
|
|
const auto in_meta = cv::GMetaArg(cv::GMatDesc{CV_8U,1,cv::Size(32,32)});
|
|
const auto pkg = cv::gapi::kernels<MockFoo>();
|
|
|
|
// Directly instantiate G-API graph compiler and run partial compilation
|
|
cv::gimpl::GCompiler compiler(c, {in_meta}, cv::compile_args(pkg));
|
|
cv::gimpl::GCompiler::GPtr graph = compiler.generateGraph();
|
|
compiler.runPasses(*graph);
|
|
|
|
// Inspect the graph and verify the metadata written by Mock backend
|
|
ade::TypedGraph<MockMeta> me(*graph);
|
|
EXPECT_LT(0u, static_cast<std::size_t>(me.nodes().size()));
|
|
for (const auto &nh : me.nodes())
|
|
{
|
|
EXPECT_TRUE(me.metadata(nh).contains<MockMeta>());
|
|
}
|
|
}
|
|
|
|
} // namespace opencv_test
|