mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 15:04:01 +08:00
added gpu::cvtColor for RGB <-> HSV and RGB <-> HLS
This commit is contained in:
parent
970dd7f593
commit
f4075e0168
File diff suppressed because it is too large
Load Diff
@ -105,21 +105,33 @@ namespace cv { namespace gpu
|
||||
void RGB2Gray_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int bidx, cudaStream_t stream);
|
||||
void RGB5x52Gray_gpu(const DevMem2D& src, int green_bits, const DevMem2D& dst, cudaStream_t stream);
|
||||
|
||||
void RGB2YCrCb_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const int* coeffs, cudaStream_t stream);
|
||||
void RGB2YCrCb_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const int* coeffs, cudaStream_t stream);
|
||||
void RGB2YCrCb_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const float* coeffs, cudaStream_t stream);
|
||||
void RGB2YCrCb_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const void* coeffs, cudaStream_t stream);
|
||||
void RGB2YCrCb_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const void* coeffs, cudaStream_t stream);
|
||||
void RGB2YCrCb_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const void* coeffs, cudaStream_t stream);
|
||||
|
||||
void YCrCb2RGB_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const int* coeffs, cudaStream_t stream);
|
||||
void YCrCb2RGB_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const int* coeffs, cudaStream_t stream);
|
||||
void YCrCb2RGB_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const float* coeffs, cudaStream_t stream);
|
||||
void YCrCb2RGB_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const void* coeffs, cudaStream_t stream);
|
||||
void YCrCb2RGB_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const void* coeffs, cudaStream_t stream);
|
||||
void YCrCb2RGB_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, const void* coeffs, cudaStream_t stream);
|
||||
|
||||
void RGB2XYZ_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const int* coeffs, cudaStream_t stream);
|
||||
void RGB2XYZ_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const int* coeffs, cudaStream_t stream);
|
||||
void RGB2XYZ_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const float* coeffs, cudaStream_t stream);
|
||||
void RGB2XYZ_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const void* coeffs, cudaStream_t stream);
|
||||
void RGB2XYZ_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const void* coeffs, cudaStream_t stream);
|
||||
void RGB2XYZ_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const void* coeffs, cudaStream_t stream);
|
||||
|
||||
void XYZ2RGB_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const int* coeffs, cudaStream_t stream);
|
||||
void XYZ2RGB_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const int* coeffs, cudaStream_t stream);
|
||||
void XYZ2RGB_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const float* coeffs, cudaStream_t stream);
|
||||
void XYZ2RGB_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const void* coeffs, cudaStream_t stream);
|
||||
void XYZ2RGB_gpu_16u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const void* coeffs, cudaStream_t stream);
|
||||
void XYZ2RGB_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, const void* coeffs, cudaStream_t stream);
|
||||
|
||||
void RGB2HSV_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
void RGB2HSV_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
|
||||
void HSV2RGB_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
void HSV2RGB_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
|
||||
void RGB2HLS_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
void RGB2HLS_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
|
||||
void HLS2RGB_gpu_8u(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
void HLS2RGB_gpu_32f(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, int hrange, cudaStream_t stream);
|
||||
}
|
||||
}}
|
||||
|
||||
@ -294,109 +306,122 @@ namespace
|
||||
|
||||
CV_Assert(depth == CV_8U || depth == CV_16U || depth == CV_32F);
|
||||
|
||||
GpuMat out;
|
||||
if (dst.data != src.data)
|
||||
out = dst;
|
||||
|
||||
NppiSize nppsz;
|
||||
nppsz.height = src.rows;
|
||||
nppsz.width = src.cols;
|
||||
|
||||
switch (code)
|
||||
{
|
||||
case CV_BGR2BGRA: case CV_RGB2BGRA: case CV_BGRA2BGR:
|
||||
case CV_RGBA2BGR: case CV_RGB2BGR: case CV_BGRA2RGBA:
|
||||
CV_Assert(scn == 3 || scn == 4);
|
||||
case CV_RGBA2BGR: case CV_RGB2BGR: case CV_BGRA2RGBA:
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::RGB2RGB_gpu_8u, 0, improc::RGB2RGB_gpu_16u, 0, 0, improc::RGB2RGB_gpu_32f};
|
||||
|
||||
dcn = code == CV_BGR2BGRA || code == CV_RGB2BGRA || code == CV_BGRA2RGBA ? 4 : 3;
|
||||
bidx = code == CV_BGR2BGRA || code == CV_BGRA2BGR ? 0 : 2;
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
if( depth == CV_8U )
|
||||
improc::RGB2RGB_gpu_8u(src, scn, out, dcn, bidx, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::RGB2RGB_gpu_16u(src, scn, out, dcn, bidx, stream);
|
||||
else
|
||||
improc::RGB2RGB_gpu_32f(src, scn, out, dcn, bidx, stream);
|
||||
break;
|
||||
CV_Assert(scn == 3 || scn == 4);
|
||||
|
||||
dcn = code == CV_BGR2BGRA || code == CV_RGB2BGRA || code == CV_BGRA2RGBA ? 4 : 3;
|
||||
bidx = code == CV_BGR2BGRA || code == CV_BGRA2BGR ? 0 : 2;
|
||||
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
funcs[depth](src, scn, dst, dcn, bidx, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_BGR2BGR565: case CV_BGR2BGR555: case CV_RGB2BGR565: case CV_RGB2BGR555:
|
||||
case CV_BGRA2BGR565: case CV_BGRA2BGR555: case CV_RGBA2BGR565: case CV_RGBA2BGR555:
|
||||
CV_Assert( (scn == 3 || scn == 4) && depth == CV_8U );
|
||||
out.create(sz, CV_8UC2);
|
||||
{
|
||||
CV_Assert((scn == 3 || scn == 4) && depth == CV_8U);
|
||||
|
||||
improc::RGB2RGB5x5_gpu(src, scn, out, code == CV_BGR2BGR565 || code == CV_RGB2BGR565 ||
|
||||
code == CV_BGRA2BGR565 || code == CV_RGBA2BGR565 ? 6 : 5,
|
||||
code == CV_BGR2BGR565 || code == CV_BGR2BGR555 ||
|
||||
code == CV_BGRA2BGR565 || code == CV_BGRA2BGR555 ? 0 : 2,
|
||||
stream);
|
||||
break;
|
||||
int green_bits = code == CV_BGR2BGR565 || code == CV_RGB2BGR565
|
||||
|| code == CV_BGRA2BGR565 || code == CV_RGBA2BGR565 ? 6 : 5;
|
||||
bidx = code == CV_BGR2BGR565 || code == CV_BGR2BGR555
|
||||
|| code == CV_BGRA2BGR565 || code == CV_BGRA2BGR555 ? 0 : 2;
|
||||
|
||||
dst.create(sz, CV_8UC2);
|
||||
|
||||
improc::RGB2RGB5x5_gpu(src, scn, dst, green_bits, bidx, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_BGR5652BGR: case CV_BGR5552BGR: case CV_BGR5652RGB: case CV_BGR5552RGB:
|
||||
case CV_BGR5652BGRA: case CV_BGR5552BGRA: case CV_BGR5652RGBA: case CV_BGR5552RGBA:
|
||||
if(dcn <= 0) dcn = 3;
|
||||
CV_Assert( (dcn == 3 || dcn == 4) && scn == 2 && depth == CV_8U );
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
{
|
||||
if (dcn <= 0) dcn = 3;
|
||||
|
||||
improc::RGB5x52RGB_gpu(src,
|
||||
code == CV_BGR5652BGR || code == CV_BGR5652RGB ||
|
||||
code == CV_BGR5652BGRA || code == CV_BGR5652RGBA ? 6 : 5,
|
||||
out, dcn,
|
||||
code == CV_BGR5652BGR || code == CV_BGR5552BGR ||
|
||||
code == CV_BGR5652BGRA || code == CV_BGR5552BGRA ? 0 : 2,
|
||||
stream);
|
||||
break;
|
||||
CV_Assert((dcn == 3 || dcn == 4) && scn == 2 && depth == CV_8U);
|
||||
|
||||
int green_bits = code == CV_BGR5652BGR || code == CV_BGR5652RGB
|
||||
|| code == CV_BGR5652BGRA || code == CV_BGR5652RGBA ? 6 : 5;
|
||||
bidx = code == CV_BGR5652BGR || code == CV_BGR5552BGR
|
||||
|| code == CV_BGR5652BGRA || code == CV_BGR5552BGRA ? 0 : 2;
|
||||
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
improc::RGB5x52RGB_gpu(src, green_bits, dst, dcn, bidx, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_BGR2GRAY: case CV_BGRA2GRAY: case CV_RGB2GRAY: case CV_RGBA2GRAY:
|
||||
CV_Assert(scn == 3 || scn == 4);
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int bidx, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::RGB2Gray_gpu_8u, 0, improc::RGB2Gray_gpu_16u, 0, 0, improc::RGB2Gray_gpu_32f};
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, 1));
|
||||
bidx = code == CV_BGR2GRAY || code == CV_BGRA2GRAY ? 0 : 2;
|
||||
|
||||
if( depth == CV_8U )
|
||||
improc::RGB2Gray_gpu_8u(src, scn, out, bidx, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::RGB2Gray_gpu_16u(src, scn, out, bidx, stream);
|
||||
else
|
||||
improc::RGB2Gray_gpu_32f(src, scn, out, bidx, stream);
|
||||
break;
|
||||
CV_Assert(scn == 3 || scn == 4);
|
||||
|
||||
bidx = code == CV_BGR2GRAY || code == CV_BGRA2GRAY ? 0 : 2;
|
||||
|
||||
dst.create(sz, CV_MAKETYPE(depth, 1));
|
||||
|
||||
funcs[depth](src, scn, dst, bidx, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_BGR5652GRAY: case CV_BGR5552GRAY:
|
||||
CV_Assert( scn == 2 && depth == CV_8U );
|
||||
{
|
||||
CV_Assert(scn == 2 && depth == CV_8U);
|
||||
|
||||
out.create(sz, CV_8UC1);
|
||||
int green_bits = code == CV_BGR5652GRAY ? 6 : 5;
|
||||
|
||||
improc::RGB5x52Gray_gpu(src, code == CV_BGR5652GRAY ? 6 : 5, out, stream);
|
||||
break;
|
||||
dst.create(sz, CV_8UC1);
|
||||
|
||||
improc::RGB5x52Gray_gpu(src, green_bits, dst, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_GRAY2BGR: case CV_GRAY2BGRA:
|
||||
if (dcn <= 0)
|
||||
dcn = 3;
|
||||
CV_Assert(scn == 1 && (dcn == 3 || dcn == 4));
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, const DevMem2D& dst, int dstcn, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::Gray2RGB_gpu_8u, 0, improc::Gray2RGB_gpu_16u, 0, 0, improc::Gray2RGB_gpu_32f};
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if( depth == CV_8U )
|
||||
improc::Gray2RGB_gpu_8u(src, out, dcn, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::Gray2RGB_gpu_16u(src, out, dcn, stream);
|
||||
else
|
||||
improc::Gray2RGB_gpu_32f(src, out, dcn, stream);
|
||||
break;
|
||||
if (dcn <= 0) dcn = 3;
|
||||
|
||||
CV_Assert(scn == 1 && (dcn == 3 || dcn == 4));
|
||||
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
funcs[depth](src, dst, dcn, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_GRAY2BGR565: case CV_GRAY2BGR555:
|
||||
CV_Assert( scn == 1 && depth == CV_8U );
|
||||
{
|
||||
CV_Assert(scn == 1 && depth == CV_8U);
|
||||
|
||||
out.create(sz, CV_8UC2);
|
||||
|
||||
improc::Gray2RGB5x5_gpu(src, out, code == CV_GRAY2BGR565 ? 6 : 5, stream);
|
||||
break;
|
||||
int green_bits = code == CV_GRAY2BGR565 ? 6 : 5;
|
||||
|
||||
dst.create(sz, CV_8UC2);
|
||||
|
||||
improc::Gray2RGB5x5_gpu(src, dst, green_bits, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_BGR2YCrCb: case CV_RGB2YCrCb:
|
||||
case CV_BGR2YUV: case CV_RGB2YUV:
|
||||
{
|
||||
if(dcn <= 0) dcn = 3;
|
||||
CV_Assert( (scn == 3 || scn == 4) && (dcn == 3 || dcn == 4) );
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx,
|
||||
const void* coeffs, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::RGB2YCrCb_gpu_8u, 0, improc::RGB2YCrCb_gpu_16u, 0, 0, improc::RGB2YCrCb_gpu_32f};
|
||||
|
||||
if (dcn <= 0) dcn = 3;
|
||||
CV_Assert((scn == 3 || scn == 4) && (dcn == 3 || dcn == 4));
|
||||
|
||||
bidx = code == CV_BGR2YCrCb || code == CV_RGB2YUV ? 0 : 2;
|
||||
|
||||
@ -408,32 +433,33 @@ namespace
|
||||
|
||||
float coeffs_f[5];
|
||||
int coeffs_i[5];
|
||||
::memcpy(coeffs_f, code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? YCrCb_f : yuv_f, 5 * sizeof(float));
|
||||
::memcpy(coeffs_i, code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? YCrCb_i : yuv_i, 5 * sizeof(int));
|
||||
::memcpy(coeffs_f, code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? YCrCb_f : yuv_f, sizeof(yuv_f));
|
||||
::memcpy(coeffs_i, code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? YCrCb_i : yuv_i, sizeof(yuv_i));
|
||||
|
||||
if (bidx==0)
|
||||
if (bidx == 0)
|
||||
{
|
||||
std::swap(coeffs_f[0], coeffs_f[2]);
|
||||
std::swap(coeffs_i[0], coeffs_i[2]);
|
||||
}
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if( depth == CV_8U )
|
||||
improc::RGB2YCrCb_gpu_8u(src, scn, out, dcn, bidx, coeffs_i, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::RGB2YCrCb_gpu_16u(src, scn, out, dcn, bidx, coeffs_i, stream);
|
||||
else
|
||||
improc::RGB2YCrCb_gpu_32f(src, scn, out, dcn, bidx, coeffs_f, stream);
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
const void* coeffs = depth == CV_32F ? (void*)coeffs_f : (void*)coeffs_i;
|
||||
|
||||
funcs[depth](src, scn, dst, dcn, bidx, coeffs, stream);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CV_YCrCb2BGR: case CV_YCrCb2RGB:
|
||||
case CV_YUV2BGR: case CV_YUV2RGB:
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx,
|
||||
const void* coeffs, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::YCrCb2RGB_gpu_8u, 0, improc::YCrCb2RGB_gpu_16u, 0, 0, improc::YCrCb2RGB_gpu_32f};
|
||||
|
||||
if (dcn <= 0) dcn = 3;
|
||||
|
||||
CV_Assert( (scn == 3 || scn == 4) && (dcn == 3 || dcn == 4) );
|
||||
CV_Assert((scn == 3 || scn == 4) && (dcn == 3 || dcn == 4));
|
||||
|
||||
bidx = code == CV_YCrCb2BGR || code == CV_YUV2RGB ? 0 : 2;
|
||||
|
||||
@ -446,21 +472,23 @@ namespace
|
||||
const float* coeffs_f = code == CV_YCrCb2BGR || code == CV_YCrCb2RGB ? YCrCb_f : yuv_f;
|
||||
const int* coeffs_i = code == CV_YCrCb2BGR || code == CV_YCrCb2RGB ? YCrCb_i : yuv_i;
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if( depth == CV_8U )
|
||||
improc::YCrCb2RGB_gpu_8u(src, scn, out, dcn, bidx, coeffs_i, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::YCrCb2RGB_gpu_16u(src, scn, out, dcn, bidx, coeffs_i, stream);
|
||||
else
|
||||
improc::YCrCb2RGB_gpu_32f(src, scn, out, dcn, bidx, coeffs_f, stream);
|
||||
const void* coeffs = depth == CV_32F ? (void*)coeffs_f : (void*)coeffs_i;
|
||||
|
||||
funcs[depth](src, scn, dst, dcn, bidx, coeffs, stream);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CV_BGR2XYZ: case CV_RGB2XYZ:
|
||||
{
|
||||
if(dcn <= 0) dcn = 3;
|
||||
CV_Assert( (scn == 3 || scn == 4) && (dcn == 3 || dcn == 4) );
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn,
|
||||
const void* coeffs, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::RGB2XYZ_gpu_8u, 0, improc::RGB2XYZ_gpu_16u, 0, 0, improc::RGB2XYZ_gpu_32f};
|
||||
|
||||
if (dcn <= 0) dcn = 3;
|
||||
|
||||
CV_Assert((scn == 3 || scn == 4) && (dcn == 3 || dcn == 4));
|
||||
|
||||
bidx = code == CV_BGR2XYZ ? 0 : 2;
|
||||
|
||||
@ -479,8 +507,8 @@ namespace
|
||||
|
||||
float coeffs_f[9];
|
||||
int coeffs_i[9];
|
||||
::memcpy(coeffs_f, RGB2XYZ_D65f, 9 * sizeof(float));
|
||||
::memcpy(coeffs_i, RGB2XYZ_D65i, 9 * sizeof(int));
|
||||
::memcpy(coeffs_f, RGB2XYZ_D65f, sizeof(RGB2XYZ_D65f));
|
||||
::memcpy(coeffs_i, RGB2XYZ_D65i, sizeof(RGB2XYZ_D65i));
|
||||
|
||||
if (bidx == 0)
|
||||
{
|
||||
@ -493,21 +521,24 @@ namespace
|
||||
std::swap(coeffs_i[6], coeffs_i[8]);
|
||||
}
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if( depth == CV_8U )
|
||||
improc::RGB2XYZ_gpu_8u(src, scn, out, dcn, coeffs_i, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::RGB2XYZ_gpu_16u(src, scn, out, dcn, coeffs_i, stream);
|
||||
else
|
||||
improc::RGB2XYZ_gpu_32f(src, scn, out, dcn, coeffs_f, stream);
|
||||
const void* coeffs = depth == CV_32F ? (void*)coeffs_f : (void*)coeffs_i;
|
||||
|
||||
funcs[depth](src, scn, dst, dcn, coeffs, stream);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CV_XYZ2BGR: case CV_XYZ2RGB:
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn,
|
||||
const void* coeffs, cudaStream_t stream);
|
||||
static const func_t funcs[] = {improc::XYZ2RGB_gpu_8u, 0, improc::XYZ2RGB_gpu_16u, 0, 0, improc::XYZ2RGB_gpu_32f};
|
||||
|
||||
if (dcn <= 0) dcn = 3;
|
||||
CV_Assert( (scn == 3 || scn == 4) && (dcn == 3 || dcn == 4) );
|
||||
|
||||
CV_Assert((scn == 3 || scn == 4) && (dcn == 3 || dcn == 4));
|
||||
|
||||
bidx = code == CV_XYZ2BGR ? 0 : 2;
|
||||
|
||||
static const float XYZ2sRGB_D65f[] =
|
||||
@ -525,8 +556,8 @@ namespace
|
||||
|
||||
float coeffs_f[9];
|
||||
int coeffs_i[9];
|
||||
::memcpy(coeffs_f, XYZ2sRGB_D65f, 9 * sizeof(float));
|
||||
::memcpy(coeffs_i, XYZ2sRGB_D65i, 9 * sizeof(int));
|
||||
::memcpy(coeffs_f, XYZ2sRGB_D65f, sizeof(XYZ2sRGB_D65f));
|
||||
::memcpy(coeffs_i, XYZ2sRGB_D65i, sizeof(XYZ2sRGB_D65i));
|
||||
|
||||
if (bidx == 0)
|
||||
{
|
||||
@ -539,153 +570,69 @@ namespace
|
||||
std::swap(coeffs_i[2], coeffs_i[8]);
|
||||
}
|
||||
|
||||
out.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if( depth == CV_8U )
|
||||
improc::XYZ2RGB_gpu_8u(src, scn, out, dcn, coeffs_i, stream);
|
||||
else if( depth == CV_16U )
|
||||
improc::XYZ2RGB_gpu_16u(src, scn, out, dcn, coeffs_i, stream);
|
||||
else
|
||||
improc::XYZ2RGB_gpu_32f(src, scn, out, dcn, coeffs_f, stream);
|
||||
const void* coeffs = depth == CV_32F ? (void*)coeffs_f : (void*)coeffs_i;
|
||||
|
||||
funcs[depth](src, scn, dst, dcn, coeffs_i, stream);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CV_BGR2HSV: case CV_RGB2HSV: case CV_BGR2HSV_FULL: case CV_RGB2HSV_FULL:
|
||||
case CV_BGR2HLS: case CV_RGB2HLS: case CV_BGR2HLS_FULL: case CV_RGB2HLS_FULL:
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx,
|
||||
int hrange, cudaStream_t stream);
|
||||
static const func_t funcs_hsv[] = {improc::RGB2HSV_gpu_8u, 0, 0, 0, 0, improc::RGB2HSV_gpu_32f};
|
||||
static const func_t funcs_hls[] = {improc::RGB2HLS_gpu_8u, 0, 0, 0, 0, improc::RGB2HLS_gpu_32f};
|
||||
|
||||
if (dcn <= 0) dcn = 3;
|
||||
|
||||
CV_Assert((scn == 3 || scn == 4) && (dcn == 3 || dcn == 4) && (depth == CV_8U || depth == CV_32F));
|
||||
|
||||
bidx = code == CV_BGR2HSV || code == CV_BGR2HLS ||
|
||||
code == CV_BGR2HSV_FULL || code == CV_BGR2HLS_FULL ? 0 : 2;
|
||||
int hrange = depth == CV_32F ? 360 : code == CV_BGR2HSV || code == CV_RGB2HSV ||
|
||||
code == CV_BGR2HLS || code == CV_RGB2HLS ? 180 : 255;
|
||||
|
||||
//case CV_BGR2HSV: case CV_RGB2HSV: case CV_BGR2HSV_FULL: case CV_RGB2HSV_FULL:
|
||||
//case CV_BGR2HLS: case CV_RGB2HLS: case CV_BGR2HLS_FULL: case CV_RGB2HLS_FULL:
|
||||
// {
|
||||
// CV_Assert( (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) );
|
||||
// bidx = code == CV_BGR2HSV || code == CV_BGR2HLS ||
|
||||
// code == CV_BGR2HSV_FULL || code == CV_BGR2HLS_FULL ? 0 : 2;
|
||||
// int hrange = depth == CV_32F ? 360 : code == CV_BGR2HSV || code == CV_RGB2HSV ||
|
||||
// code == CV_BGR2HLS || code == CV_RGB2HLS ? 180 : 255;
|
||||
//
|
||||
// dst.create(sz, CV_MAKETYPE(depth, 3));
|
||||
//
|
||||
// if( code == CV_BGR2HSV || code == CV_RGB2HSV ||
|
||||
// code == CV_BGR2HSV_FULL || code == CV_RGB2HSV_FULL )
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, RGB2HSV_b(scn, bidx, hrange));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, RGB2HSV_f(scn, bidx, (float)hrange));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, RGB2HLS_b(scn, bidx, hrange));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, RGB2HLS_f(scn, bidx, (float)hrange));
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
//case CV_HSV2BGR: case CV_HSV2RGB: case CV_HSV2BGR_FULL: case CV_HSV2RGB_FULL:
|
||||
//case CV_HLS2BGR: case CV_HLS2RGB: case CV_HLS2BGR_FULL: case CV_HLS2RGB_FULL:
|
||||
// {
|
||||
// if( dcn <= 0 ) dcn = 3;
|
||||
// CV_Assert( scn == 3 && (dcn == 3 || dcn == 4) && (depth == CV_8U || depth == CV_32F) );
|
||||
// bidx = code == CV_HSV2BGR || code == CV_HLS2BGR ||
|
||||
// code == CV_HSV2BGR_FULL || code == CV_HLS2BGR_FULL ? 0 : 2;
|
||||
// int hrange = depth == CV_32F ? 360 : code == CV_HSV2BGR || code == CV_HSV2RGB ||
|
||||
// code == CV_HLS2BGR || code == CV_HLS2RGB ? 180 : 255;
|
||||
//
|
||||
// dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
//
|
||||
// if( code == CV_HSV2BGR || code == CV_HSV2RGB ||
|
||||
// code == CV_HSV2BGR_FULL || code == CV_HSV2RGB_FULL )
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, HSV2RGB_b(dcn, bidx, hrange));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, HSV2RGB_f(dcn, bidx, (float)hrange));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, HLS2RGB_b(dcn, bidx, hrange));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, HLS2RGB_f(dcn, bidx, (float)hrange));
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
//case CV_BGR2Lab: case CV_RGB2Lab: case CV_LBGR2Lab: case CV_LRGB2Lab:
|
||||
//case CV_BGR2Luv: case CV_RGB2Luv: case CV_LBGR2Luv: case CV_LRGB2Luv:
|
||||
// {
|
||||
// CV_Assert( (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) );
|
||||
// bidx = code == CV_BGR2Lab || code == CV_BGR2Luv ||
|
||||
// code == CV_LBGR2Lab || code == CV_LBGR2Luv ? 0 : 2;
|
||||
// bool srgb = code == CV_BGR2Lab || code == CV_RGB2Lab ||
|
||||
// code == CV_BGR2Luv || code == CV_RGB2Luv;
|
||||
//
|
||||
// dst.create(sz, CV_MAKETYPE(depth, 3));
|
||||
//
|
||||
// if( code == CV_BGR2Lab || code == CV_RGB2Lab ||
|
||||
// code == CV_LBGR2Lab || code == CV_LRGB2Lab )
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, RGB2Lab_b(scn, bidx, 0, 0, srgb));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, RGB2Lab_f(scn, bidx, 0, 0, srgb));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, RGB2Luv_b(scn, bidx, 0, 0, srgb));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, RGB2Luv_f(scn, bidx, 0, 0, srgb));
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
//case CV_Lab2BGR: case CV_Lab2RGB: case CV_Lab2LBGR: case CV_Lab2LRGB:
|
||||
//case CV_Luv2BGR: case CV_Luv2RGB: case CV_Luv2LBGR: case CV_Luv2LRGB:
|
||||
// {
|
||||
// if( dcn <= 0 ) dcn = 3;
|
||||
// CV_Assert( scn == 3 && (dcn == 3 || dcn == 4) && (depth == CV_8U || depth == CV_32F) );
|
||||
// bidx = code == CV_Lab2BGR || code == CV_Luv2BGR ||
|
||||
// code == CV_Lab2LBGR || code == CV_Luv2LBGR ? 0 : 2;
|
||||
// bool srgb = code == CV_Lab2BGR || code == CV_Lab2RGB ||
|
||||
// code == CV_Luv2BGR || code == CV_Luv2RGB;
|
||||
//
|
||||
// dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
//
|
||||
// if( code == CV_Lab2BGR || code == CV_Lab2RGB ||
|
||||
// code == CV_Lab2LBGR || code == CV_Lab2LRGB )
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, Lab2RGB_b(dcn, bidx, 0, 0, srgb));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, Lab2RGB_f(dcn, bidx, 0, 0, srgb));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if( depth == CV_8U )
|
||||
// CvtColorLoop(src, dst, Luv2RGB_b(dcn, bidx, 0, 0, srgb));
|
||||
// else
|
||||
// CvtColorLoop(src, dst, Luv2RGB_f(dcn, bidx, 0, 0, srgb));
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
//case CV_BayerBG2BGR: case CV_BayerGB2BGR: case CV_BayerRG2BGR: case CV_BayerGR2BGR:
|
||||
//case CV_BayerBG2BGR_VNG: case CV_BayerGB2BGR_VNG: case CV_BayerRG2BGR_VNG: case CV_BayerGR2BGR_VNG:
|
||||
// if(dcn <= 0) dcn = 3;
|
||||
// CV_Assert( scn == 1 && dcn == 3 && depth == CV_8U );
|
||||
// dst.create(sz, CV_8UC3);
|
||||
//
|
||||
// if( code == CV_BayerBG2BGR || code == CV_BayerGB2BGR ||
|
||||
// code == CV_BayerRG2BGR || code == CV_BayerGR2BGR )
|
||||
// Bayer2RGB_8u(src, dst, code);
|
||||
// else
|
||||
// Bayer2RGB_VNG_8u(src, dst, code);
|
||||
// break;
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if (code == CV_BGR2HSV || code == CV_RGB2HSV || code == CV_BGR2HSV_FULL || code == CV_RGB2HSV_FULL)
|
||||
funcs_hsv[depth](src, scn, dst, dcn, bidx, hrange, stream);
|
||||
else
|
||||
funcs_hls[depth](src, scn, dst, dcn, bidx, hrange, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
case CV_HSV2BGR: case CV_HSV2RGB: case CV_HSV2BGR_FULL: case CV_HSV2RGB_FULL:
|
||||
case CV_HLS2BGR: case CV_HLS2RGB: case CV_HLS2BGR_FULL: case CV_HLS2RGB_FULL:
|
||||
{
|
||||
typedef void (*func_t)(const DevMem2D& src, int srccn, const DevMem2D& dst, int dstcn, int bidx,
|
||||
int hrange, cudaStream_t stream);
|
||||
static const func_t funcs_hsv[] = {improc::HSV2RGB_gpu_8u, 0, 0, 0, 0, improc::HSV2RGB_gpu_32f};
|
||||
static const func_t funcs_hls[] = {improc::HLS2RGB_gpu_8u, 0, 0, 0, 0, improc::HLS2RGB_gpu_32f};
|
||||
|
||||
if (dcn <= 0) dcn = 3;
|
||||
|
||||
CV_Assert((scn == 3 || scn == 4) && (dcn == 3 || dcn == 4) && (depth == CV_8U || depth == CV_32F));
|
||||
|
||||
bidx = code == CV_HSV2BGR || code == CV_HLS2BGR ||
|
||||
code == CV_HSV2BGR_FULL || code == CV_HLS2BGR_FULL ? 0 : 2;
|
||||
int hrange = depth == CV_32F ? 360 : code == CV_HSV2BGR || code == CV_HSV2RGB ||
|
||||
code == CV_HLS2BGR || code == CV_HLS2RGB ? 180 : 255;
|
||||
|
||||
dst.create(sz, CV_MAKETYPE(depth, dcn));
|
||||
|
||||
if (code == CV_HSV2BGR || code == CV_HSV2RGB || code == CV_HSV2BGR_FULL || code == CV_HSV2RGB_FULL)
|
||||
funcs_hsv[depth](src, scn, dst, dcn, bidx, hrange, stream);
|
||||
else
|
||||
funcs_hls[depth](src, scn, dst, dcn, bidx, hrange, stream);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" );
|
||||
}
|
||||
|
||||
dst = out;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,7 +459,7 @@ int CV_GpuCvtColorTest::CheckNorm(const Mat& m1, const Mat& m2)
|
||||
{
|
||||
double ret = norm(m1, m2, NORM_INF);
|
||||
|
||||
if (ret < std::numeric_limits<double>::epsilon())
|
||||
if (ret <= 2)
|
||||
{
|
||||
return CvTS::OK;
|
||||
}
|
||||
@ -472,7 +472,6 @@ int CV_GpuCvtColorTest::CheckNorm(const Mat& m1, const Mat& m2)
|
||||
|
||||
void CV_GpuCvtColorTest::run( int )
|
||||
{
|
||||
//load image
|
||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||
|
||||
if (img.empty())
|
||||
@ -486,17 +485,20 @@ void CV_GpuCvtColorTest::run( int )
|
||||
cv::gpu::GpuMat gpuImg(img), gpuRes;
|
||||
try
|
||||
{
|
||||
//run tests
|
||||
int codes[] = { CV_BGR2RGB, CV_RGB2BGRA, CV_BGRA2RGB,
|
||||
CV_RGB2BGR555, CV_BGR5552BGR, CV_BGR2BGR565, CV_BGR5652RGB,
|
||||
CV_RGB2YCrCb, CV_YCrCb2BGR, CV_BGR2YUV, CV_YUV2RGB,
|
||||
CV_RGB2XYZ, CV_XYZ2BGR, CV_BGR2XYZ, CV_XYZ2RGB,
|
||||
CV_RGB2HSV, CV_HSV2BGR, CV_BGR2HSV_FULL, CV_HSV2RGB_FULL,
|
||||
CV_RGB2HLS, CV_HLS2BGR, CV_BGR2HLS_FULL, CV_HLS2RGB_FULL,
|
||||
CV_RGB2GRAY, CV_GRAY2BGRA, CV_BGRA2GRAY,
|
||||
CV_GRAY2BGR555, CV_BGR5552GRAY, CV_GRAY2BGR565, CV_BGR5652GRAY};
|
||||
const char* codes_str[] = { "CV_BGR2RGB", "CV_RGB2BGRA", "CV_BGRA2RGB",
|
||||
"CV_RGB2BGR555", "CV_BGR5552BGR", "CV_BGR2BGR565", "CV_BGR5652RGB",
|
||||
"CV_RGB2YCrCb", "CV_YCrCb2BGR", "CV_BGR2YUV", "CV_YUV2RGB",
|
||||
"CV_RGB2XYZ", "CV_XYZ2BGR", "CV_BGR2XYZ", "CV_XYZ2RGB",
|
||||
"CV_RGB2HSV", "CV_HSV2RGB", "CV_BGR2HSV_FULL", "CV_HSV2RGB_FULL",
|
||||
"CV_RGB2HLS", "CV_HLS2RGB", "CV_BGR2HLS_FULL", "CV_HLS2RGB_FULL",
|
||||
"CV_RGB2GRAY", "CV_GRAY2BGRA", "CV_BGRA2GRAY",
|
||||
"CV_GRAY2BGR555", "CV_BGR5552GRAY", "CV_GRAY2BGR565", "CV_BGR5652GRAY"};
|
||||
int codes_num = sizeof(codes) / sizeof(int);
|
||||
|
Loading…
Reference in New Issue
Block a user