@@ -227,6 +227,73 @@ namespace
227
227
}
228
228
};
229
229
230
+ G_TYPED_KERNEL (GToInterleaved, <GMat(GMatP)>, " org.opencv.test.to_interleaved" )
231
+ {
232
+ static GMatDesc outMeta (GMatDesc in)
233
+ {
234
+ GAPI_Assert (in.planar == true );
235
+ GAPI_Assert (in.chan == 3 );
236
+ return in.asInterleaved ();
237
+ }
238
+ };
239
+
240
+ G_TYPED_KERNEL (GToPlanar, <GMatP(GMat)>, " org.opencv.test.to_planar" )
241
+ {
242
+ static GMatDesc outMeta (GMatDesc in)
243
+ {
244
+ GAPI_Assert (in.planar == false );
245
+ GAPI_Assert (in.chan == 3 );
246
+ return in.asPlanar ();
247
+ }
248
+ };
249
+
250
+ GAPI_OCV_KERNEL (GToInterleavedImpl, GToInterleaved)
251
+ {
252
+ static void run (const cv::Mat& in, cv::Mat& out)
253
+ {
254
+ constexpr int inPlanesCount = 3 ;
255
+ int inPlaneHeight = in.rows / inPlanesCount;
256
+
257
+ std::vector<cv::Mat> inPlanes (inPlanesCount);
258
+ for (int i = 0 ; i < inPlanesCount; ++i)
259
+ {
260
+ int startRow = i * inPlaneHeight;
261
+ int endRow = startRow + inPlaneHeight;
262
+ inPlanes[i] = in.rowRange (startRow, endRow);
263
+ }
264
+
265
+ cv::merge (inPlanes, out);
266
+ }
267
+ };
268
+
269
+ GAPI_OCV_KERNEL (GToPlanarImpl, GToPlanar)
270
+ {
271
+ static void run (const cv::Mat& in, cv::Mat& out)
272
+ {
273
+ std::vector<cv::Mat> inPlanes;
274
+ cv::split (in, inPlanes);
275
+ cv::vconcat (inPlanes, out);
276
+ }
277
+ };
278
+
279
+ G_TYPED_KERNEL (GCompoundToInterleavedToPlanar, <GMatP(GMatP)>,
280
+ " org.opencv.test.compound_to_interleaved_to_planar" )
281
+ {
282
+ static GMatDesc outMeta (GMatDesc in)
283
+ {
284
+ GAPI_Assert (in.planar == true );
285
+ GAPI_Assert (in.chan == 3 );
286
+ return in;
287
+ }
288
+ };
289
+
290
+ GAPI_COMPOUND_KERNEL (GCompoundToInterleavedToPlanarImpl, GCompoundToInterleavedToPlanar)
291
+ {
292
+ static GMatP expand (cv::GMatP in)
293
+ {
294
+ return GToPlanar::on (GToInterleaved::on (in));
295
+ }
296
+ };
230
297
} // namespace
231
298
232
299
// FIXME avoid cv::combine that use custom and default kernels together
@@ -496,5 +563,30 @@ TEST(GCompoundKernel, RightGArrayHandle)
496
563
497
564
EXPECT_EQ (0 , cvtest::norm (out_mat, ref_mat, NORM_INF));
498
565
566
+ }
567
+
568
+ TEST (GCompoundKernel, ToInterleavedToPlanar)
569
+ {
570
+ cv::GMatP in;
571
+ cv::GMatP out = GCompoundToInterleavedToPlanar::on (in);
572
+ const auto pkg = cv::gapi::kernels<GCompoundToInterleavedToPlanarImpl,
573
+ GToInterleavedImpl,
574
+ GToPlanarImpl>();
575
+
576
+ cv::GComputation comp (cv::GIn (in), cv::GOut (out));
577
+
578
+ constexpr int numPlanes = 3 ;
579
+ cv::Mat in_mat (cv::Size (15 , 15 ), CV_8UC1),
580
+ out_mat,
581
+ ref_mat;
582
+
583
+ cv::randu (in_mat, 0 , 255 );
584
+ ref_mat = in_mat;
585
+
586
+ comp.compile (cv::descr_of (in_mat).asPlanar (numPlanes), cv::compile_args (pkg))
587
+ (cv::gin (in_mat), cv::gout (out_mat));
588
+
589
+ EXPECT_EQ (0 , cvtest::norm (out_mat, ref_mat, NORM_INF));
590
+
499
591
}
500
592
} // opencv_test
0 commit comments