123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947 |
- // This file is part of OpenCV project.
- // It is subject to the license terms in the LICENSE file found in the top-level directory
- // of this distribution and at http://opencv.org/license.html.
- //
- // Copyright (C) 2018-2020 Intel Corporation
- #ifndef OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP
- #define OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP
- #include "gapi_imgproc_perf_tests.hpp"
- #include "../../test/common/gapi_imgproc_tests_common.hpp"
- namespace opencv_test
- {
- using namespace perf;
- namespace
- {
- void rgb2yuyv(const uchar* rgb_line, uchar* yuv422_line, int width)
- {
- CV_Assert(width % 2 == 0);
- for (int i = 0; i < width; i += 2)
- {
- uchar r = rgb_line[i * 3 ];
- uchar g = rgb_line[i * 3 + 1];
- uchar b = rgb_line[i * 3 + 2];
- yuv422_line[i * 2 ] = cv::saturate_cast<uchar>(-0.14713 * r - 0.28886 * g + 0.436 * b + 128.f); // U0
- yuv422_line[i * 2 + 1] = cv::saturate_cast<uchar>( 0.299 * r + 0.587 * g + 0.114 * b ); // Y0
- yuv422_line[i * 2 + 2] = cv::saturate_cast<uchar>(0.615 * r - 0.51499 * g - 0.10001 * b + 128.f); // V0
- r = rgb_line[i * 3 + 3];
- g = rgb_line[i * 3 + 4];
- b = rgb_line[i * 3 + 5];
- yuv422_line[i * 2 + 3] = cv::saturate_cast<uchar>(0.299 * r + 0.587 * g + 0.114 * b); // Y1
- }
- }
- void convertRGB2YUV422Ref(const cv::Mat& in, cv::Mat &out)
- {
- out.create(in.size(), CV_8UC2);
- for (int i = 0; i < in.rows; ++i)
- {
- const uchar* in_line_p = in.ptr<uchar>(i);
- uchar* out_line_p = out.ptr<uchar>(i);
- rgb2yuyv(in_line_p, out_line_p, in.cols);
- }
- }
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(SepFilterPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, dtype = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, dtype, compile_args) = GetParam();
- cv::Mat kernelX(kernSize, 1, CV_32F);
- cv::Mat kernelY(kernSize, 1, CV_32F);
- randu(kernelX, -1, 1);
- randu(kernelY, -1, 1);
- initMatrixRandN(type, sz, dtype, false);
- cv::Point anchor = cv::Point(-1, -1);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() );
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(Filter2DPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, borderType = 0, dtype = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, borderType, dtype, compile_args) = GetParam();
- initMatrixRandN(type, sz, dtype, false);
- cv::Point anchor = {-1, -1};
- double delta = 0;
- cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 );
- cv::Scalar kernMean = cv::Scalar::all(1.0);
- cv::Scalar kernStddev = cv::Scalar::all(2.0/3);
- randn(kernel, kernMean, kernStddev);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BoxFilterPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int filterSize = 0, borderType = 0, dtype = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, filterSize, sz, borderType, dtype, compile_args) = GetParam();
- initMatrixRandN(type, sz, dtype, false);
- cv::Point anchor = {-1, -1};
- bool normalize = true;
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BlurPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int filterSize = 0, borderType = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, filterSize, sz, borderType, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- cv::Point anchor = {-1, -1};
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(GaussianBlurPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam();
- cv::Size kSize = cv::Size(kernSize, kernSize);
- auto& rng = cv::theRNG();
- double sigmaX = rng();
- initMatrixRandN(type, sz, type, false);
- // OpenCV code ///////////////////////////////////////////////////////////
- cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(MedianBlurPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::medianBlur(in_mat1, out_mat_ocv, kernSize);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::medianBlur(in, kernSize);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(ErodePerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, kernType = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::erode(in_mat1, out_mat_ocv, kernel);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::erode(in, kernel);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(Erode3x3PerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int numIters = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, numIters, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3));
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::erode3x3(in, numIters);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(DilatePerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, kernType = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::dilate(in_mat1, out_mat_ocv, kernel);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::dilate(in, kernel);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(Dilate3x3PerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int numIters = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, numIters, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3));
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::dilate3x3(in, numIters);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(MorphologyExPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- cv::MorphTypes op = cv::MORPH_ERODE;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, op, compile_args) = GetParam();
- initMatrixRandN(type, sz, type, false);
- cv::MorphShapes defShape = cv::MORPH_RECT;
- int defKernSize = 3;
- cv::Mat kernel = cv::getStructuringElement(defShape, cv::Size(defKernSize, defKernSize));
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::morphologyEx(in_mat1, out_mat_ocv, op, kernel);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::morphologyEx(in, op, kernel);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(SobelPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, dtype = 0, dx = 0, dy = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, compile_args) = GetParam();
- initMatrixRandN(type, sz, dtype, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(SobelXYPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, dtype = 0, order = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, dtype, order, compile_args) = GetParam();
- cv::Mat out_mat_ocv2;
- cv::Mat out_mat_gapi2;
- initMatrixRandN(type, sz, dtype, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::Sobel(in_mat1, out_mat_ocv, dtype, order, 0, kernSize);
- cv::Sobel(in_mat1, out_mat_ocv2, dtype, 0, order, kernSize);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::SobelXY(in, dtype, order, kernSize);
- cv::GComputation c(cv::GIn(in), cv::GOut(std::get<0>(out), std::get<1>(out)));
- // Warm-up graph engine:
- c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat_gapi2), std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat_gapi2));
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_TRUE(cmpF(out_mat_gapi2, out_mat_ocv2));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- EXPECT_EQ(out_mat_gapi2.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(LaplacianPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int kernSize = 0, dtype = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, kernSize, sz, dtype, compile_args) = GetParam();
- initMatrixRandN(type, sz, dtype, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::Laplacian(in_mat1, out_mat_ocv, dtype, kernSize);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::Laplacian(in, dtype, kernSize);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BilateralFilterPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = 0;
- int dtype = 0, d = 0, borderType = BORDER_DEFAULT;
- double sigmaColor = 0, sigmaSpace = 0;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, dtype, sz, d, sigmaColor, sigmaSpace,
- compile_args) = GetParam();
- initMatrixRandN(type, sz, dtype, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::bilateralFilter(in_mat1, out_mat_ocv, d, sigmaColor, sigmaSpace, borderType);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::bilateralFilter(in, d, sigmaColor, sigmaSpace, borderType);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(CannyPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type;
- int apSize = 0;
- double thrLow = 0.0, thrUp = 0.0;
- cv::Size sz;
- bool l2gr = false;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, compile_args) = GetParam();
- initMatrixRandN(type, sz, CV_8UC1, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(GoodFeaturesPerfTest, TestPerformance)
- {
- double k = 0.04;
- compare_vector_f<cv::Point2f> cmpF;
- std::string fileName = "";
- int type = -1, maxCorners = -1, blockSize = -1;
- double qualityLevel = 0.0, minDistance = 0.0;
- bool useHarrisDetector = false;
- cv::GCompileArgs compileArgs;
- std::tie(cmpF, fileName, type, maxCorners, qualityLevel,
- minDistance, blockSize, useHarrisDetector, compileArgs) = GetParam();
- initMatFromImage(type, fileName);
- std::vector<cv::Point2f> outVecOCV, outVecGAPI;
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::goodFeaturesToTrack(in_mat1, outVecOCV, maxCorners, qualityLevel, minDistance,
- cv::noArray(), blockSize, useHarrisDetector, k);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::goodFeaturesToTrack(in, maxCorners, qualityLevel, minDistance, cv::Mat(),
- blockSize, useHarrisDetector, k);
- cv::GComputation c(cv::GIn(in), cv::GOut(out));
- // Warm-up graph engine:
- c.apply(cv::gin(in_mat1), cv::gout(outVecGAPI), std::move(compileArgs));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_mat1), cv::gout(outVecGAPI));
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(outVecGAPI, outVecOCV));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(FindContoursPerfTest, TestPerformance)
- {
- CompareMats cmpF;
- MatType type;
- cv::Size sz;
- cv::RetrievalModes mode;
- cv::ContourApproximationModes method;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, mode, method, compile_args) = GetParam();
- cv::Mat in;
- initMatForFindingContours(in, sz, type);
- cv::Point offset = cv::Point();
- std::vector<cv::Vec4i> out_hier_gapi = std::vector<cv::Vec4i>();
- std::vector<std::vector<cv::Point>> out_cnts_gapi;
- cv::GComputation c(findContoursTestGAPI(in, mode, method, std::move(compile_args),
- out_cnts_gapi, out_hier_gapi, offset));
- TEST_CYCLE()
- {
- c.apply(gin(in, offset), gout(out_cnts_gapi));
- }
- findContoursTestOpenCVCompare(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FindContoursHPerfTest, TestPerformance)
- {
- CompareMats cmpF;
- MatType type;
- cv::Size sz;
- cv::RetrievalModes mode;
- cv::ContourApproximationModes method;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, mode, method, compile_args) = GetParam();
- cv::Mat in;
- initMatForFindingContours(in, sz, type);
- cv::Point offset = cv::Point();
- std::vector<std::vector<cv::Point>> out_cnts_gapi;
- std::vector<cv::Vec4i> out_hier_gapi;
- cv::GComputation c(findContoursTestGAPI<HIERARCHY>(in, mode, method, std::move(compile_args),
- out_cnts_gapi, out_hier_gapi, offset));
- TEST_CYCLE()
- {
- c.apply(gin(in, offset), gout(out_cnts_gapi, out_hier_gapi));
- }
- findContoursTestOpenCVCompare<HIERARCHY>(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BoundingRectMatPerfTest, TestPerformance)
- {
- CompareRects cmpF;
- cv::Size sz;
- MatType type;
- bool initByVector = false;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, initByVector, compile_args) = GetParam();
- if (initByVector)
- {
- initMatByPointsVectorRandU<cv::Point_>(type, sz, -1);
- }
- else
- {
- initMatrixRandU(type, sz, -1, false);
- }
- cv::Rect out_rect_gapi;
- cv::GComputation c(boundingRectTestGAPI(in_mat1, std::move(compile_args), out_rect_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi));
- }
- boundingRectTestOpenCVCompare(in_mat1, out_rect_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(BoundingRectVector32SPerfTest, TestPerformance)
- {
- CompareRects cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- std::vector<cv::Point2i> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Rect out_rect_gapi;
- cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi));
- }
- boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(BoundingRectVector32FPerfTest, TestPerformance)
- {
- CompareRects cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- std::vector<cv::Point2f> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Rect out_rect_gapi;
- cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi));
- }
- boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(FitLine2DMatVectorPerfTest, TestPerformance)
- {
- CompareVecs<float, 4> cmpF;
- cv::Size sz;
- MatType type;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, distType, compile_args) = GetParam();
- initMatByPointsVectorRandU<cv::Point_>(type, sz, -1);
- cv::Vec4f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_mat1, distType, std::move(compile_args), out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_mat1, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine2DVector32SPerfTest, TestPerformance)
- {
- CompareVecs<float, 4> cmpF;
- cv::Size sz;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, distType, compile_args) = GetParam();
- std::vector<cv::Point2i> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Vec4f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
- out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine2DVector32FPerfTest, TestPerformance)
- {
- CompareVecs<float, 4> cmpF;
- cv::Size sz;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, distType, compile_args) = GetParam();
- std::vector<cv::Point2f> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Vec4f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
- out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine2DVector64FPerfTest, TestPerformance)
- {
- CompareVecs<float, 4> cmpF;
- cv::Size sz;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, distType, compile_args) = GetParam();
- std::vector<cv::Point2d> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Vec4f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
- out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine3DMatVectorPerfTest, TestPerformance)
- {
- CompareVecs<float, 6> cmpF;
- cv::Size sz;
- MatType type;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, distType, compile_args) = GetParam();
- initMatByPointsVectorRandU<cv::Point3_>(type, sz, -1);
- cv::Vec6f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_mat1, distType, std::move(compile_args), out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_mat1, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine3DVector32SPerfTest, TestPerformance)
- {
- CompareVecs<float, 6> cmpF;
- cv::Size sz;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, distType, compile_args) = GetParam();
- std::vector<cv::Point3i> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Vec6f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
- out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine3DVector32FPerfTest, TestPerformance)
- {
- CompareVecs<float, 6> cmpF;
- cv::Size sz;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, distType, compile_args) = GetParam();
- std::vector<cv::Point3f> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Vec6f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
- out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(FitLine3DVector64FPerfTest, TestPerformance)
- {
- CompareVecs<float, 6> cmpF;
- cv::Size sz;
- cv::DistanceTypes distType;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, distType, compile_args) = GetParam();
- std::vector<cv::Point3d> in_vector;
- initPointsVectorRandU(sz.width, in_vector);
- cv::Vec6f out_vec_gapi;
- cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
- out_vec_gapi));
- TEST_CYCLE()
- {
- c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
- }
- fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(EqHistPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC1, sz, CV_8UC1, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::equalizeHist(in_mat1, out_mat_ocv);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::equalizeHist(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BGR2RGBPerfTest, TestPerformance)
- {
- compare_f cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2RGB);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::BGR2RGB(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(RGB2GrayPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::RGB2Gray(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BGR2GrayPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::BGR2Gray(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(RGB2YUVPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::RGB2YUV(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::YUV2RGB(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BGR2I420PerfTest, TestPerformance)
- {
- compare_f cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV_I420);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::BGR2I420(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(RGB2I420PerfTest, TestPerformance)
- {
- compare_f cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV_I420);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::RGB2I420(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(I4202BGRPerfTest, TestPerformance)
- {
- compare_f cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR_I420);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::I4202BGR(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(I4202RGBPerfTest, TestPerformance)
- {
- compare_f cmpF;
- cv::Size sz;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, sz, compile_args) = GetParam();
- initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB_I420);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::I4202RGB(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(RGB2LabPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::RGB2Lab(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::BGR2LUV(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(LUV2BGRPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- // OpenCV code /////////////////////////////////////////////////////////////
- {
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);
- }
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::LUV2BGR(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- // Comparison //////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(BGR2YUVPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
- cv::GMat in;
- auto out = cv::gapi::BGR2YUV(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
- cv::GMat in;
- auto out = cv::gapi::YUV2BGR(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(BayerGR2RGBPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB);
- cv::GMat in;
- auto out = cv::gapi::BayerGR2RGB(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(RGB2HSVPerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
- cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB);
- cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV);
- cv::GMat in;
- auto out = cv::gapi::RGB2HSV(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- SANITY_CHECK_NOTHING();
- }
- PERF_TEST_P_(RGB2YUV422PerfTest, TestPerformance)
- {
- compare_f cmpF = get<0>(GetParam());
- Size sz = get<1>(GetParam());
- cv::GCompileArgs compile_args = get<2>(GetParam());
- initMatrixRandN(CV_8UC3, sz, CV_8UC2, false);
- cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB);
- convertRGB2YUV422Ref(in_mat1, out_mat_ocv);
- cv::GMat in;
- auto out = cv::gapi::RGB2YUV422(in);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
- TEST_CYCLE()
- {
- c.apply(in_mat1, out_mat_gapi);
- }
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- EXPECT_EQ(out_mat_gapi.size(), sz);
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(ResizePerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = -1;
- int interp = 1;
- cv::Size sz;
- cv::Size sz_out;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, interp, sz, sz_out, compile_args) = GetParam();
- in_mat1 = cv::Mat(sz, type);
- cv::Scalar mean = cv::Scalar::all(127);
- cv::Scalar stddev = cv::Scalar::all(40.f);
- cv::randn(in_mat1, mean, stddev);
- out_mat_gapi = cv::Mat(sz_out, type);
- out_mat_ocv = cv::Mat(sz_out, type);
- // OpenCV code ///////////////////////////////////////////////////////////
- cv::resize(in_mat1, out_mat_ocv, sz_out, 0.0, 0.0, interp);
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::resize(in, sz_out, 0.0, 0.0, interp);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- auto cc = c.compile(descr_of(gin(in_mat1)),
- std::move(compile_args));
- cc(gin(in_mat1), gout(out_mat_gapi));
- TEST_CYCLE()
- {
- cc(gin(in_mat1), gout(out_mat_gapi));
- }
- // Comparison ////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(ResizeFxFyPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = -1;
- int interp = 1;
- cv::Size sz;
- double fx = 1.0;
- double fy = 1.0;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, interp, sz, fx, fy, compile_args) = GetParam();
- in_mat1 = cv::Mat(sz, type);
- cv::Scalar mean = cv::Scalar::all(127);
- cv::Scalar stddev = cv::Scalar::all(40.f);
- cv::randn(in_mat1, mean, stddev);
- cv::Size sz_out = cv:: Size(saturate_cast<int>(sz.width*fx), saturate_cast<int>(sz.height*fy));
- out_mat_gapi = cv::Mat(sz_out, type);
- out_mat_ocv = cv::Mat(sz_out, type);
- // OpenCV code ///////////////////////////////////////////////////////////
- cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
- // G-API code //////////////////////////////////////////////////////////////
- cv::GMat in;
- auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
- cv::GComputation c(in, out);
- // Warm-up graph engine:
- auto cc = c.compile(descr_of(gin(in_mat1)),
- std::move(compile_args));
- cc(gin(in_mat1), gout(out_mat_gapi));
- TEST_CYCLE()
- {
- cc(gin(in_mat1), gout(out_mat_gapi));
- }
- // Comparison ////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- PERF_TEST_P_(ResizeInSimpleGraphPerfTest, TestPerformance)
- {
- compare_f cmpF;
- MatType type = -1;
- cv::Size sz;
- double fx = 0.5;
- double fy = 0.5;
- cv::GCompileArgs compile_args;
- std::tie(cmpF, type, sz, fx, fy, compile_args) = GetParam();
- initMatsRandU(type, sz, type, false);
- cv::Mat add_res_ocv;
- cv::add(in_mat1, in_mat2, add_res_ocv);
- cv::resize(add_res_ocv, out_mat_ocv, cv::Size(), fx, fy);
- cv::GMat in1, in2;
- cv::GMat add_res_gapi = cv::gapi::add(in1, in2);
- cv::GMat out = cv::gapi::resize(add_res_gapi, cv::Size(), fx, fy, INTER_LINEAR);
- cv::GComputation ac(GIn(in1, in2), GOut(out));
- auto cc = ac.compile(descr_of(gin(in_mat1, in_mat2)),
- std::move(compile_args));
- cc(gin(in_mat1, in_mat2), gout(out_mat_gapi));
- TEST_CYCLE()
- {
- cc(gin(in_mat1, in_mat2), gout(out_mat_gapi));
- }
- // Comparison ////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- // This test cases were created to control performance result of test scenario mentioned here:
- // https://stackoverflow.com/questions/60629331/opencv-gapi-performance-not-good-as-expected
- PERF_TEST_P_(BottleneckKernelsConstInputPerfTest, TestPerformance)
- {
- compare_f cmpF;
- std::string fileName = "";
- cv::GCompileArgs compile_args;
- double fx = 0.5;
- double fy = 0.5;
- std::tie(cmpF, fileName, compile_args) = GetParam();
- in_mat1 = cv::imread(findDataFile(fileName));
- cv::Mat cvvga;
- cv::Mat cvgray;
- cv::Mat cvblurred;
- cv::resize(in_mat1, cvvga, cv::Size(), fx, fy);
- cv::cvtColor(cvvga, cvgray, cv::COLOR_BGR2GRAY);
- cv::blur(cvgray, cvblurred, cv::Size(3, 3));
- cv::Canny(cvblurred, out_mat_ocv, 32, 128, 3);
- cv::GMat in;
- cv::GMat vga = cv::gapi::resize(in, cv::Size(), fx, fy, INTER_LINEAR);
- cv::GMat gray = cv::gapi::BGR2Gray(vga);
- cv::GMat blurred = cv::gapi::blur(gray, cv::Size(3, 3));
- cv::GMat out = cv::gapi::Canny(blurred, 32, 128, 3);
- cv::GComputation ac(in, out);
- auto cc = ac.compile(descr_of(gin(in_mat1)),
- std::move(compile_args));
- cc(gin(in_mat1), gout(out_mat_gapi));
- TEST_CYCLE()
- {
- cc(gin(in_mat1), gout(out_mat_gapi));
- }
- // Comparison ////////////////////////////////////////////////////////////
- {
- EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
- }
- SANITY_CHECK_NOTHING();
- }
- //------------------------------------------------------------------------------
- }
- #endif //OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP
|