protected:
GArrayU(); // Default constructor
+ GArrayU(const detail::VectorRef& vref); // Constant value constructor
template<class> friend class cv::GArray; // (available to GArray<T> only)
void setConstructFcn(ConstructVec &&cv); // Store T-aware constructor
template<typename T> class GArray
{
public:
+ // Host type (or Flat type) - the type this GArray is actually
+ // specified to.
+ using HT = typename detail::flatten_g<typename std::decay<T>::type>::type;
+
+ explicit GArray(const std::vector<HT>& v) // Constant value constructor
+ : m_ref(detail::GArrayU(detail::VectorRef(v))) { putDetails(); }
+ explicit GArray(std::vector<HT>&& v) // Move-constructor
+ : m_ref(detail::GArrayU(detail::VectorRef(std::move(v)))) { putDetails(); }
GArray() { putDetails(); } // Empty constructor
explicit GArray(detail::GArrayU &&ref) // GArrayU-based constructor
: m_ref(ref) { putDetails(); } // (used by GCall, not for users)
detail::GArrayU strip() const { return m_ref; }
private:
- // Host type (or Flat type) - the type this GArray is actually
- // specified to.
- using HT = typename detail::flatten_g<typename std::decay<T>::type>::type;
-
static void VCTor(detail::VectorRef& vref) {
vref.reset<HT>();
vref.storeKind<HT>();
}
cv::GOrigin::GOrigin(GShape s, cv::gimpl::ConstVal v)
- : shape(s), node(cv::GNode::Const()), value(v), port(INVALID_PORT), kind(cv::detail::OpaqueKind::CV_UNKNOWN)
+ : shape(s), node(cv::GNode::Const()), value(v), port(INVALID_PORT),
+ kind(util::holds_alternative<detail::VectorRef>(v)
+ ? util::get<detail::VectorRef>(v).getKind()
+ : cv::detail::OpaqueKind::CV_UNKNOWN)
{
}
{
static GScalarDesc outMeta(const GArrayDesc &) { return empty_scalar_desc(); }
};
+G_TYPED_KERNEL(PointIncrement, <GPointArray(GMat, GPointArray)>, "test.point_increment")
+{
+ static GArrayDesc outMeta(const GMatDesc&, const GArrayDesc&) { return empty_array_desc(); }
+};
} // namespace ThisTest
namespace
}
};
+GAPI_OCV_KERNEL(OCVPointIncrement, ThisTest::PointIncrement)
+{
+ static void run(const cv::Mat&, const std::vector<cv::Point>& in, std::vector<cv::Point>& out)
+ {
+ for (const auto& el : in)
+ out.emplace_back(el + Point(1,1));
+ }
+};
+
cv::Mat cross(int w, int h)
{
cv::Mat mat = cv::Mat::eye(h, w, CV_8UC1)*255;
EXPECT_EQ(10, out_count[0]);
}
+TEST(GArray, GArrayConstValInitialization)
+{
+ std::vector<cv::Point> initial_vec {Point(0,0), Point(1,1), Point(2,2)};
+ std::vector<cv::Point> ref_vec {Point(1,1), Point(2,2), Point(3,3)};
+ std::vector<cv::Point> out_vec;
+ cv::Mat in_mat;
+
+ cv::GComputationT<ThisTest::GPointArray(cv::GMat)> c([&](cv::GMat in)
+ {
+ // Initialization
+ ThisTest::GPointArray test_garray(initial_vec);
+ return ThisTest::PointIncrement::on(in, test_garray);
+ });
+ auto cc = c.compile(cv::descr_of(in_mat),
+ cv::compile_args(cv::gapi::kernels<OCVPointIncrement>()));
+ cc(in_mat, out_vec);
+
+ EXPECT_EQ(ref_vec, out_vec);
+}
+
+TEST(GArray, GArrayRValInitialization)
+{
+ std::vector<cv::Point> ref_vec {Point(1,1), Point(2,2), Point(3,3)};
+ std::vector<cv::Point> out_vec;
+ cv::Mat in_mat;
+
+ cv::GComputationT<ThisTest::GPointArray(cv::GMat)> c([&](cv::GMat in)
+ {
+ // Rvalue initialization
+ ThisTest::GPointArray test_garray({Point(0,0), Point(1,1), Point(2,2)});
+ return ThisTest::PointIncrement::on(in, test_garray);
+ });
+ auto cc = c.compile(cv::descr_of(in_mat),
+ cv::compile_args(cv::gapi::kernels<OCVPointIncrement>()));
+ cc(in_mat, out_vec);
+
+ EXPECT_EQ(ref_vec, out_vec);
+}
+
TEST(GArray_VectorRef, TestMov)
{
// Warning: this test is testing some not-very-public APIs