Path: blob/master/modules/gapi/test/gapi_gcomputation_tests.cpp
16337 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3//4// Copyright (C) 2018 Intel Corporation567#include "test_precomp.hpp"8#include "opencv2/gapi/cpu/gcpukernel.hpp"910namespace opencv_test11{1213namespace14{15G_TYPED_KERNEL(CustomResize, <cv::GMat(cv::GMat, cv::Size, double, double, int)>, "org.opencv.customk.resize")16{17static cv::GMatDesc outMeta(cv::GMatDesc in, cv::Size sz, double fx, double fy, int) {18if (sz.width != 0 && sz.height != 0)19{20return in.withSize(to_own(sz));21}22else23{24GAPI_Assert(fx != 0. && fy != 0.);25return in.withSize26(cv::gapi::own::Size(static_cast<int>(std::round(in.size.width * fx)),27static_cast<int>(std::round(in.size.height * fy))));28}29}30};3132GAPI_OCV_KERNEL(CustomResizeImpl, CustomResize)33{34static void run(const cv::Mat& in, cv::Size sz, double fx, double fy, int interp, cv::Mat &out)35{36cv::resize(in, out, sz, fx, fy, interp);37}38};3940struct GComputationApplyTest: public ::testing::Test41{42cv::GMat in;43cv::Mat in_mat;44cv::Mat out_mat;45cv::GComputation m_c;4647GComputationApplyTest() : in_mat(300, 300, CV_8UC1),48m_c(cv::GIn(in), cv::GOut(CustomResize::on(in, cv::Size(100, 100),490.0, 0.0, cv::INTER_LINEAR)))50{51}52};53}5455TEST_F(GComputationApplyTest, ThrowDontPassCustomKernel)56{57EXPECT_THROW(m_c.apply(in_mat, out_mat), std::logic_error);58}5960TEST_F(GComputationApplyTest, NoThrowPassCustomKernel)61{62const auto pkg = cv::gapi::kernels<CustomResizeImpl>();6364ASSERT_NO_THROW(m_c.apply(in_mat, out_mat, cv::compile_args(pkg)));65}6667} // namespace opencv_test686970