Commit 25c36fb0 authored by Namgoo Lee's avatar Namgoo Lee Committed by Vadim Pisarevsky

cv::cuda::cvtColor bug fix (#10640)

* cuda::cvtColor bug fix

Fixed bug in conversion formula between RGB space and LUV space.
Testing with opencv_test_cudaimgproc.exe, this commit reduces the number
of failed tests from 191 to 95. (96 more tests pass)

* Rename variables
parent 71ba54b2
...@@ -342,15 +342,15 @@ namespace color_cvt_detail ...@@ -342,15 +342,15 @@ namespace color_cvt_detail
const int delta = ColorChannel<T>::half() * (1 << yuv_shift); const int delta = ColorChannel<T>::half() * (1 << yuv_shift);
const int Y = CV_CUDEV_DESCALE(b * c_RGB2YUVCoeffs_i[2] + g * c_RGB2YUVCoeffs_i[1] + r * c_RGB2YUVCoeffs_i[0], yuv_shift); const int Y = CV_CUDEV_DESCALE(b * c_RGB2YUVCoeffs_i[0] + g * c_RGB2YUVCoeffs_i[1] + r * c_RGB2YUVCoeffs_i[2], yuv_shift);
const int Cr = CV_CUDEV_DESCALE((r - Y) * c_RGB2YUVCoeffs_i[3] + delta, yuv_shift); const int Cb = CV_CUDEV_DESCALE((b - Y) * c_RGB2YUVCoeffs_i[3] + delta, yuv_shift);
const int Cb = CV_CUDEV_DESCALE((b - Y) * c_RGB2YUVCoeffs_i[4] + delta, yuv_shift); const int Cr = CV_CUDEV_DESCALE((r - Y) * c_RGB2YUVCoeffs_i[4] + delta, yuv_shift);
typename MakeVec<T, dcn>::type dst; typename MakeVec<T, dcn>::type dst;
dst.x = saturate_cast<T>(Y); dst.x = saturate_cast<T>(Y);
dst.y = saturate_cast<T>(Cr); dst.y = saturate_cast<T>(Cb);
dst.z = saturate_cast<T>(Cb); dst.z = saturate_cast<T>(Cr);
return dst; return dst;
} }
...@@ -367,9 +367,9 @@ namespace color_cvt_detail ...@@ -367,9 +367,9 @@ namespace color_cvt_detail
typename MakeVec<float, dcn>::type dst; typename MakeVec<float, dcn>::type dst;
dst.x = b * c_RGB2YUVCoeffs_f[2] + g * c_RGB2YUVCoeffs_f[1] + r * c_RGB2YUVCoeffs_f[0]; dst.x = b * c_RGB2YUVCoeffs_f[0] + g * c_RGB2YUVCoeffs_f[1] + r * c_RGB2YUVCoeffs_f[2];
dst.y = (r - dst.x) * c_RGB2YUVCoeffs_f[3] + ColorChannel<float>::half(); dst.y = (b - dst.x) * c_RGB2YUVCoeffs_f[3] + ColorChannel<float>::half();
dst.z = (b - dst.x) * c_RGB2YUVCoeffs_f[4] + ColorChannel<float>::half(); dst.z = (r - dst.x) * c_RGB2YUVCoeffs_f[4] + ColorChannel<float>::half();
return dst; return dst;
} }
...@@ -385,9 +385,9 @@ namespace color_cvt_detail ...@@ -385,9 +385,9 @@ namespace color_cvt_detail
{ {
__device__ typename MakeVec<T, dcn>::type operator ()(const typename MakeVec<T, scn>::type& src) const __device__ typename MakeVec<T, dcn>::type operator ()(const typename MakeVec<T, scn>::type& src) const
{ {
const int b = src.x + CV_CUDEV_DESCALE((src.z - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[3], yuv_shift); const int r = src.x + CV_CUDEV_DESCALE((src.z - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[3], yuv_shift);
const int g = src.x + CV_CUDEV_DESCALE((src.z - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[2] + (src.y - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[1], yuv_shift); const int g = src.x + CV_CUDEV_DESCALE((src.z - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[2] + (src.y - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[1], yuv_shift);
const int r = src.x + CV_CUDEV_DESCALE((src.y - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[0], yuv_shift); const int b = src.x + CV_CUDEV_DESCALE((src.y - ColorChannel<T>::half()) * c_YUV2RGBCoeffs_i[0], yuv_shift);
typename MakeVec<T, dcn>::type dst; typename MakeVec<T, dcn>::type dst;
...@@ -405,9 +405,9 @@ namespace color_cvt_detail ...@@ -405,9 +405,9 @@ namespace color_cvt_detail
{ {
__device__ typename MakeVec<float, dcn>::type operator ()(const typename MakeVec<float, scn>::type& src) const __device__ typename MakeVec<float, dcn>::type operator ()(const typename MakeVec<float, scn>::type& src) const
{ {
const float b = src.x + (src.z - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[3]; const float r = src.x + (src.z - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[3];
const float g = src.x + (src.z - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[2] + (src.y - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[1]; const float g = src.x + (src.z - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[2] + (src.y - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[1];
const float r = src.x + (src.y - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[0]; const float b = src.x + (src.y - ColorChannel<float>::half()) * c_YUV2RGBCoeffs_f[0];
typename MakeVec<float, dcn>::type dst; typename MakeVec<float, dcn>::type dst;
......
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