Commit 1aefa677 authored by atalaman's avatar atalaman Committed by Alexander Alekhin

Merge pull request #14513 from TolyaTalamanov:at/color-convert-kernels

G-API: Implement color-convert kernels (#14513)

* Implement color-convert kernels

* Fix rgb2yuv422 reference version

* Fix comments to review

* Restore NV12toBGR in imgproc.hpp

* Add accuracy tests

* Fix doxygen

* Fix ref version yuv422

* Fix warnings

* Fix typos

* Fix simd version yuv422

* Fix warnings

* Fix compile error

* Fix warning

* Remove comment
parent ddcf3882
......@@ -187,6 +187,26 @@ namespace imgproc {
return in.withType(CV_8U, 1);
}
};
G_TYPED_KERNEL(GBayerGR2RGB, <cv::GMat(cv::GMat)>, "org.opencv.imgproc.colorconvert.bayergr2rgb") {
static cv::GMatDesc outMeta(cv::GMatDesc in) {
return in.withType(CV_8U, 3);
}
};
G_TYPED_KERNEL(GRGB2HSV, <cv::GMat(cv::GMat)>, "org.opencv.imgproc.colorconvert.rgb2hsv") {
static cv::GMatDesc outMeta(cv::GMatDesc in) {
return in;
}
};
G_TYPED_KERNEL(GRGB2YUV422, <cv::GMat(cv::GMat)>, "org.opencv.imgproc.colorconvert.rgb2yuv422") {
static cv::GMatDesc outMeta(cv::GMatDesc in) {
GAPI_Assert(in.depth == CV_8U);
GAPI_Assert(in.chan == 3);
return in.withType(in.depth, 2);
}
};
}
......@@ -784,6 +804,49 @@ Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
@sa YUV2BGR, NV12toRGB
*/
GAPI_EXPORTS GMat NV12toBGR(const GMat& src_y, const GMat& src_uv);
/** @brief Converts an image from BayerGR color space to RGB.
The function converts an input image from BayerGR color space to RGB.
The conventional ranges for G, R, and B channel values are 0 to 255.
Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
@note Function textual ID is "org.opencv.imgproc.colorconvert.bayergr2rgb"
@param src_gr input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
@sa YUV2BGR, NV12toRGB
*/
GAPI_EXPORTS GMat BayerGR2RGB(const GMat& src_gr);
/** @brief Converts an image from RGB color space to HSV.
The function converts an input image from RGB color space to HSV.
The conventional ranges for R, G, and B channel values are 0 to 255.
Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2hsv"
@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
@sa YUV2BGR, NV12toRGB
*/
GAPI_EXPORTS GMat RGB2HSV(const GMat& src);
/** @brief Converts an image from RGB color space to YUV422.
The function converts an input image from RGB color space to YUV422.
The conventional ranges for R, G, and B channel values are 0 to 255.
Output image must be 8-bit unsigned 2-channel image @ref CV_8UC2.
@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv422"
@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
@sa YUV2BGR, NV12toRGB
*/
GAPI_EXPORTS GMat RGB2YUV422(const GMat& src);
//! @} gapi_colorconvert
} //namespace gapi
} //namespace cv
......
......@@ -43,5 +43,8 @@ class BGR2LUVPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCo
class LUV2BGRPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
class BGR2YUVPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
class YUV2BGRPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
class RGB2HSVPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
class BayerGR2RGBPerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
class RGB2YUV422PerfTest : public TestPerfParams<tuple<compare_f, cv::Size, cv::GCompileArgs>> {};
}
#endif //OPENCV_GAPI_IMGPROC_PERF_TESTS_HPP
......@@ -18,6 +18,41 @@ 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)
......@@ -949,6 +984,92 @@ PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance)
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());
initMatsRandN(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());
initMatsRandN(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());
initMatsRandN(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();
}
//------------------------------------------------------------------------------
}
......
......@@ -185,4 +185,18 @@ INSTANTIATE_TEST_CASE_P(YUV2BGRPerfTestCPU, YUV2BGRPerfTest,
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(RGB2HSVPerfTestCPU, RGB2HSVPerfTest,
Combine(Values(AbsExact().to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(BayerGR2RGBPerfTestCPU, BayerGR2RGBPerfTest,
Combine(Values(AbsExact().to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(RGB2YUV422PerfTestCPU, RGB2YUV422PerfTest,
Combine(Values(ToleranceColor(1e-3).to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_CPU))));
}
......@@ -173,6 +173,21 @@ INSTANTIATE_TEST_CASE_P(YUV2BGRPerfTestFluid, YUV2BGRPerfTest,
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(BayerGR2RGBPerfTestFluid, BayerGR2RGBPerfTest,
Combine(Values(ToleranceColor(1e-3).to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(RGB2YUV422PerfTestFluid, RGB2YUV422PerfTest,
Combine(Values(ToleranceColor(1e-3).to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(RGB2HSVPerfTestFluid, RGB2HSVPerfTest,
Combine(Values(ToleranceColor(1e-3).to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(BGR2LUVPerfTestFluid, BGR2LUVPerfTest,
Combine(Values(AbsSimilarPoints(1, 0.05).to_compare_f()),
Values(szVGA, sz720p, sz1080p),
......
......@@ -157,5 +157,17 @@ GMat RGB2Lab(const GMat& src)
return imgproc::GRGB2Lab::on(src);
}
GMat BayerGR2RGB(const GMat& src_gr) {
return imgproc::GBayerGR2RGB::on(src_gr);
}
GMat RGB2HSV(const GMat& src) {
return imgproc::GRGB2HSV::on(src);
}
GMat RGB2YUV422(const GMat& src) {
return imgproc::GRGB2YUV422::on(src);
}
} //namespace gapi
} //namespace cv
......@@ -11,6 +11,8 @@
#include "opencv2/gapi/cpu/imgproc.hpp"
#include "opencv2/gapi/cpu/gcpukernel.hpp"
#include "backends/fluid/gfluidimgproc_func.hpp"
namespace {
cv::Mat add_border(const cv::Mat& in, const int ksize, const int borderType, const cv::Scalar& bordVal){
if( borderType == cv::BORDER_CONSTANT )
......@@ -276,6 +278,37 @@ GAPI_OCV_KERNEL(GCPURGB2GrayCustom, cv::gapi::imgproc::GRGB2GrayCustom)
}
};
GAPI_OCV_KERNEL(GCPUBayerGR2RGB, cv::gapi::imgproc::GBayerGR2RGB)
{
static void run(const cv::Mat& in, cv::Mat &out)
{
cv::cvtColor(in, out, cv::COLOR_BayerGR2RGB);
}
};
GAPI_OCV_KERNEL(GCPURGB2HSV, cv::gapi::imgproc::GRGB2HSV)
{
static void run(const cv::Mat& in, cv::Mat &out)
{
cv::cvtColor(in, out, cv::COLOR_RGB2HSV);
}
};
GAPI_OCV_KERNEL(GCPURGB2YUV422, cv::gapi::imgproc::GRGB2YUV422)
{
static void run(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);
cv::gapi::fluid::run_rgb2yuv422_impl(out_line_p, in_line_p, in.cols);
}
}
};
cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
{
static auto pkg = cv::gapi::kernels
......@@ -303,6 +336,9 @@ cv::gapi::GKernelPackage cv::gapi::imgproc::cpu::kernels()
, GCPUBGR2Gray
, GCPURGB2Gray
, GCPURGB2GrayCustom
, GCPUBayerGR2RGB
, GCPURGB2HSV
, GCPURGB2YUV422
>();
return pkg;
}
......@@ -1683,6 +1683,121 @@ GAPI_FLUID_KERNEL(GFluidMedianBlur, cv::gapi::imgproc::GMedianBlur, false)
}
};
GAPI_FLUID_KERNEL(GFluidRGB2YUV422, cv::gapi::imgproc::GRGB2YUV422, false)
{
static const int Window = 1;
static const auto Kind = cv::GFluidKernel::Kind::Filter;
static void run(const cv::gapi::fluid::View& in,
cv::gapi::fluid::Buffer& out)
{
const auto *src = in.InLine<uchar>(0);
auto *dst = out.OutLine<uchar>();
run_rgb2yuv422_impl(dst, src, in.length());
}
};
GAPI_FLUID_KERNEL(GFluidRGB2HSV, cv::gapi::imgproc::GRGB2HSV, true)
{
static const int Window = 1;
static const auto Kind = cv::GFluidKernel::Kind::Filter;
static void run(const cv::gapi::fluid::View& in,
cv::gapi::fluid::Buffer& out,
cv::gapi::fluid::Buffer& scratch)
{
const auto *src = in.InLine<uchar>(0);
auto *dst = out.OutLine<uchar>();
auto* sdiv_table = scratch.OutLine<int>(0);
auto* hdiv_table = sdiv_table + 256;
run_rgb2hsv_impl(dst, src, sdiv_table, hdiv_table, in.length());
}
static void initScratch(const cv::GMatDesc& /* in */,
cv::gapi::fluid::Buffer& scratch)
{
const int hsv_shift = 12;
cv::GMatDesc desc;
desc.chan = 1;
desc.depth = CV_32S;
desc.size = cv::gapi::own::Size(512, 1);
cv::gapi::fluid::Buffer buffer(desc);
scratch = std::move(buffer);
auto* sdiv_table = scratch.OutLine<int>(0);
auto* hdiv_table = sdiv_table + 256;
sdiv_table[0] = hdiv_table[0] = 0;
for(int i = 1; i < 256; i++ )
{
sdiv_table[i] = cv::saturate_cast<int>((255 << hsv_shift)/(1.*i));
hdiv_table[i] = cv::saturate_cast<int>((180 << hsv_shift)/(6.*i));
}
}
static void resetScratch(cv::gapi::fluid::Buffer& /* scratch */)
{
}
};
GAPI_FLUID_KERNEL(GFluidBayerGR2RGB, cv::gapi::imgproc::GBayerGR2RGB, false)
{
static const int Window = 3;
static const int LPI = 2;
static void run(const cv::gapi::fluid::View& in,
cv::gapi::fluid::Buffer& out)
{
const int height = in.meta().size.height;
const int border_size = 1;
const int width = in.length();
constexpr int num_lines = LPI + 2 * border_size;
const uchar* src[num_lines];
uchar* dst[LPI];
for (int i = 0; i < LPI; ++i)
{
dst[i] = out.OutLine<uchar>(i);
}
for (int i = 0; i < num_lines; ++i)
{
src[i] = in.InLine<uchar>(i - 1);
}
if (in.y() == -1)
{
run_bayergr2rgb_bg_impl(dst[1], src + border_size, width);
std::memcpy(dst[0], dst[1], width * 3);
}
else if (in.y() == height - LPI - 2 * border_size + 1)
{
run_bayergr2rgb_gr_impl(dst[0], src, width);
std::memcpy(dst[1], dst[0], width * 3);
}
else
{
run_bayergr2rgb_gr_impl(dst[0], src, width);
run_bayergr2rgb_bg_impl(dst[1], src + border_size, width);
}
}
static cv::gapi::fluid::Border getBorder(const cv::GMatDesc&)
{
int borderType = cv::BORDER_CONSTANT;
auto borderValue = cv::Scalar();
return { borderType, borderValue };
}
};
} // namespace fliud
} // namespace gapi
} // namespace cv
......@@ -1709,6 +1824,9 @@ cv::gapi::GKernelPackage cv::gapi::imgproc::fluid::kernels()
, GFluidGaussBlur
, GFluidSobel
, GFluidSobelXY
, GFluidRGB2YUV422
, GFluidRGB2HSV
, GFluidBayerGR2RGB
#if 0
, GFluidCanny -- not fluid (?)
, GFluidEqualizeHist -- not fluid
......
......@@ -43,7 +43,35 @@ void run_rgb2gray_impl(uchar out[], const uchar in[], int width,
//--------------------------------------
//
// Fluid kernels: RGB-to-YUV, YUV-to-RGB
// Fluid kernels: RGB-to-HSV
//
//--------------------------------------
void run_rgb2hsv_impl(uchar out[], const uchar in[], const int sdiv_table[],
const int hdiv_table[], int width)
{
CV_CPU_DISPATCH(run_rgb2hsv_impl, (out, in, sdiv_table, hdiv_table, width), CV_CPU_DISPATCH_MODES_ALL);
}
//--------------------------------------
//
// Fluid kernels: RGB-to-BayerGR
//
//--------------------------------------
void run_bayergr2rgb_bg_impl(uchar out[], const uchar **in, int width)
{
CV_CPU_DISPATCH(run_bayergr2rgb_bg_impl, (out, in, width), CV_CPU_DISPATCH_MODES_ALL);
}
void run_bayergr2rgb_gr_impl(uchar out[], const uchar **in, int width)
{
CV_CPU_DISPATCH(run_bayergr2rgb_gr_impl, (out, in, width), CV_CPU_DISPATCH_MODES_ALL);
}
//--------------------------------------
//
// Fluid kernels: RGB-to-YUV, RGB-to-YUV422, YUV-to-RGB
//
//--------------------------------------
......@@ -57,6 +85,11 @@ void run_yuv2rgb_impl(uchar out[], const uchar in[], int width, const float coef
CV_CPU_DISPATCH(run_yuv2rgb_impl, (out, in, width, coef), CV_CPU_DISPATCH_MODES_ALL);
}
void run_rgb2yuv422_impl(uchar out[], const uchar in[], int width)
{
CV_CPU_DISPATCH(run_rgb2yuv422_impl, (out, in, width), CV_CPU_DISPATCH_MODES_ALL);
}
//-------------------------
//
// Fluid kernels: sepFilter
......
......@@ -25,7 +25,26 @@ void run_rgb2gray_impl(uchar out[], const uchar in[], int width,
//--------------------------------------
//
// Fluid kernels: RGB-to-YUV, YUV-to-RGB
// Fluid kernels: RGB-to-HSV
//
//--------------------------------------
void run_rgb2hsv_impl(uchar out[], const uchar in[], const int sdiv_table[],
const int hdiv_table[], int width);
//--------------------------------------
//
// Fluid kernels: RGB-to-BayerGR
//
//--------------------------------------
void run_bayergr2rgb_bg_impl(uchar out[], const uchar **in, int width);
void run_bayergr2rgb_gr_impl(uchar out[], const uchar **in, int width);
//--------------------------------------
//
// Fluid kernels: RGB-to-YUV,RGB-to-YUV422, YUV-to-RGB
//
//--------------------------------------
......@@ -33,6 +52,8 @@ void run_rgb2yuv_impl(uchar out[], const uchar in[], int width, const float coef
void run_yuv2rgb_impl(uchar out[], const uchar in[], int width, const float coef[4]);
void run_rgb2yuv422_impl(uchar out[], const uchar in[], int width);
//-------------------------
//
// Fluid kernels: sepFilter
......
......@@ -40,6 +40,9 @@ struct BGR2LUVTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GC
struct LUV2BGRTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct BGR2YUVTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct YUV2BGRTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct RGB2HSVTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct BayerGR2RGBTest : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
struct RGB2YUV422Test : public TestParams<std::tuple<compare_f,cv::Size,bool,cv::GCompileArgs>> {};
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_HPP
......@@ -13,6 +13,45 @@
namespace opencv_test
{
// FIXME avoid this code duplicate in perf tests
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);
}
}
}
TEST_P(Filter2DTest, AccuracyTest)
{
compare_f cmpF;
......@@ -730,6 +769,78 @@ TEST_P(YUV2BGRTest, AccuracyTest)
}
}
TEST_P(RGB2HSVTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::RGB2HSV(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
}
}
TEST_P(BayerGR2RGBTest, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC1, std::get<1>(param), CV_8UC3, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::BayerGR2RGB(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
}
}
TEST_P(RGB2YUV422Test, AccuracyTest)
{
auto param = GetParam();
auto compile_args = std::get<3>(param);
compare_f cmpF = std::get<0>(param);
initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC2, std::get<2>(param));
// G-API code //////////////////////////////////////////////////////////////
cv::GMat in;
auto out = cv::gapi::RGB2YUV422(in);
cv::GComputation c(in, out);
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
// OpenCV code /////////////////////////////////////////////////////////////
{
convertRGB2YUV422Ref(in_mat1, out_mat_ocv);
}
// Comparison //////////////////////////////////////////////////////////////
{
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
}
}
} // opencv_test
#endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
......@@ -271,4 +271,24 @@ INSTANTIATE_TEST_CASE_P(YUV2BGRTestCPU, YUV2BGRTest,
/*init output matrices or not*/ testing::Bool(),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(RGB2HSVTestCPU, RGB2HSVTest,
Combine(Values(AbsExact().to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
/*init output matrices or not*/ testing::Bool(),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(BayerGR2RGBTestCPU, BayerGR2RGBTest,
Combine(Values(AbsExact().to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
/*init output matrices or not*/ testing::Bool(),
Values(cv::compile_args(IMGPROC_CPU))));
INSTANTIATE_TEST_CASE_P(RGB2YUV422TestCPU, RGB2YUV422Test,
Combine(Values(AbsTolerance(1).to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
/*init output matrices or not*/ testing::Bool(),
Values(cv::compile_args(IMGPROC_CPU))));
} // opencv_test
......@@ -56,6 +56,27 @@ INSTANTIATE_TEST_CASE_P(BGR2LUVTestFluid, BGR2LUVTest,
Values(true, false),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(RGB2HSVTestFluid, RGB2HSVTest,
Combine(Values(ToleranceColor(1e-3).to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
Values(true, false),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(BayerGR2RGBTestFluid, BayerGR2RGBTest,
Combine(Values(ToleranceColor(1e-3).to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
Values(true, false),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(RGB2YUV422TestFluid, RGB2YUV422Test,
Combine(Values(AbsTolerance(1).to_compare_f()),
Values(cv::Size(1280, 720),
cv::Size(640, 480)),
Values(true, false),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(blurTestFluid, BlurTest,
Combine(Values(ToleranceFilter(1e-4f, 0.01).to_compare_f()),
Values(CV_8UC1, CV_16UC1, CV_16SC1),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment