mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 19:59:08 +08:00
Merge pull request #12279 from savuor:cvtcolor_bgr2gray_8u_15bits
* bgr2gray 8u fixed to be in conformance with IPP code * coefficients fixed so their sum is 32768 * java test for CascadeDetect fixed: equalizeHist added
This commit is contained in:
parent
43b64140ae
commit
da7e1cfb49
@ -22,11 +22,15 @@ const float R2YF = 0.299f;
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
gray_shift = 15,
|
||||||
yuv_shift = 14,
|
yuv_shift = 14,
|
||||||
xyz_shift = 12,
|
xyz_shift = 12,
|
||||||
R2Y = 4899, // == R2YF*16384
|
R2Y = 4899, // == R2YF*16384
|
||||||
G2Y = 9617, // == G2YF*16384
|
G2Y = 9617, // == G2YF*16384
|
||||||
B2Y = 1868, // == B2YF*16384
|
B2Y = 1868, // == B2YF*16384
|
||||||
|
RY15 = 9798, // == R2YF*32768 + 0.5
|
||||||
|
GY15 = 19235, // == G2YF*32768 + 0.5
|
||||||
|
BY15 = 3735, // == B2YF*32768 + 0.5
|
||||||
BLOCK_SIZE = 256
|
BLOCK_SIZE = 256
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -717,10 +717,10 @@ template<> struct RGB2Gray<uchar>
|
|||||||
|
|
||||||
RGB2Gray(int _srccn, int blueIdx, const int* coeffs) : srccn(_srccn)
|
RGB2Gray(int _srccn, int blueIdx, const int* coeffs) : srccn(_srccn)
|
||||||
{
|
{
|
||||||
const int coeffs0[] = { R2Y, G2Y, B2Y };
|
const int coeffs0[] = { RY15, GY15, BY15 };
|
||||||
if(!coeffs) coeffs = coeffs0;
|
if(!coeffs) coeffs = coeffs0;
|
||||||
|
|
||||||
int b = 0, g = 0, r = (1 << (yuv_shift-1));
|
int b = 0, g = 0, r = (1 << (gray_shift-1));
|
||||||
int db = coeffs[blueIdx^2], dg = coeffs[1], dr = coeffs[blueIdx];
|
int db = coeffs[blueIdx^2], dg = coeffs[1], dr = coeffs[blueIdx];
|
||||||
|
|
||||||
for( int i = 0; i < 256; i++, b += db, g += dg, r += dr )
|
for( int i = 0; i < 256; i++, b += db, g += dg, r += dr )
|
||||||
@ -735,7 +735,7 @@ template<> struct RGB2Gray<uchar>
|
|||||||
int scn = srccn;
|
int scn = srccn;
|
||||||
const int* _tab = tab;
|
const int* _tab = tab;
|
||||||
for(int i = 0; i < n; i++, src += scn)
|
for(int i = 0; i < n; i++, src += scn)
|
||||||
dst[i] = (uchar)((_tab[src[0]] + _tab[src[1]+256] + _tab[src[2]+512]) >> yuv_shift);
|
dst[i] = (uchar)((_tab[src[0]] + _tab[src[1]+256] + _tab[src[2]+512]) >> gray_shift);
|
||||||
}
|
}
|
||||||
int srccn;
|
int srccn;
|
||||||
int tab[256*3];
|
int tab[256*3];
|
||||||
|
@ -75,10 +75,14 @@
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
gray_shift = 15,
|
||||||
yuv_shift = 14,
|
yuv_shift = 14,
|
||||||
R2Y = 4899,
|
R2Y = 4899,
|
||||||
G2Y = 9617,
|
G2Y = 9617,
|
||||||
B2Y = 1868
|
B2Y = 1868,
|
||||||
|
RY15 = 9798, // == R2YF*32768 + 0.5
|
||||||
|
GY15 = 19235, // == G2YF*32768 + 0.5
|
||||||
|
BY15 = 3735 // == B2YF*32768 + 0.5
|
||||||
};
|
};
|
||||||
|
|
||||||
//constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601
|
//constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601
|
||||||
@ -129,6 +133,8 @@ __kernel void RGB2Gray(__global const uchar * srcptr, int src_step, int src_offs
|
|||||||
DATA_TYPE_3 src_pix = vload3(0, src);
|
DATA_TYPE_3 src_pix = vload3(0, src);
|
||||||
#ifdef DEPTH_5
|
#ifdef DEPTH_5
|
||||||
dst[0] = fma(src_pix.B_COMP, B2YF, fma(src_pix.G_COMP, G2YF, src_pix.R_COMP * R2YF));
|
dst[0] = fma(src_pix.B_COMP, B2YF, fma(src_pix.G_COMP, G2YF, src_pix.R_COMP * R2YF));
|
||||||
|
#elif defined(DEPTH_0)
|
||||||
|
dst[0] = (DATA_TYPE)CV_DESCALE(mad24(src_pix.B_COMP, BY15, mad24(src_pix.G_COMP, GY15, mul24(src_pix.R_COMP, RY15))), gray_shift);
|
||||||
#else
|
#else
|
||||||
dst[0] = (DATA_TYPE)CV_DESCALE(mad24(src_pix.B_COMP, B2Y, mad24(src_pix.G_COMP, G2Y, mul24(src_pix.R_COMP, R2Y))), yuv_shift);
|
dst[0] = (DATA_TYPE)CV_DESCALE(mad24(src_pix.B_COMP, B2Y, mad24(src_pix.G_COMP, G2Y, mul24(src_pix.R_COMP, R2Y))), yuv_shift);
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,9 +36,9 @@ public class CascadeClassifierTest extends OpenCVTestCase {
|
|||||||
|
|
||||||
Mat greyLena = new Mat();
|
Mat greyLena = new Mat();
|
||||||
Imgproc.cvtColor(rgbLena, greyLena, Imgproc.COLOR_RGB2GRAY);
|
Imgproc.cvtColor(rgbLena, greyLena, Imgproc.COLOR_RGB2GRAY);
|
||||||
|
Imgproc.equalizeHist(greyLena, greyLena);
|
||||||
|
|
||||||
// TODO: doesn't detect with 1.1 scale
|
cc.detectMultiScale(greyLena, faces, 1.1, 3, Objdetect.CASCADE_SCALE_IMAGE, new Size(30, 30), new Size());
|
||||||
cc.detectMultiScale(greyLena, faces, 1.09, 3, Objdetect.CASCADE_SCALE_IMAGE, new Size(30, 30), new Size());
|
|
||||||
assertEquals(1, faces.total());
|
assertEquals(1, faces.total());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user