mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Add new render primitives
This commit is contained in:
@@ -10,14 +10,53 @@
|
||||
|
||||
#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 Points = std::vector<cv::Point>;
|
||||
using Rects = std::vector<cv::Rect>;
|
||||
using PairOfPoints = std::pair<cv::Point, cv::Point>;
|
||||
using VecOfPairOfPoints = std::vector<PairOfPoints>;
|
||||
using Prims = cv::gapi::wip::draw::Prims;
|
||||
using Prim = cv::gapi::wip::draw::Prim;
|
||||
|
||||
template<class T>
|
||||
class RenderWithParam : public TestWithParam<T>
|
||||
@@ -26,47 +65,50 @@ 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
cv::gapi::GKernelPackage pkg;
|
||||
|
||||
cv::Mat y_mat_ocv, uv_mat_ocv, y_mat_gapi, uv_mat_gapi, mat_ocv, 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>> {};
|
||||
using TestArgs = std::tuple<cv::Size,cv::gapi::wip::draw::Prims,cv::gapi::GKernelPackage>;
|
||||
|
||||
struct RenderNV12 : public RenderWithParam<TestArgs>
|
||||
{
|
||||
void ComputeRef()
|
||||
{
|
||||
cv::gapi::wip::draw::BGR2NV12(mat_ocv, y_mat_ocv, uv_mat_ocv);
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
|
||||
struct RenderBGR : public RenderWithParam<TestArgs>
|
||||
{
|
||||
void ComputeRef()
|
||||
{
|
||||
cv::gapi::wip::draw::drawPrimitivesOCVBGR(mat_ocv, prims);
|
||||
}
|
||||
};
|
||||
|
||||
} // opencv_test
|
||||
|
||||
|
||||
@@ -2,93 +2,41 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2019 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>
|
||||
#include "gapi_render_tests.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
TEST_P(RenderTextTest, AccuracyTest)
|
||||
TEST_P(RenderNV12, 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();
|
||||
std::tie(sz, prims, pkg) = 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});
|
||||
}
|
||||
cv::gapi::wip::draw::BGR2NV12(mat_gapi, y_mat_gapi, uv_mat_gapi);
|
||||
cv::gapi::wip::draw::render(y_mat_gapi, uv_mat_gapi, prims, pkg);
|
||||
|
||||
Run();
|
||||
ComputeRef();
|
||||
|
||||
EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
|
||||
EXPECT_EQ(0, cv::norm(y_mat_gapi, y_mat_ocv));
|
||||
EXPECT_EQ(0, cv::norm(uv_mat_gapi, uv_mat_ocv));
|
||||
}
|
||||
|
||||
TEST_P(RenderRectTest, AccuracyTest)
|
||||
TEST_P(RenderBGR, AccuracyTest)
|
||||
{
|
||||
std::vector<cv::Rect> rects;
|
||||
int shift;
|
||||
|
||||
std::tie(sz, rects, color, thick, lt, shift, isNV12Format) = GetParam();
|
||||
std::tie(sz, prims, pkg) = 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});
|
||||
}
|
||||
cv::gapi::wip::draw::render(mat_gapi, prims, pkg);
|
||||
ComputeRef();
|
||||
|
||||
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));
|
||||
EXPECT_EQ(0, cv::norm(mat_gapi, mat_ocv));
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
|
||||
Reference in New Issue
Block a user