1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #15751 from TolyaTalamanov:at/refactor-render-tests

* Refactor render tests

* Fix comment to review

* Move ocv render tests stuff to specific file

* Add OCV prefix for render tests

* Fix comments to review
This commit is contained in:
atalaman
2019-10-30 13:33:39 +03:00
committed by Alexander Alekhin
parent ea5499fa51
commit ea64bb58a5
12 changed files with 688 additions and 273 deletions
+102 -80
View File
@@ -9,107 +9,129 @@
#define OPENCV_GAPI_RENDER_TESTS_HPP
#include "gapi_tests_common.hpp"
#include "api/render_priv.hpp"
#include "api/render_ocv.hpp"
#define rect1 Prim{cv::gapi::wip::draw::Rect{cv::Rect{101, 101, 199, 199}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define rect2 Prim{cv::gapi::wip::draw::Rect{cv::Rect{100, 100, 199, 199}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define rect3 Prim{cv::gapi::wip::draw::Rect{cv::Rect{0 , 0 , 199, 199}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define rect4 Prim{cv::gapi::wip::draw::Rect{cv::Rect{100, 100, 0, 199 }, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define rect5 Prim{cv::gapi::wip::draw::Rect{cv::Rect{0 , -1 , 199, 199}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define rect6 Prim{cv::gapi::wip::draw::Rect{cv::Rect{100, 100, 199, 199}, cv::Scalar{153, 172, 58}, 10, LINE_8, 0}}
#define rect7 Prim{cv::gapi::wip::draw::Rect{cv::Rect{100, 100, 200, 200}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define box1 Prim{cv::gapi::wip::draw::Rect{cv::Rect{101, 101, 200, 200}, cv::Scalar{153, 172, 58}, -1, LINE_8, 0}}
#define box2 Prim{cv::gapi::wip::draw::Rect{cv::Rect{100, 100, 199, 199}, cv::Scalar{153, 172, 58}, -1, LINE_8, 0}}
#define rects Prims{rect1, rect2, rect3, rect4, rect5, rect6, rect7, box1, box2}
#define circle1 Prim{cv::gapi::wip::draw::Circle{cv::Point{200, 200}, 100, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define circle2 Prim{cv::gapi::wip::draw::Circle{cv::Point{10, 30} , 2 , cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define circle3 Prim{cv::gapi::wip::draw::Circle{cv::Point{75, 100} , 50 , cv::Scalar{153, 172, 58}, 5, LINE_8, 0}}
#define circles Prims{circle1, circle2, circle3}
#define line1 Prim{cv::gapi::wip::draw::Line{cv::Point{50, 50}, cv::Point{250, 200}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define line2 Prim{cv::gapi::wip::draw::Line{cv::Point{51, 51}, cv::Point{51, 100}, cv::Scalar{153, 172, 58}, 1, LINE_8, 0}}
#define lines Prims{line1, line2}
#define mosaic1 Prim{cv::gapi::wip::draw::Mosaic{cv::Rect{100, 100, 200, 200}, 5, 0}}
#define mosaics Prims{mosaic1}
#define image1 Prim{cv::gapi::wip::draw::Image{cv::Point(100, 100), cv::Mat(cv::Size(200, 200), CV_8UC3, cv::Scalar::all(255)),\
cv::Mat(cv::Size(200, 200), CV_32FC1, cv::Scalar::all(1))}}
#define image2 Prim{cv::gapi::wip::draw::Image{cv::Point(100, 100), cv::Mat(cv::Size(200, 200), CV_8UC3, cv::Scalar::all(255)),\
cv::Mat(cv::Size(200, 200), CV_32FC1, cv::Scalar::all(0.5))}}
#define image3 Prim{cv::gapi::wip::draw::Image{cv::Point(100, 100), cv::Mat(cv::Size(200, 200), CV_8UC3, cv::Scalar::all(255)),\
cv::Mat(cv::Size(200, 200), CV_32FC1, cv::Scalar::all(0.0))}}
#define images Prims{image1, image2, image3}
#define polygon1 Prim{cv::gapi::wip::draw::Poly{ {cv::Point{100, 100}, cv::Point{50, 200}, cv::Point{200, 30}, cv::Point{150, 50} }, cv::Scalar{153, 172, 58}, 1, LINE_8, 0} }
#define polygons Prims{polygon1}
#define text1 Prim{cv::gapi::wip::draw::Text{"TheBrownFoxJump", cv::Point{100, 100}, FONT_HERSHEY_SIMPLEX, 2, cv::Scalar{102, 178, 240}, 1, LINE_8, false} }
#define texts Prims{text1}
namespace opencv_test
{
using Prims = cv::gapi::wip::draw::Prims;
using Prim = cv::gapi::wip::draw::Prim;
template<typename ...SpecificParams>
struct RenderParams : public Params<SpecificParams...>
{
using common_params_t = std::tuple<cv::Size>;
using specific_params_t = std::tuple<SpecificParams...>;
using params_t = std::tuple<cv::Size, SpecificParams...>;
template<class T>
class RenderWithParam : public TestWithParam<T>
static constexpr const size_t common_params_size = std::tuple_size<common_params_t>::value;
static constexpr const size_t specific_params_size = std::tuple_size<specific_params_t>::value;
template<size_t I>
static const typename std::tuple_element<I, common_params_t>::type&
getCommon(const params_t& t)
{
static_assert(I < common_params_size, "Index out of range");
return std::get<I>(t);
}
template<size_t I>
static const typename std::tuple_element<I, specific_params_t>::type&
getSpecific(const params_t& t)
{
static_assert(specific_params_size > 0,
"Impossible to call this function: no specific parameters specified");
static_assert(I < specific_params_size, "Index out of range");
return std::get<common_params_size + I>(t);
}
};
template<typename ...SpecificParams>
struct RenderTestBase : public TestWithParam<typename RenderParams<SpecificParams...>::params_t>
{
using AllParams = RenderParams<SpecificParams...>;
// Get common (pre-defined) parameter value by index
template<size_t I>
inline auto getCommonParam() const
-> decltype(AllParams::template getCommon<I>(this->GetParam()))
{
return AllParams::template getCommon<I>(this->GetParam());
}
// Get specific (user-defined) parameter value by index
template<size_t I>
inline auto getSpecificParam() const
-> decltype(AllParams::template getSpecific<I>(this->GetParam()))
{
return AllParams::template getSpecific<I>(this->GetParam());
}
cv::Size sz_ = getCommonParam<0>();
};
template <typename ...Args>
class RenderBGRTestBase : public RenderTestBase<Args...>
{
protected:
void Init()
void Init(const cv::Size& sz)
{
MatType type = CV_8UC3;
mat_ocv.create(sz, type);
mat_gapi.create(sz, type);
cv::randu(mat_ocv, cv::Scalar::all(0), cv::Scalar::all(255));
mat_ocv.copyTo(mat_gapi);
ref_mat.create(sz, type);
gapi_mat.create(sz, type);
cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
ref_mat.copyTo(gapi_mat);
}
cv::Size sz;
std::vector<cv::gapi::wip::draw::Prim> prims;
cv::gapi::GKernelPackage pkg;
cv::Mat y_mat_ocv, uv_mat_ocv, y_mat_gapi, uv_mat_gapi, mat_ocv, mat_gapi;
cv::Mat gapi_mat, ref_mat;
};
using TestArgs = std::tuple<cv::Size,cv::gapi::wip::draw::Prims>;
struct RenderNV12 : public RenderWithParam<TestArgs>
template <typename ...Args>
class RenderNV12TestBase : public RenderTestBase<Args...>
{
void ComputeRef()
protected:
void Init(const cv::Size& sz)
{
cv::gapi::wip::draw::BGR2NV12(mat_ocv, y_mat_ocv, uv_mat_ocv);
auto create_rand_mats = [](const cv::Size& size, MatType type, cv::Mat& ref_mat, cv::Mat& gapi_mat) {
ref_mat.create(size, type);
cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
ref_mat.copyTo(gapi_mat);
};
// NV12 -> YUV
cv::Mat upsample_uv, yuv;
cv::resize(uv_mat_ocv, upsample_uv, uv_mat_ocv.size() * 2, cv::INTER_LINEAR);
cv::merge(std::vector<cv::Mat>{y_mat_ocv, upsample_uv}, yuv);
cv::gapi::wip::draw::drawPrimitivesOCVYUV(yuv, prims);
// YUV -> NV12
std::vector<cv::Mat> chs(3);
cv::split(yuv, chs);
cv::merge(std::vector<cv::Mat>{chs[1], chs[2]}, uv_mat_ocv);
y_mat_ocv = chs[0];
cv::resize(uv_mat_ocv, uv_mat_ocv, uv_mat_ocv.size() / 2, cv::INTER_LINEAR);
create_rand_mats(sz, CV_8UC1, y_ref_mat , y_gapi_mat);
create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat , uv_gapi_mat);
}
cv::Mat y_ref_mat, uv_ref_mat, y_gapi_mat, uv_gapi_mat;
};
struct RenderBGR : public RenderWithParam<TestArgs>
{
void ComputeRef()
{
cv::gapi::wip::draw::drawPrimitivesOCVBGR(mat_ocv, prims);
}
cv::Scalar cvtBGRToYUVC(const cv::Scalar& bgr);
void drawMosaicRef(const cv::Mat& mat, const cv::Rect &rect, int cellSz);
void blendImageRef(cv::Mat& mat,
const cv::Point& org,
const cv::Mat& img,
const cv::Mat& alpha);
#define GAPI_RENDER_TEST_FIXTURE_NV12(Fixture, API, Number, ...) \
struct Fixture : public RenderNV12TestBase API { \
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
Fixture() { \
Init(sz_); \
}; \
};
#define GAPI_RENDER_TEST_FIXTURE_BGR(Fixture, API, Number, ...) \
struct Fixture : public RenderBGRTestBase API { \
__WRAP_VAARGS(DEFINE_SPECIFIC_PARAMS_##Number(__VA_ARGS__)) \
Fixture() { \
Init(sz_); \
}; \
};
#define GET_VA_ARGS(...) __VA_ARGS__
#define GAPI_RENDER_TEST_FIXTURES(Fixture, API, Number, ...) \
GAPI_RENDER_TEST_FIXTURE_BGR(RenderBGR##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
GAPI_RENDER_TEST_FIXTURE_NV12(RenderNV12##Fixture, GET_VA_ARGS(API), Number, __VA_ARGS__) \
using Points = std::vector<cv::Point>;
} // opencv_test
#endif //OPENCV_GAPI_RENDER_TESTS_HPP