// 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-2020 Intel Corporation
+// Copyright (C) 2018-2021 Intel Corporation
#ifndef OPENCV_GAPI_GKERNEL_HPP
const std::vector<GTransform>& get_transformations() const;
/**
+ * @brief Returns vector of kernel ids included in the package
+ *
+ * @return vector of kernel ids included in the package
+ */
+ std::vector<std::string> get_kernel_ids() const;
+
+ /**
* @brief Test if a particular kernel _implementation_ KImpl is
* included in this kernel package.
*
}
/**
+ * @brief Adds a new kernel based on it's backend and id into the kernel package
+ *
+ * @param backend backend associated with the kernel
+ * @param kernel_id a name/id of the kernel
+ */
+ void include(const cv::gapi::GBackend& backend, const std::string& kernel_id)
+ {
+ removeAPI(kernel_id);
+ m_id_kernels[kernel_id] = std::make_pair(backend, GKernelImpl{{}, {}});
+ }
+
+ /**
* @brief Lists all backends which are included into package
*
* @return vector of backends
// 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) 2020 Intel Corporation
+// Copyright (C) 2020-2021 Intel Corporation
#ifndef OPENCV_GAPI_S11N_HPP
#define OPENCV_GAPI_S11N_HPP
GAPI_EXPORTS cv::GRunArgs getRunArgs(const std::vector<char> &p);
+ GAPI_EXPORTS std::vector<std::string> getVectorOfStrings(const std::vector<char> &p);
+
template<typename... Types>
cv::GCompileArgs getCompileArgs(const std::vector<char> &p);
GAPI_EXPORTS std::vector<char> serialize(const cv::GCompileArgs&);
GAPI_EXPORTS std::vector<char> serialize(const cv::GMetaArgs&);
GAPI_EXPORTS std::vector<char> serialize(const cv::GRunArgs&);
+GAPI_EXPORTS std::vector<char> serialize(const std::vector<std::string>&);
template<> inline
cv::GComputation deserialize(const std::vector<char> &p) {
return detail::getRunArgs(p);
}
+template<> inline
+std::vector<std::string> deserialize(const std::vector<char> &p) {
+ return detail::getVectorOfStrings(p);
+}
+
template<typename T, typename... Types> inline
typename std::enable_if<std::is_same<T, GCompileArgs>::value, GCompileArgs>::
type deserialize(const std::vector<char> &p) {
// 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-2019 Intel Corporation
+// Copyright (C) 2018-2021 Intel Corporation
#include "precomp.hpp"
return m_transformations;
}
+std::vector<std::string> cv::gapi::GKernelPackage::get_kernel_ids() const
+{
+ std::vector<std::string> ids;
+ for (auto &&id : m_id_kernels)
+ {
+ ids.emplace_back(id.first);
+ }
+ return ids;
+}
+
cv::gapi::GKernelPackage cv::gapi::combine(const GKernelPackage &lhs,
const GKernelPackage &rhs)
{
// 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) 2020 Intel Corporation
+// Copyright (C) 2020-2021 Intel Corporation
#include <opencv2/gapi/s11n.hpp>
#include <opencv2/gapi/garg.hpp>
return run_args_deserialize(is);
}
+std::vector<std::string> cv::gapi::detail::getVectorOfStrings(const std::vector<char> &p) {
+ cv::gapi::s11n::ByteMemoryInStream is(p);
+ return vector_of_strings_deserialize(is);
+}
+
std::vector<char> cv::gapi::serialize(const cv::GMetaArgs& ma)
{
cv::gapi::s11n::ByteMemoryOutStream os;
return os.data();
}
+std::vector<char> cv::gapi::serialize(const std::vector<std::string>& vs)
+{
+ cv::gapi::s11n::ByteMemoryOutStream os;
+ serialize(os, vs);
+ return os.data();
+}
+
// FIXME: This function should move from S11N to GRunArg-related entities.
// it has nothing to do with the S11N as it is
cv::GRunArgsP cv::gapi::bind(cv::GRunArgs &results)
// 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) 2020 Intel Corporation
+// Copyright (C) 2020-2021 Intel Corporation
#include <set> // set
#include <map> // map
GAPI_EXPORTS void serialize(IOStream& os, const cv::GRunArgs &ra) {
os << ra;
}
+GAPI_EXPORTS void serialize(IOStream& os, const std::vector<std::string> &vs) {
+ os << vs;
+}
GAPI_EXPORTS GMetaArgs meta_args_deserialize(IIStream& is) {
GMetaArgs s;
is >> s;
is >> s;
return s;
}
+GAPI_EXPORTS std::vector<std::string> vector_of_strings_deserialize(IIStream& is) {
+ std::vector<std::string> s;
+ is >> s;
+ return s;
+}
} // namespace s11n
} // namespace gapi
// 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) 2020 Intel Corporation
+// Copyright (C) 2020-2021 Intel Corporation
#include <iostream>
#include <fstream>
GAPI_EXPORTS void serialize(IOStream& os, const cv::GCompileArgs &ca);
GAPI_EXPORTS void serialize(IOStream& os, const cv::GMetaArgs &ma);
GAPI_EXPORTS void serialize(IOStream& os, const cv::GRunArgs &ra);
+GAPI_EXPORTS void serialize(IOStream& os, const std::vector<std::string> &vs);
GAPI_EXPORTS GMetaArgs meta_args_deserialize(IIStream& is);
GAPI_EXPORTS GRunArgs run_args_deserialize(IIStream& is);
+GAPI_EXPORTS std::vector<std::string> vector_of_strings_deserialize(IIStream& is);
} // namespace s11n
} // namespace gapi
// 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
+// Copyright (C) 2018-2021 Intel Corporation
+#include <algorithm>
#include "test_precomp.hpp"
#include "gapi_mock_kernels.hpp"
EXPECT_FALSE(pkg.includes<J::Qux>());
}
+TEST(KernelPackage, Include)
+{
+ namespace J = Jupiter;
+ auto pkg = cv::gapi::kernels();
+ pkg.include(J::backend(), "test.kernels.foo");
+ pkg.include(J::backend(), "test.kernels.bar");
+ EXPECT_TRUE (pkg.includes<J::Foo>());
+ EXPECT_TRUE (pkg.includes<J::Bar>());
+}
+
+TEST(KernelPackage, GetIds)
+{
+ namespace J = Jupiter;
+ auto pkg = cv::gapi::kernels();
+ pkg.include(J::backend(), "test.kernels.foo");
+ pkg.include(J::backend(), "test.kernels.bar");
+ pkg.include<J::Baz>();
+ auto ids = pkg.get_kernel_ids();
+ EXPECT_NE(ids.end(), std::find(ids.begin(), ids.end(), "test.kernels.foo"));
+ EXPECT_NE(ids.end(), std::find(ids.begin(), ids.end(), "test.kernels.bar"));
+ EXPECT_NE(ids.end(), std::find(ids.begin(), ids.end(), "test.kernels.baz"));
+}
+
TEST(KernelPackage, IncludesAPI)
{
namespace J = Jupiter;
}
}
+TEST_F(S11N_Basic, Test_Vector_Of_Strings) {
+ std::vector<std::string> vs{"hello", "world", "42"};
+
+ const std::vector<char> ser = cv::gapi::serialize(vs);
+ auto des = cv::gapi::deserialize<std::vector<std::string>>(ser);
+ EXPECT_EQ("hello", des[0]);
+ EXPECT_EQ("world", des[1]);
+ EXPECT_EQ("42", des[2]);
+}
+
TEST_F(S11N_Basic, Test_RunArg_RMat) {
cv::Mat mat = cv::Mat::eye(cv::Size(128, 64), CV_8UC3);
cv::RMat rmat = cv::make_rmat<MyRMatAdapter>(mat, 42, "It actually works");