Merge pull request #13206 from elatkin:el/gapi_perf_rgb2lab

GAPI (fluid): RGB to Lab optimization (#13206)

* GAPI (fluid): BGR2LUV, RGB2Lab: performance test

* GAPI (fluid): BGR2LUV, RGB2Lab: using cv::hal::cvtBGRtoLab

* GAPI (fluid): BGR2LUV, RGB2Lab: hide reference code with #ifdef
This commit is contained in:
Evgeny Latkin 2018-11-19 18:52:48 +03:00 committed by Alexander Alekhin
parent 6757c2c5a6
commit 083332f85f
3 changed files with 55 additions and 17 deletions

View File

@ -754,7 +754,7 @@ PERF_TEST_P_(RGB2LabPerfTest, TestPerformance)
TEST_CYCLE()
{
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
c.apply(in_mat1, out_mat_gapi);
}
// Comparison //////////////////////////////////////////////////////////////
@ -792,7 +792,7 @@ PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance)
TEST_CYCLE()
{
c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
c.apply(in_mat1, out_mat_gapi);
}
// Comparison //////////////////////////////////////////////////////////////

View File

@ -63,4 +63,14 @@ namespace opencv_test
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),
Values(cv::compile_args(IMGPROC_FLUID))));
INSTANTIATE_TEST_CASE_P(RGB2LabPerfTestFluid, RGB2LabPerfTest,
Combine(Values(AbsSimilarPoints(1, 0.05).to_compare_f()),
Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_FLUID))));
}

View File

@ -27,7 +27,8 @@
#include "gfluidimgproc_func.hpp"
#include <opencv2/core/hal/intrin.hpp>
#include "opencv2/imgproc/hal/hal.hpp"
#include "opencv2/core/hal/intrin.hpp"
#include <cmath>
#include <cstdlib>
@ -173,6 +174,10 @@ GAPI_FLUID_KERNEL(GFluidYUV2RGB, cv::gapi::imgproc::GYUV2RGB, false)
enum LabLUV { LL_Lab, LL_LUV };
#define LabLuv_reference 0 // 1=use reference code of RGB/BGR to LUV/Lab, 0=don't
#if LabLuv_reference
// gamma-correction (inverse) for sRGB, 1/gamma=2.4 for inverse, like for Mac OS (?)
static inline float f_gamma(float x)
{
@ -230,22 +235,9 @@ static inline void f_xyz2luv(float X, float Y, float Z,
v = 13*L * (v1 - vn);
}
// compile-time parameters: output format (Lab/LUV),
// and position of blue channel in BGR/RGB (0 or 2)
template<LabLUV labluv, int blue=0>
static void run_rgb2labluv(Buffer &dst, const View &src)
static void run_rgb2labluv_reference(uchar out[], const uchar in[], int width)
{
GAPI_Assert(src.meta().depth == CV_8U);
GAPI_Assert(dst.meta().depth == CV_8U);
GAPI_Assert(src.meta().chan == 3);
GAPI_Assert(dst.meta().chan == 3);
GAPI_Assert(src.length() == dst.length());
const auto *in = src.InLine<uchar>(0);
auto *out = dst.OutLine<uchar>();
int width = dst.length();
for (int w=0; w < width; w++)
{
float R, G, B;
@ -284,6 +276,42 @@ static void run_rgb2labluv(Buffer &dst, const View &src)
}
}
#endif // LabLuv_reference
// compile-time parameters: output format (Lab/LUV),
// and position of blue channel in BGR/RGB (0 or 2)
template<LabLUV labluv, int blue=0>
static void run_rgb2labluv(Buffer &dst, const View &src)
{
GAPI_Assert(src.meta().depth == CV_8U);
GAPI_Assert(dst.meta().depth == CV_8U);
GAPI_Assert(src.meta().chan == 3);
GAPI_Assert(dst.meta().chan == 3);
GAPI_Assert(src.length() == dst.length());
const auto *in = src.InLine<uchar>(0);
auto *out = dst.OutLine<uchar>();
int width = dst.length();
#if LabLuv_reference
run_rgb2labluv_reference<labluv, blue>(out, in, width);
#else
uchar *dst_data = out;
const uchar *src_data = in;
size_t src_step = width;
size_t dst_step = width;
int height = 1;
int depth = CV_8U;
int scn = 3;
bool swapBlue = (blue == 2);
bool isLab = (LL_Lab == labluv);
bool srgb = true;
cv::hal::cvtBGRtoLab(src_data, src_step, dst_data, dst_step,
width, height, depth, scn, swapBlue, isLab, srgb);
#endif
}
GAPI_FLUID_KERNEL(GFluidRGB2Lab, cv::gapi::imgproc::GRGB2Lab, false)
{
static const int Window = 1;