Merge pull request #14892 from TolyaTalamanov:at/parameterized-render-tests
G-API: Parameterized render tests (#14892) * Init commit * Add mat size as test parameter * Add test for text render * Add test for rect render * Add tests for line and circle * Remove old render tests * Init output mats * Remove methods input arguments * Add comment about data loss in BGR2NV12 conversion * Add edge test cases * Replace default color for out mats black -> white
This commit is contained in:
committed by
Alexander Alekhin
parent
75c567b6ab
commit
8dd596b7ba
@@ -24,7 +24,7 @@ void cv::gapi::wip::draw::render(cv::Mat& bgr, const Prims& prims)
|
||||
{
|
||||
const auto& t_p = cv::util::get<Text>(p);
|
||||
cv::putText(bgr, t_p.text, t_p.org, t_p.ff, t_p.fs,
|
||||
t_p.color, t_p.thick, t_p.bottom_left_origin);
|
||||
t_p.color, t_p.thick, t_p.lt, t_p.bottom_left_origin);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// 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 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "gapi_render_tests_inl.hpp"
|
||||
@@ -0,0 +1,73 @@
|
||||
// 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 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_RENDER_TESTS_HPP
|
||||
#define OPENCV_GAPI_RENDER_TESTS_HPP
|
||||
|
||||
#include "gapi_tests_common.hpp"
|
||||
#include "api/render_priv.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
using Points = std::vector<cv::Point>;
|
||||
using Rects = std::vector<cv::Rect>;
|
||||
using PairOfPoints = std::pair<cv::Point, cv::Point>;
|
||||
using VecOfPairOfPoints = std::vector<PairOfPoints>;
|
||||
|
||||
template<class T>
|
||||
class RenderWithParam : public TestWithParam<T>
|
||||
{
|
||||
protected:
|
||||
void Init()
|
||||
{
|
||||
MatType type = CV_8UC3;
|
||||
out_mat_ocv = cv::Mat(sz, type, cv::Scalar(255));
|
||||
out_mat_gapi = cv::Mat(sz, type, cv::Scalar(255));
|
||||
|
||||
if (isNV12Format) {
|
||||
/* NB: When converting data from BGR to NV12, data loss occurs,
|
||||
* so the reference data is subjected to the same transformation
|
||||
* for correct comparison of the test results */
|
||||
cv::gapi::wip::draw::BGR2NV12(out_mat_ocv, y, uv);
|
||||
cv::cvtColorTwoPlane(y, uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
|
||||
}
|
||||
}
|
||||
|
||||
void Run()
|
||||
{
|
||||
if (isNV12Format) {
|
||||
cv::gapi::wip::draw::BGR2NV12(out_mat_gapi, y, uv);
|
||||
cv::gapi::wip::draw::render(y, uv, prims);
|
||||
cv::cvtColorTwoPlane(y, uv, out_mat_gapi, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
// NB: Also due to data loss
|
||||
cv::gapi::wip::draw::BGR2NV12(out_mat_ocv, y, uv);
|
||||
cv::cvtColorTwoPlane(y, uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
|
||||
} else {
|
||||
cv::gapi::wip::draw::render(out_mat_gapi, prims);
|
||||
}
|
||||
}
|
||||
|
||||
cv::Size sz;
|
||||
cv::Scalar color;
|
||||
int thick;
|
||||
int lt;
|
||||
bool isNV12Format;
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
cv::Mat y, uv;
|
||||
cv::Mat out_mat_ocv, out_mat_gapi;
|
||||
};
|
||||
|
||||
struct RenderTextTest : public RenderWithParam <std::tuple<cv::Size,std::string,Points,int,double,cv::Scalar,int,int,bool,bool>> {};
|
||||
struct RenderRectTest : public RenderWithParam <std::tuple<cv::Size,Rects,cv::Scalar,int,int,int,bool>> {};
|
||||
struct RenderCircleTest : public RenderWithParam <std::tuple<cv::Size,Points,int,cv::Scalar,int,int,int,bool>> {};
|
||||
struct RenderLineTest : public RenderWithParam <std::tuple<cv::Size,VecOfPairOfPoints,cv::Scalar,int,int,int,bool>> {};
|
||||
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_RENDER_TESTS_HPP
|
||||
@@ -0,0 +1,96 @@
|
||||
// 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 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_RENDER_TESTS_INL_HPP
|
||||
#define OPENCV_GAPI_RENDER_TESTS_INL_HPP
|
||||
|
||||
#include "gapi_render_tests.hpp"
|
||||
|
||||
#include <opencv2/gapi/render.hpp>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST_P(RenderTextTest, AccuracyTest)
|
||||
{
|
||||
std::vector<cv::Point> points;
|
||||
std::string text;
|
||||
int ff;
|
||||
double fs;
|
||||
bool blo;
|
||||
|
||||
std::tie(sz, text, points, ff, fs, color, thick, lt, blo, isNV12Format) = GetParam();
|
||||
Init();
|
||||
|
||||
for (const auto& p : points) {
|
||||
cv::putText(out_mat_ocv, text, p, ff, fs, color, thick, lt, blo);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Text{text, p, ff, fs, color, thick, lt, blo});
|
||||
}
|
||||
|
||||
Run();
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
TEST_P(RenderRectTest, AccuracyTest)
|
||||
{
|
||||
std::vector<cv::Rect> rects;
|
||||
int shift;
|
||||
|
||||
std::tie(sz, rects, color, thick, lt, shift, isNV12Format) = GetParam();
|
||||
Init();
|
||||
|
||||
for (const auto& r : rects) {
|
||||
cv::rectangle(out_mat_ocv, r, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Rect{r, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
Run();
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
TEST_P(RenderCircleTest, AccuracyTest)
|
||||
{
|
||||
std::vector<cv::Point> points;
|
||||
int radius;
|
||||
int shift;
|
||||
|
||||
std::tie(sz, points, radius, color, thick, lt, shift, isNV12Format) = GetParam();
|
||||
Init();
|
||||
|
||||
for (const auto& p : points) {
|
||||
cv::circle(out_mat_ocv, p, radius, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Circle{p, radius, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
Run();
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
TEST_P(RenderLineTest, AccuracyTest)
|
||||
{
|
||||
std::vector<std::pair<cv::Point, cv::Point>> points;
|
||||
int shift;
|
||||
|
||||
std::tie(sz, points, color, thick, lt, shift, isNV12Format) = GetParam();
|
||||
Init();
|
||||
|
||||
for (const auto& p : points) {
|
||||
cv::line(out_mat_ocv, p.first, p.second, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Line{p.first, p.second, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
Run();
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_RENDER_TESTS_INL_HPP
|
||||
@@ -0,0 +1,66 @@
|
||||
// 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 Intel Corporation
|
||||
|
||||
|
||||
#include "../test_precomp.hpp"
|
||||
#include "../common/gapi_render_tests.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RenderTextTestCPU, RenderTextTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values("text"),
|
||||
Values(Points{Point(5, 30), Point(40, 70), Point(-1, -1)}),
|
||||
/* Font face */ Values(FONT_HERSHEY_SIMPLEX),
|
||||
/* Font scale */ Values(2),
|
||||
/* Color */ Values(cv::Scalar(255, 0, 0)),
|
||||
/* Thickness */ Values(1),
|
||||
/* Line type */ Values(LINE_8),
|
||||
/* Bottom left origin */ testing::Bool(),
|
||||
/* NV12 format or not */ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RenderRectTestCPU, RenderRectTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(Rects{Rect(5, 30, 40, 50),
|
||||
Rect(40, 70, 40, 50),
|
||||
/* Edge case, rectangle will not be drawn */ Rect(75, 110, -40, 50),
|
||||
/* Edge case, rectangle will not be drawn */ Rect(70, 100, 0, 50)}),
|
||||
/* Color */ Values(cv::Scalar(255, 0, 0)),
|
||||
/* Thickness */ Values(1),
|
||||
/* Line type */ Values(LINE_8),
|
||||
/* Shift */ Values(0),
|
||||
/* NV12 format or not */ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RenderCircleTestCPU, RenderCircleTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(Points{Point(5, 30), Point(40, 70), Point(75, 110)}),
|
||||
/* Radius */ Values(5),
|
||||
/* Color */ Values(cv::Scalar(255, 0, 0)),
|
||||
/* Thickness */ Values(1),
|
||||
/* Line type */ Values(LINE_8),
|
||||
/* Shift */ Values(0),
|
||||
/* NV12 format or not */ testing::Bool()));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RenderLineTestCPU, RenderLineTest,
|
||||
Combine(Values(cv::Size(1280, 720),
|
||||
cv::Size(640, 480),
|
||||
cv::Size(128, 128)),
|
||||
Values(VecOfPairOfPoints{ {Point(5, 30) , Point(5, 40) },
|
||||
{Point(40, 70) , Point(50, 70) },
|
||||
{Point(75, 110), Point(100, 115)} }),
|
||||
/* Color */ Values(cv::Scalar(255, 0, 0)),
|
||||
/* Thickness */ Values(1),
|
||||
/* Line type */ Values(LINE_8),
|
||||
/* Shift */ Values(0),
|
||||
/* NV12 format or not */ testing::Bool()));
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
// 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 Intel Corporation
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#include "api/render_priv.hpp"
|
||||
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/gapi/render.hpp>
|
||||
#include <opencv2/gapi/own/scalar.hpp>
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
struct RenderTestFixture : public ::testing::Test
|
||||
{
|
||||
cv::Size size = {30, 40};
|
||||
int thick = 2;
|
||||
int ff = cv::FONT_HERSHEY_SIMPLEX;
|
||||
int lt = LINE_8;
|
||||
double fs = 1;
|
||||
int radius = 15;
|
||||
int shift = 0;
|
||||
|
||||
cv::Mat ref_mat {320, 480, CV_8UC3, cv::Scalar::all(255)};
|
||||
cv::Mat out_mat {320, 480, CV_8UC3, cv::Scalar::all(255)};
|
||||
cv::Scalar color {0, 255, 0};
|
||||
std::string text {"some text"};
|
||||
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST(BGR2NV12Test, CorrectConversion)
|
||||
{
|
||||
cv::Mat in_mat(320, 240, CV_8UC3);
|
||||
cv::Mat out_y, out_uv, ref_y, yuv;
|
||||
cv::randu(in_mat, cv::Scalar::all(0), cv::Scalar::all(255));
|
||||
|
||||
cv::cvtColor(in_mat, yuv, cv::COLOR_BGR2YUV);
|
||||
cv::Mat channels[3];
|
||||
cv::split(yuv, channels);
|
||||
|
||||
ref_y = channels[0];
|
||||
cv::Mat ref_uv(in_mat.size() / 2, CV_8UC2);
|
||||
cv::resize(channels[1], channels[1], channels[1].size() / 2, 0, 0, cv::INTER_NEAREST);
|
||||
cv::resize(channels[2], channels[2], channels[2].size() / 2, 0, 0, cv::INTER_NEAREST);
|
||||
cv::merge(channels + 1, 2, ref_uv);
|
||||
|
||||
cv::gapi::wip::draw::BGR2NV12(in_mat, out_y, out_uv);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_y != ref_y));
|
||||
EXPECT_EQ(0, cv::countNonZero(out_uv != ref_uv));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, PutText)
|
||||
{
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point point {30 + i * 60, 40 + i * 50};
|
||||
|
||||
cv::putText(ref_mat, text, point, ff, fs, color, thick);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Text{text, point, ff, fs, color, thick, lt, false});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(out_mat, prims);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, Rectangle)
|
||||
{
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Rect rect {30 + i * 60, 40 + i * 50, size.width, size.height};
|
||||
cv::rectangle(ref_mat, rect, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(out_mat, prims);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, Circle)
|
||||
{
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point center {30 + i * 60, 40 + i * 50};
|
||||
cv::circle(ref_mat, center, radius, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(out_mat, prims);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, Line)
|
||||
{
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point pt1{30 + i * 60 , 40 + i * 50};
|
||||
cv::Point pt2{30 + i * 60 + 40, 40 + i * 50};
|
||||
|
||||
cv::line(ref_mat, pt1, pt2, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(out_mat, prims);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, PutTextAndRectangle)
|
||||
{
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point point {30 + i * 60, 40 + i * 50};
|
||||
cv::Rect rect {point, size};
|
||||
|
||||
cv::rectangle(ref_mat, rect, color, thick);
|
||||
cv::putText(ref_mat, text, point, ff, fs, color, thick);
|
||||
|
||||
prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
|
||||
prims.emplace_back(cv::gapi::wip::draw::Text{text, point, ff, fs, color, thick, lt, false});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(out_mat, prims);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, PutTextAndRectangleNV12)
|
||||
{
|
||||
cv::Mat y;
|
||||
cv::Mat uv;
|
||||
cv::gapi::wip::draw::BGR2NV12(out_mat, y, uv);
|
||||
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point point {30 + i * 60, 40 + i * 50};
|
||||
cv::Rect rect {point, size};
|
||||
|
||||
cv::rectangle(ref_mat, rect, color, thick);
|
||||
cv::putText(ref_mat, text, point, ff, fs, color, thick);
|
||||
|
||||
prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
|
||||
prims.emplace_back(cv::gapi::wip::draw::Text{text, point, ff, fs, color, thick, lt, false});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(y, uv, prims);
|
||||
cv::cvtColorTwoPlane(y, uv, out_mat, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
cv::gapi::wip::draw::BGR2NV12(ref_mat, y, uv);
|
||||
cv::cvtColorTwoPlane(y, uv, ref_mat, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, CircleNV12)
|
||||
{
|
||||
cv::Mat y;
|
||||
cv::Mat uv;
|
||||
cv::gapi::wip::draw::BGR2NV12(out_mat, y, uv);
|
||||
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point center {30 + i * 60, 40 + i * 50};
|
||||
cv::circle(ref_mat, center, radius, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(y, uv, prims);
|
||||
cv::cvtColorTwoPlane(y, uv, out_mat, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
cv::gapi::wip::draw::BGR2NV12(ref_mat, y, uv);
|
||||
cv::cvtColorTwoPlane(y, uv, ref_mat, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
TEST_F(RenderTestFixture, LineNV12)
|
||||
{
|
||||
cv::Mat y;
|
||||
cv::Mat uv;
|
||||
cv::gapi::wip::draw::BGR2NV12(out_mat, y, uv);
|
||||
|
||||
std::vector<cv::gapi::wip::draw::Prim> prims;
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cv::Point pt1{30 + i * 60 , 40 + i * 50};
|
||||
cv::Point pt2{30 + i * 60 + 40, 40 + i * 50};
|
||||
|
||||
cv::line(ref_mat, pt1, pt2, color, thick, lt, shift);
|
||||
prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift});
|
||||
}
|
||||
|
||||
cv::gapi::wip::draw::render(y, uv, prims);
|
||||
cv::cvtColorTwoPlane(y, uv, out_mat, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
cv::gapi::wip::draw::BGR2NV12(ref_mat, y, uv);
|
||||
cv::cvtColorTwoPlane(y, uv, ref_mat, cv::COLOR_YUV2BGR_NV12);
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat != ref_mat));
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
Reference in New Issue
Block a user