}
};
+ G_TYPED_KERNEL(GToInterleaved, <GMat(GMatP)>, "org.opencv.test.to_interleaved")
+ {
+ static GMatDesc outMeta(GMatDesc in)
+ {
+ GAPI_Assert(in.planar == true);
+ GAPI_Assert(in.chan == 3);
+ return in.asInterleaved();
+ }
+ };
+
+ G_TYPED_KERNEL(GToPlanar, <GMatP(GMat)>, "org.opencv.test.to_planar")
+ {
+ static GMatDesc outMeta(GMatDesc in)
+ {
+ GAPI_Assert(in.planar == false);
+ GAPI_Assert(in.chan == 3);
+ return in.asPlanar();
+ }
+ };
+
+ GAPI_OCV_KERNEL(GToInterleavedImpl, GToInterleaved)
+ {
+ static void run(const cv::Mat& in, cv::Mat& out)
+ {
+ constexpr int inPlanesCount = 3;
+ int inPlaneHeight = in.rows / inPlanesCount;
+
+ std::vector<cv::Mat> inPlanes(inPlanesCount);
+ for (int i = 0; i < inPlanesCount; ++i)
+ {
+ int startRow = i * inPlaneHeight;
+ int endRow = startRow + inPlaneHeight;
+ inPlanes[i] = in.rowRange(startRow, endRow);
+ }
+
+ cv::merge(inPlanes, out);
+ }
+ };
+
+ GAPI_OCV_KERNEL(GToPlanarImpl, GToPlanar)
+ {
+ static void run(const cv::Mat& in, cv::Mat& out)
+ {
+ std::vector<cv::Mat> inPlanes;
+ cv::split(in, inPlanes);
+ cv::vconcat(inPlanes, out);
+ }
+ };
+
+ G_TYPED_KERNEL(GCompoundToInterleavedToPlanar, <GMatP(GMatP)>,
+ "org.opencv.test.compound_to_interleaved_to_planar")
+ {
+ static GMatDesc outMeta(GMatDesc in)
+ {
+ GAPI_Assert(in.planar == true);
+ GAPI_Assert(in.chan == 3);
+ return in;
+ }
+ };
+
+ GAPI_COMPOUND_KERNEL(GCompoundToInterleavedToPlanarImpl, GCompoundToInterleavedToPlanar)
+ {
+ static GMatP expand(cv::GMatP in)
+ {
+ return GToPlanar::on(GToInterleaved::on(in));
+ }
+ };
} // namespace
// FIXME avoid cv::combine that use custom and default kernels together
EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
}
+
+TEST(GCompoundKernel, ToInterleavedToPlanar)
+{
+ cv::GMatP in;
+ cv::GMatP out = GCompoundToInterleavedToPlanar::on(in);
+ const auto pkg = cv::gapi::kernels<GCompoundToInterleavedToPlanarImpl,
+ GToInterleavedImpl,
+ GToPlanarImpl>();
+
+ cv::GComputation comp(cv::GIn(in), cv::GOut(out));
+
+ constexpr int numPlanes = 3;
+ cv::Mat in_mat(cv::Size(15, 15), CV_8UC1),
+ out_mat,
+ ref_mat;
+
+ cv::randu(in_mat, 0, 255);
+ ref_mat = in_mat;
+
+ comp.compile(cv::descr_of(in_mat).asPlanar(numPlanes), cv::compile_args(pkg))
+ (cv::gin(in_mat), cv::gout(out_mat));
+
+ EXPECT_EQ(0, cvtest::norm(out_mat, ref_mat, NORM_INF));
+
+}
} // opencv_test