Commit 083332f8 authored by Evgeny Latkin's avatar Evgeny Latkin Committed by Alexander Alekhin

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
parent 6757c2c5
...@@ -754,7 +754,7 @@ PERF_TEST_P_(RGB2LabPerfTest, TestPerformance) ...@@ -754,7 +754,7 @@ PERF_TEST_P_(RGB2LabPerfTest, TestPerformance)
TEST_CYCLE() TEST_CYCLE()
{ {
c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); c.apply(in_mat1, out_mat_gapi);
} }
// Comparison ////////////////////////////////////////////////////////////// // Comparison //////////////////////////////////////////////////////////////
...@@ -792,7 +792,7 @@ PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance) ...@@ -792,7 +792,7 @@ PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance)
TEST_CYCLE() TEST_CYCLE()
{ {
c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); c.apply(in_mat1, out_mat_gapi);
} }
// Comparison ////////////////////////////////////////////////////////////// // Comparison //////////////////////////////////////////////////////////////
......
...@@ -63,4 +63,14 @@ namespace opencv_test ...@@ -63,4 +63,14 @@ namespace opencv_test
Values(szVGA, sz720p, sz1080p), Values(szVGA, sz720p, sz1080p),
Values(cv::compile_args(IMGPROC_FLUID)))); 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))));
} }
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
#include "gfluidimgproc_func.hpp" #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 <cmath>
#include <cstdlib> #include <cstdlib>
...@@ -173,6 +174,10 @@ GAPI_FLUID_KERNEL(GFluidYUV2RGB, cv::gapi::imgproc::GYUV2RGB, false) ...@@ -173,6 +174,10 @@ GAPI_FLUID_KERNEL(GFluidYUV2RGB, cv::gapi::imgproc::GYUV2RGB, false)
enum LabLUV { LL_Lab, LL_LUV }; 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 (?) // gamma-correction (inverse) for sRGB, 1/gamma=2.4 for inverse, like for Mac OS (?)
static inline float f_gamma(float x) static inline float f_gamma(float x)
{ {
...@@ -230,22 +235,9 @@ static inline void f_xyz2luv(float X, float Y, float Z, ...@@ -230,22 +235,9 @@ static inline void f_xyz2luv(float X, float Y, float Z,
v = 13*L * (v1 - vn); 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> 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++) for (int w=0; w < width; w++)
{ {
float R, G, B; float R, G, B;
...@@ -284,6 +276,42 @@ static void run_rgb2labluv(Buffer &dst, const View &src) ...@@ -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) GAPI_FLUID_KERNEL(GFluidRGB2Lab, cv::gapi::imgproc::GRGB2Lab, false)
{ {
static const int Window = 1; static const int Window = 1;
......
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