Path: blob/master/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp
16339 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#ifndef OPENCV_GAPI_IMGPROC_TESTS_INL_HPP8#define OPENCV_GAPI_IMGPROC_TESTS_INL_HPP910#include "opencv2/gapi/imgproc.hpp"11#include "gapi_imgproc_tests.hpp"1213namespace opencv_test14{15TEST_P(Filter2DTest, AccuracyTest)16{17compare_f cmpF;18MatType type = 0;19int kernSize = 0, borderType = 0, dtype = 0;20cv::Size sz;21bool initOut = false;22cv::GCompileArgs compile_args;23std::tie(cmpF, type, kernSize, sz, borderType, dtype, initOut, compile_args) = GetParam();24initMatsRandN(type, sz, dtype, initOut);2526cv::Point anchor = {-1, -1};27double delta = 0;2829cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 );30cv::Scalar kernMean = cv::Scalar(1.0);31cv::Scalar kernStddev = cv::Scalar(2.0/3);32randn(kernel, kernMean, kernStddev);3334// G-API code //////////////////////////////////////////////////////////////35cv::GMat in;36auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType);3738cv::GComputation c(in, out);39c.apply(in_mat1, out_mat_gapi, std::move(compile_args));40// OpenCV code /////////////////////////////////////////////////////////////41{42cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);43}44// Comparison //////////////////////////////////////////////////////////////45{46EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));47EXPECT_EQ(out_mat_gapi.size(), sz);48}49}5051TEST_P(BoxFilterTest, AccuracyTest)52{53compare_f cmpF;54MatType type = 0;55int filterSize = 0, borderType = 0, dtype = 0;56cv::Size sz;57bool initOut = false;58cv::GCompileArgs compile_args;59std::tie(cmpF, type, filterSize, sz, borderType, dtype, initOut, compile_args) = GetParam();60initMatsRandN(type, sz, dtype, initOut);6162cv::Point anchor = {-1, -1};63bool normalize = true;6465// G-API code //////////////////////////////////////////////////////////////66cv::GMat in;67auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);6869cv::GComputation c(in, out);70c.apply(in_mat1, out_mat_gapi, std::move(compile_args));71// OpenCV code /////////////////////////////////////////////////////////////72{73cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);74}75// Comparison //////////////////////////////////////////////////////////////76{77EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));78EXPECT_EQ(out_mat_gapi.size(), sz);79}80}8182TEST_P(SepFilterTest, AccuracyTest)83{84compare_f cmpF;85MatType type = 0;86int kernSize = 0, dtype = 0;87cv::Size sz;88bool initOut = false;89cv::GCompileArgs compile_args;90std::tie(cmpF, type, kernSize, sz, dtype, initOut, compile_args) = GetParam();9192cv::Mat kernelX(kernSize, 1, CV_32F);93cv::Mat kernelY(kernSize, 1, CV_32F);94randu(kernelX, -1, 1);95randu(kernelY, -1, 1);96initMatsRandN(type, sz, dtype, initOut);9798cv::Point anchor = cv::Point(-1, -1);99100// G-API code //////////////////////////////////////////////////////////////101cv::GMat in;102auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() );103104cv::GComputation c(in, out);105c.apply(in_mat1, out_mat_gapi, std::move(compile_args));106// OpenCV code /////////////////////////////////////////////////////////////107{108cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );109}110// Comparison //////////////////////////////////////////////////////////////111{112EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));113EXPECT_EQ(out_mat_gapi.size(), sz);114}115}116117TEST_P(BlurTest, AccuracyTest)118{119compare_f cmpF;120MatType type = 0;121int filterSize = 0, borderType = 0;122cv::Size sz;123bool initOut = false;124cv::GCompileArgs compile_args;125std::tie(cmpF, type, filterSize, sz, borderType, initOut, compile_args) = GetParam();126initMatsRandN(type, sz, type, initOut);127128cv::Point anchor = {-1, -1};129130// G-API code //////////////////////////////////////////////////////////////131cv::GMat in;132auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType);133134cv::GComputation c(in, out);135c.apply(in_mat1, out_mat_gapi, std::move(compile_args));136// OpenCV code /////////////////////////////////////////////////////////////137{138cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);139}140// Comparison //////////////////////////////////////////////////////////////141{142EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));143EXPECT_EQ(out_mat_gapi.size(), sz);144}145}146147TEST_P(GaussianBlurTest, AccuracyTest)148{149compare_f cmpF;150MatType type = 0;151int kernSize = 0;152cv::Size sz;153bool initOut = false;154cv::GCompileArgs compile_args;155std::tie(cmpF,type, kernSize, sz, initOut, compile_args) = GetParam();156initMatsRandN(type, sz, type, initOut);157158cv::Size kSize = cv::Size(kernSize, kernSize);159double sigmaX = rand();160161// G-API code //////////////////////////////////////////////////////////////162cv::GMat in;163auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX);164165cv::GComputation c(in, out);166c.apply(in_mat1, out_mat_gapi, std::move(compile_args));167// OpenCV code /////////////////////////////////////////////////////////////168{169cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);170}171// Comparison //////////////////////////////////////////////////////////////172{173EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));174EXPECT_EQ(out_mat_gapi.size(), sz);175}176}177178TEST_P(MedianBlurTest, AccuracyTest)179{180compare_f cmpF;181MatType type = 0;182int kernSize = 0;183cv::Size sz;184bool initOut = false;185cv::GCompileArgs compile_args;186std::tie(cmpF, type, kernSize, sz, initOut, compile_args) = GetParam();187initMatsRandN(type, sz, type, initOut);188189// G-API code //////////////////////////////////////////////////////////////190cv::GMat in;191auto out = cv::gapi::medianBlur(in, kernSize);192193cv::GComputation c(in, out);194c.apply(in_mat1, out_mat_gapi, std::move(compile_args));195// OpenCV code /////////////////////////////////////////////////////////////196{197cv::medianBlur(in_mat1, out_mat_ocv, kernSize);198}199// Comparison //////////////////////////////////////////////////////////////200{201EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));202EXPECT_EQ(out_mat_gapi.size(), sz);203}204}205206TEST_P(ErodeTest, AccuracyTest)207{208compare_f cmpF;209MatType type = 0;210int kernSize = 0, kernType = 0;211cv::Size sz;212bool initOut = false;213cv::GCompileArgs compile_args;214std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam();215initMatsRandN(type, sz, type, initOut);216217cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));218219// G-API code //////////////////////////////////////////////////////////////220cv::GMat in;221auto out = cv::gapi::erode(in, kernel);222223cv::GComputation c(in, out);224c.apply(in_mat1, out_mat_gapi, std::move(compile_args));225// OpenCV code /////////////////////////////////////////////////////////////226{227cv::erode(in_mat1, out_mat_ocv, kernel);228}229// Comparison //////////////////////////////////////////////////////////////230{231EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));232EXPECT_EQ(out_mat_gapi.size(), sz);233}234}235236TEST_P(Erode3x3Test, AccuracyTest)237{238compare_f cmpF;239MatType type = 0;240int numIters = 0;241cv::Size sz;242bool initOut = false;243cv::GCompileArgs compile_args;244std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam();245initMatsRandN(type, sz, type, initOut);246247cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));248249// G-API code //////////////////////////////////////////////////////////////250cv::GMat in;251auto out = cv::gapi::erode3x3(in, numIters);252253cv::GComputation c(in, out);254c.apply(in_mat1, out_mat_gapi, std::move(compile_args));255// OpenCV code /////////////////////////////////////////////////////////////256{257cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);258}259// Comparison //////////////////////////////////////////////////////////////260{261EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));262EXPECT_EQ(out_mat_gapi.size(), sz);263}264}265266TEST_P(DilateTest, AccuracyTest)267{268compare_f cmpF;269MatType type = 0;270int kernSize = 0, kernType = 0;271cv::Size sz;272bool initOut = false;273cv::GCompileArgs compile_args;274std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam();275initMatsRandN(type, sz, type, initOut);276277cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));278279// G-API code //////////////////////////////////////////////////////////////280cv::GMat in;281auto out = cv::gapi::dilate(in, kernel);282283cv::GComputation c(in, out);284c.apply(in_mat1, out_mat_gapi, std::move(compile_args));285// OpenCV code /////////////////////////////////////////////////////////////286{287cv::dilate(in_mat1, out_mat_ocv, kernel);288}289// Comparison //////////////////////////////////////////////////////////////290{291EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));292EXPECT_EQ(out_mat_gapi.size(), sz);293}294}295296TEST_P(Dilate3x3Test, AccuracyTest)297{298compare_f cmpF;299MatType type = 0;300int numIters = 0;301cv::Size sz;302bool initOut = false;303cv::GCompileArgs compile_args;304std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam();305initMatsRandN(type, sz, type, initOut);306307cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));308309// G-API code //////////////////////////////////////////////////////////////310cv::GMat in;311auto out = cv::gapi::dilate3x3(in, numIters);312313cv::GComputation c(in, out);314c.apply(in_mat1, out_mat_gapi, std::move(compile_args));315// OpenCV code /////////////////////////////////////////////////////////////316{317cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);318}319// Comparison //////////////////////////////////////////////////////////////320{321EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));322EXPECT_EQ(out_mat_gapi.size(), sz);323}324}325326327TEST_P(SobelTest, AccuracyTest)328{329compare_f cmpF;330MatType type = 0;331int kernSize = 0, dtype = 0, dx = 0, dy = 0;332cv::Size sz;333bool initOut = false;334cv::GCompileArgs compile_args;335std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, initOut, compile_args) = GetParam();336initMatsRandN(type, sz, dtype, initOut);337338// G-API code //////////////////////////////////////////////////////////////339cv::GMat in;340auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize );341342cv::GComputation c(in, out);343c.apply(in_mat1, out_mat_gapi, std::move(compile_args));344// OpenCV code /////////////////////////////////////////////////////////////345{346cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);347}348// Comparison //////////////////////////////////////////////////////////////349{350EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));351EXPECT_EQ(out_mat_gapi.size(), sz);352}353}354355TEST_P(EqHistTest, AccuracyTest)356{357compare_f cmpF;358cv::Size sz;359bool initOut = false;360cv::GCompileArgs compile_args;361std::tie(cmpF, sz, initOut, compile_args) = GetParam();362initMatsRandN(CV_8UC1, sz, CV_8UC1, initOut);363364// G-API code //////////////////////////////////////////////////////////////365cv::GMat in;366auto out = cv::gapi::equalizeHist(in);367368cv::GComputation c(in, out);369c.apply(in_mat1, out_mat_gapi, std::move(compile_args));370// OpenCV code /////////////////////////////////////////////////////////////371{372cv::equalizeHist(in_mat1, out_mat_ocv);373}374// Comparison //////////////////////////////////////////////////////////////375{376EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));377EXPECT_EQ(out_mat_gapi.size(), std::get<1>(GetParam()));378}379}380381TEST_P(CannyTest, AccuracyTest)382{383compare_f cmpF;384MatType type;385int apSize = 0;386double thrLow = 0.0, thrUp = 0.0;387cv::Size sz;388bool l2gr = false, initOut = false;389cv::GCompileArgs compile_args;390std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, initOut, compile_args) = GetParam();391392initMatsRandN(type, sz, CV_8UC1, initOut);393394// G-API code //////////////////////////////////////////////////////////////395cv::GMat in;396auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr);397398cv::GComputation c(in, out);399c.apply(in_mat1, out_mat_gapi, std::move(compile_args));400// OpenCV code /////////////////////////////////////////////////////////////401{402cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);403}404// Comparison //////////////////////////////////////////////////////////////405{406EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));407EXPECT_EQ(out_mat_gapi.size(), sz);408}409}410411TEST_P(RGB2GrayTest, AccuracyTest)412{413auto param = GetParam();414auto compile_args = std::get<3>(param);415compare_f cmpF = std::get<0>(param);416initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));417418// G-API code //////////////////////////////////////////////////////////////419cv::GMat in;420auto out = cv::gapi::RGB2Gray(in);421422cv::GComputation c(in, out);423c.apply(in_mat1, out_mat_gapi, std::move(compile_args));424// OpenCV code /////////////////////////////////////////////////////////////425{426cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);427}428// Comparison //////////////////////////////////////////////////////////////429{430EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));431EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));432}433}434435TEST_P(BGR2GrayTest, AccuracyTest)436{437auto param = GetParam();438auto compile_args = std::get<3>(param);439compare_f cmpF = std::get<0>(param);440initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));441442// G-API code //////////////////////////////////////////////////////////////443cv::GMat in;444auto out = cv::gapi::BGR2Gray(in);445446cv::GComputation c(in, out);447c.apply(in_mat1, out_mat_gapi, std::move(compile_args));448// OpenCV code /////////////////////////////////////////////////////////////449{450cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);451}452// Comparison //////////////////////////////////////////////////////////////453{454EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));455EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));456}457}458459TEST_P(RGB2YUVTest, AccuracyTest)460{461auto param = GetParam();462auto compile_args = std::get<3>(param);463compare_f cmpF = std::get<0>(param);464initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));465466// G-API code //////////////////////////////////////////////////////////////467cv::GMat in;468auto out = cv::gapi::RGB2YUV(in);469470cv::GComputation c(in, out);471c.apply(in_mat1, out_mat_gapi, std::move(compile_args));472// OpenCV code /////////////////////////////////////////////////////////////473{474cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);475}476// Comparison //////////////////////////////////////////////////////////////477{478EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));479EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));480}481}482483TEST_P(YUV2RGBTest, AccuracyTest)484{485auto param = GetParam();486auto compile_args = std::get<3>(param);487compare_f cmpF = std::get<0>(param);488initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));489490491// G-API code //////////////////////////////////////////////////////////////492cv::GMat in;493auto out = cv::gapi::YUV2RGB(in);494495cv::GComputation c(in, out);496c.apply(in_mat1, out_mat_gapi, std::move(compile_args));497// OpenCV code /////////////////////////////////////////////////////////////498{499cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);500}501// Comparison //////////////////////////////////////////////////////////////502{503EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));504EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));505}506}507508TEST_P(RGB2LabTest, AccuracyTest)509{510auto param = GetParam();511auto compile_args = std::get<3>(param);512compare_f cmpF = std::get<0>(param);513initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));514515// G-API code //////////////////////////////////////////////////////////////516cv::GMat in;517auto out = cv::gapi::RGB2Lab(in);518519cv::GComputation c(in, out);520c.apply(in_mat1, out_mat_gapi, std::move(compile_args));521// OpenCV code /////////////////////////////////////////////////////////////522{523cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);524}525// Comparison //////////////////////////////////////////////////////////////526{527EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));528EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));529}530}531532TEST_P(BGR2LUVTest, AccuracyTest)533{534auto param = GetParam();535auto compile_args = std::get<3>(param);536compare_f cmpF = std::get<0>(param);537initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));538539// G-API code //////////////////////////////////////////////////////////////540cv::GMat in;541auto out = cv::gapi::BGR2LUV(in);542543cv::GComputation c(in, out);544c.apply(in_mat1, out_mat_gapi, std::move(compile_args));545// OpenCV code /////////////////////////////////////////////////////////////546{547cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);548}549// Comparison //////////////////////////////////////////////////////////////550{551EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));552EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));553}554}555556TEST_P(LUV2BGRTest, AccuracyTest)557{558auto param = GetParam();559auto compile_args = std::get<3>(param);560compare_f cmpF = std::get<0>(param);561initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));562563// G-API code //////////////////////////////////////////////////////////////564cv::GMat in;565auto out = cv::gapi::LUV2BGR(in);566567cv::GComputation c(in, out);568c.apply(in_mat1, out_mat_gapi, std::move(compile_args));569// OpenCV code /////////////////////////////////////////////////////////////570{571cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);572}573// Comparison //////////////////////////////////////////////////////////////574{575EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));576EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));577}578}579580TEST_P(BGR2YUVTest, AccuracyTest)581{582auto param = GetParam();583auto compile_args = std::get<3>(param);584compare_f cmpF = std::get<0>(param);585initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));586587// G-API code //////////////////////////////////////////////////////////////588cv::GMat in;589auto out = cv::gapi::BGR2YUV(in);590591cv::GComputation c(in, out);592c.apply(in_mat1, out_mat_gapi, std::move(compile_args));593// OpenCV code /////////////////////////////////////////////////////////////594{595cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);596}597// Comparison //////////////////////////////////////////////////////////////598{599EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));600EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));601}602}603604TEST_P(YUV2BGRTest, AccuracyTest)605{606auto param = GetParam();607auto compile_args = std::get<3>(param);608compare_f cmpF = std::get<0>(param);609initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));610611// G-API code //////////////////////////////////////////////////////////////612cv::GMat in;613auto out = cv::gapi::YUV2BGR(in);614615cv::GComputation c(in, out);616c.apply(in_mat1, out_mat_gapi, std::move(compile_args));617// OpenCV code /////////////////////////////////////////////////////////////618{619cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);620}621// Comparison //////////////////////////////////////////////////////////////622{623EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));624EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));625}626}627} // opencv_test628629#endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP630631632