mirror of
https://github.com/opencv/opencv.git
synced 2025-07-25 22:57:53 +08:00
Reworked HSV color conversion tables initialization for OpenCL branch.
This commit is contained in:
parent
c248d47110
commit
306204089f
@ -257,6 +257,34 @@ bool oclCvtColorBGR2HLS( InputArray _src, OutputArray _dst, int bidx, bool full
|
|||||||
return h.run();
|
return h.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static UMat init_sdiv_table()
|
||||||
|
{
|
||||||
|
std::vector<int> sdiv(256);
|
||||||
|
|
||||||
|
const int hsv_shift = 12;
|
||||||
|
const int v = 255 << hsv_shift;
|
||||||
|
|
||||||
|
sdiv[0] = 0;
|
||||||
|
for(int i = 1; i < 256; i++ )
|
||||||
|
sdiv[i] = saturate_cast<int>(v/(1.*i));
|
||||||
|
|
||||||
|
return UMat(sdiv, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static UMat init_hdiv_table(int hrange)
|
||||||
|
{
|
||||||
|
std::vector<int> hdiv(256);
|
||||||
|
|
||||||
|
const int hsv_shift = 12;
|
||||||
|
const int v = hrange << hsv_shift;
|
||||||
|
|
||||||
|
hdiv[0] = 0;
|
||||||
|
for (int i = 1; i < 256; i++ )
|
||||||
|
hdiv[i] = saturate_cast<int>(v/(6.*i));
|
||||||
|
|
||||||
|
return UMat(hdiv, true);
|
||||||
|
}
|
||||||
|
|
||||||
bool oclCvtColorBGR2HSV( InputArray _src, OutputArray _dst, int bidx, bool full )
|
bool oclCvtColorBGR2HSV( InputArray _src, OutputArray _dst, int bidx, bool full )
|
||||||
{
|
{
|
||||||
OclHelper< Set<3, 4>, Set<3>, Set<CV_8U, CV_32F> > h(_src, _dst, 3);
|
OclHelper< Set<3, 4>, Set<3>, Set<CV_8U, CV_32F> > h(_src, _dst, 3);
|
||||||
@ -274,41 +302,22 @@ bool oclCvtColorBGR2HSV( InputArray _src, OutputArray _dst, int bidx, bool full
|
|||||||
|
|
||||||
if(_src.depth() == CV_8U)
|
if(_src.depth() == CV_8U)
|
||||||
{
|
{
|
||||||
static UMat sdiv_data;
|
static UMat sdiv_data = init_sdiv_table();
|
||||||
static UMat hdiv_data180;
|
UMat hdiv_data;
|
||||||
static UMat hdiv_data256;
|
|
||||||
static int sdiv_table[256];
|
|
||||||
static int hdiv_table180[256];
|
|
||||||
static int hdiv_table256[256];
|
|
||||||
static volatile bool initialized180 = false, initialized256 = false;
|
|
||||||
volatile bool & initialized = hrange == 180 ? initialized180 : initialized256;
|
|
||||||
|
|
||||||
if (!initialized)
|
if (hrange == 180)
|
||||||
{
|
{
|
||||||
int * const hdiv_table = hrange == 180 ? hdiv_table180 : hdiv_table256, hsv_shift = 12;
|
static UMat hdiv_data180 = init_hdiv_table(180);
|
||||||
UMat & hdiv_data = hrange == 180 ? hdiv_data180 : hdiv_data256;
|
hdiv_data = hdiv_data180;
|
||||||
|
}
|
||||||
sdiv_table[0] = hdiv_table180[0] = hdiv_table256[0] = 0;
|
else
|
||||||
|
{
|
||||||
int v = 255 << hsv_shift;
|
static UMat hdiv_data256 = init_hdiv_table(256);
|
||||||
if (!initialized180 && !initialized256)
|
hdiv_data = hdiv_data256;
|
||||||
{
|
|
||||||
for(int i = 1; i < 256; i++ )
|
|
||||||
sdiv_table[i] = saturate_cast<int>(v/(1.*i));
|
|
||||||
Mat(1, 256, CV_32SC1, sdiv_table).copyTo(sdiv_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
v = hrange << hsv_shift;
|
|
||||||
for (int i = 1; i < 256; i++ )
|
|
||||||
hdiv_table[i] = saturate_cast<int>(v/(6.*i));
|
|
||||||
|
|
||||||
Mat(1, 256, CV_32SC1, hdiv_table).copyTo(hdiv_data);
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h.setArg(ocl::KernelArg::PtrReadOnly(sdiv_data));
|
h.setArg(ocl::KernelArg::PtrReadOnly(sdiv_data));
|
||||||
h.setArg(hrange == 256 ? ocl::KernelArg::PtrReadOnly(hdiv_data256) :
|
h.setArg(ocl::KernelArg::PtrReadOnly(hdiv_data));
|
||||||
ocl::KernelArg::PtrReadOnly(hdiv_data180));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.run();
|
return h.run();
|
||||||
|
Loading…
Reference in New Issue
Block a user