1 #include <fluid_test_computations.hpp>
2 #include <opencv2/gapi.hpp>
3 #include <ie_preprocess_gapi_kernels.hpp>
5 #define CV_MAT_CHANNELS(flags) (((flags) >> CV_CN_SHIFT) + 1)
9 struct FluidComputation::Priv
12 std::vector<cv::gapi::own::Mat> m_v_in;
13 std::vector<cv::gapi::own::Mat> m_v_out;
16 FluidComputation::FluidComputation(Priv *priv)
20 void FluidComputation::warmUp()
22 m_priv->m_c.apply(m_priv->m_v_in, m_priv->m_v_out, cv::compile_args(InferenceEngine::gapi::preprocKernels()));
25 void FluidComputation::apply()
27 m_priv->m_c.apply(m_priv->m_v_in, m_priv->m_v_out);
32 cv::gapi::own::Mat to_own(test::Mat mat) { return {mat.rows, mat.cols, mat.type, mat.data}; }
34 std::vector<cv::gapi::own::Mat> to_own(std::vector<test::Mat> mats)
36 std::vector<cv::gapi::own::Mat> own_mats(mats.size());
37 for (int i = 0; i < mats.size(); i++) {
38 own_mats[i] = to_own(mats[i]);
43 template<typename... Ts, int... IIs>
44 std::vector<cv::GMat> to_vec_impl(std::tuple<Ts...> &&gmats, cv::detail::Seq<IIs...>) {
45 return { std::get<IIs>(gmats)... };
48 template<typename... Ts>
49 std::vector<cv::GMat> to_vec(std::tuple<Ts...> &&gmats) {
50 return to_vec_impl(std::move(gmats), typename cv::detail::MkSeq<sizeof...(Ts)>::type());
52 } // anonymous namespace
54 static cv::GComputation buildResizeComputation(test::Mat inMat, test::Mat outMat, int interp)
56 cv::gapi::own::Size sz_in { inMat.cols, inMat.rows};
57 cv::gapi::own::Size sz_out {outMat.cols, outMat.rows};
58 int type = outMat.type;
60 switch (CV_MAT_CHANNELS(type)) {
62 out = InferenceEngine::gapi::ScalePlane::on(in, type, sz_in, sz_out, interp);
66 int depth = CV_MAT_DEPTH(type);
67 int type1 = CV_MAKE_TYPE(depth, 1);
68 cv::GMat in0, in1, in2, out0, out1, out2;
69 std::tie(in0, in1, in2) = InferenceEngine::gapi::Split3::on(in);
70 out0 = InferenceEngine::gapi::ScalePlane::on(in0, type1, sz_in, sz_out, interp);
71 out1 = InferenceEngine::gapi::ScalePlane::on(in1, type1, sz_in, sz_out, interp);
72 out2 = InferenceEngine::gapi::ScalePlane::on(in2, type1, sz_in, sz_out, interp);
73 out = InferenceEngine::gapi::Merge3::on(out0, out1, out2);
76 default: GAPI_Assert(!"ERROR: unsupported number of channels!");
79 return cv::GComputation(in, out);
82 FluidResizeComputation::FluidResizeComputation(test::Mat inMat, test::Mat outMat, int interp)
83 : FluidComputation(new Priv{buildResizeComputation(inMat, outMat, interp)
89 static cv::GComputation buildSplitComputation(int planes)
91 std::vector<cv::GMat> ins(1);
92 std::vector<cv::GMat> outs(planes);
95 case 2: outs = to_vec(InferenceEngine::gapi::Split2::on(ins[0])); break;
96 case 3: outs = to_vec(InferenceEngine::gapi::Split3::on(ins[0])); break;
97 case 4: outs = to_vec(InferenceEngine::gapi::Split4::on(ins[0])); break;
98 default: GAPI_Assert(false);
101 return cv::GComputation(ins, outs);
104 FluidSplitComputation::FluidSplitComputation(test::Mat inMat, std::vector<test::Mat> outMats)
105 : FluidComputation(new Priv{buildSplitComputation(outMats.size())
111 static cv::GComputation buildMergeComputation(int planes)
113 std::vector<cv::GMat> ins(planes);
114 std::vector<cv::GMat> outs(1);
117 case 2: outs[0] = InferenceEngine::gapi::Merge2::on(ins[0], ins[1]); break;
118 case 3: outs[0] = InferenceEngine::gapi::Merge3::on(ins[0], ins[1], ins[2]); break;
119 case 4: outs[0] = InferenceEngine::gapi::Merge4::on(ins[0], ins[1], ins[2], ins[3]); break;
120 default: GAPI_Assert(false);
123 return cv::GComputation(ins, outs);
126 FluidMergeComputation::FluidMergeComputation(std::vector<test::Mat> inMats, test::Mat outMat)
127 : FluidComputation(new Priv{buildMergeComputation(inMats.size())
133 } // namespace opencv_test