Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / test / gapi_gcomputation_tests.cpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2018-2019 Intel Corporation
6
7
8 #include "test_precomp.hpp"
9 #include "opencv2/gapi/cpu/gcpukernel.hpp"
10
11 namespace opencv_test
12 {
13
14   namespace
15   {
16       G_TYPED_KERNEL(CustomResize, <cv::GMat(cv::GMat, cv::Size, double, double, int)>, "org.opencv.customk.resize")
17       {
18           static cv::GMatDesc outMeta(cv::GMatDesc in, cv::Size sz, double fx, double fy, int) {
19               if (sz.width != 0 && sz.height != 0)
20               {
21                   return in.withSize(to_own(sz));
22               }
23               else
24               {
25                   GAPI_Assert(fx != 0. && fy != 0.);
26                   return in.withSize
27                     (cv::gapi::own::Size(static_cast<int>(std::round(in.size.width  * fx)),
28                                          static_cast<int>(std::round(in.size.height * fy))));
29               }
30           }
31       };
32
33       GAPI_OCV_KERNEL(CustomResizeImpl, CustomResize)
34       {
35           static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)
36           {
37               cv::resize(in, out, sz, fx, fy, interp);
38           }
39       };
40
41       struct GComputationApplyTest: public ::testing::Test
42       {
43           cv::GMat in;
44           cv::Mat  in_mat;
45           cv::Mat  out_mat;
46           cv::GComputation m_c;
47
48           GComputationApplyTest() : in_mat(300, 300, CV_8UC1),
49                                     m_c(cv::GIn(in), cv::GOut(CustomResize::on(in, cv::Size(100, 100),
50                                                                                0.0, 0.0, cv::INTER_LINEAR)))
51           {
52           }
53       };
54   }
55
56   TEST_F(GComputationApplyTest, ThrowDontPassCustomKernel)
57   {
58       EXPECT_THROW(m_c.apply(in_mat, out_mat), std::logic_error);
59   }
60
61   TEST_F(GComputationApplyTest, NoThrowPassCustomKernel)
62   {
63       const auto pkg = cv::gapi::kernels<CustomResizeImpl>();
64
65       ASSERT_NO_THROW(m_c.apply(in_mat, out_mat, cv::compile_args(pkg)));
66   }
67
68 } // namespace opencv_test