Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / ie_preprocess_gapi_kernels.hpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6
7 #include <tuple>
8
9 #include <opencv2/gapi.hpp>
10 #include <opencv2/gapi/gmat.hpp>
11 #include <opencv2/gapi/gkernel.hpp>
12
13 namespace InferenceEngine {
14 namespace gapi {
15     using Size = cv::gapi::own::Size;
16
17     using GMat2 = std::tuple<cv::GMat, cv::GMat>;
18     using GMat3 = std::tuple<cv::GMat, cv::GMat, cv::GMat>;
19     using GMat4 = std::tuple<cv::GMat, cv::GMat, cv::GMat, cv::GMat>;
20
21     G_TYPED_KERNEL(ChanToPlane, <cv::GMat(cv::GMat, int)>, "com.intel.ie.chan_to_plane") {
22         static cv::GMatDesc outMeta(const cv::GMatDesc &in, int) {
23             return in.withType(in.depth, 1);
24         }
25     };
26
27     G_TYPED_KERNEL(ScalePlane, <cv::GMat(cv::GMat, int, Size, Size, int)>, "com.intel.ie.scale_plane") {
28         static cv::GMatDesc outMeta(const cv::GMatDesc &in, int type, const Size &szIn, const Size &szOut, int) {
29             GAPI_Assert(type == in.depth);
30             return in.withSize(szOut);
31         }
32     };
33
34     G_TYPED_KERNEL_M(ScalePlanes, <GMat3(cv::GMat, int, Size, Size, int)>, "com.intel.ie.scale_planes") {
35         static std::tuple<cv::GMatDesc, cv::GMatDesc, cv::GMatDesc> outMeta(const cv::GMatDesc &in, int /*type*/, const Size &szIn, const Size &szOut, int) {
36             cv::GMatDesc out_desc;
37             out_desc.depth = in.depth;
38             out_desc.chan  = 1;
39             out_desc.size = szOut;
40             return std::make_tuple(out_desc, out_desc, out_desc);
41         }
42     };
43
44     G_TYPED_KERNEL(Merge2, <cv::GMat(cv::GMat, cv::GMat)>, "com.intel.ie.merge2") {
45         static cv::GMatDesc outMeta(const cv::GMatDesc &in, const cv::GMatDesc &) {
46             // FIXME: check a/b are equal!
47             return in.withType(in.depth, 2);
48         }
49     };
50
51     G_TYPED_KERNEL(Merge3, <cv::GMat(cv::GMat, cv::GMat, cv::GMat)>, "com.intel.ie.merge3") {
52         static cv::GMatDesc outMeta(const cv::GMatDesc &in, const cv::GMatDesc &, const cv::GMatDesc &) {
53             // FIXME: check a/b are equal!
54             return in.withType(in.depth, 3);
55         }
56     };
57
58     G_TYPED_KERNEL(Merge4, <cv::GMat(cv::GMat, cv::GMat, cv::GMat, cv::GMat)>, "com.intel.ie.merge4") {
59         static cv::GMatDesc outMeta(const cv::GMatDesc& in,
60                                     const cv::GMatDesc&, const cv::GMatDesc&, const cv::GMatDesc&) {
61             // FIXME: check a/b are equal!
62             return in.withType(in.depth, 4);
63         }
64     };
65
66     G_TYPED_KERNEL_M(Split2, <GMat2(cv::GMat)>, "com.intel.ie.split2") {
67         static std::tuple<cv::GMatDesc, cv::GMatDesc> outMeta(const cv::GMatDesc& in) {
68             const auto out_depth = in.depth;
69             const auto out_desc  = in.withType(out_depth, 1);
70             return std::make_tuple(out_desc, out_desc);
71         }
72     };
73
74     G_TYPED_KERNEL_M(Split3, <GMat3(cv::GMat)>, "com.intel.ie.split3") {
75         static std::tuple<cv::GMatDesc, cv::GMatDesc, cv::GMatDesc> outMeta(const cv::GMatDesc& in) {
76             const auto out_depth = in.depth;
77             const auto out_desc  = in.withType(out_depth, 1);
78             return std::make_tuple(out_desc, out_desc, out_desc);
79         }
80     };
81
82     G_TYPED_KERNEL_M(Split4, <GMat4(cv::GMat)>, "com.intel.ie.split4") {
83         static std::tuple<cv::GMatDesc, cv::GMatDesc, cv::GMatDesc, cv::GMatDesc> outMeta(const cv::GMatDesc& in) {
84             const auto out_depth = in.depth;
85             const auto out_desc  = in.withType(out_depth, 1);
86             return std::make_tuple(out_desc, out_desc, out_desc, out_desc);
87         }
88     };
89
90     cv::gapi::GKernelPackage preprocKernels();
91
92 }  // namespace gapi
93 }  // namespace InferenceEngine