1
/* See LICENSE file in the root OpenCV directory */
4
#error "TILE SIZE should be 32"
8
__kernel void moments(__global const uchar* src, int src_step, int src_offset,
9
int src_rows, int src_cols, __global int* mom0, int xtiles)
11
int x0 = get_global_id(0);
12
int y0 = get_group_id(1);
13
int x, y = get_local_id(1);
14
int x_min = x0*TILE_SIZE;
15
int ypix = y0*TILE_SIZE + y;
16
__local int mom[TILE_SIZE][10];
18
if (x_min < src_cols && y0*TILE_SIZE < src_rows)
22
int x_max = min(src_cols - x_min, TILE_SIZE);
23
__global const uchar* ptr = src + src_offset + ypix*src_step + x_min;
24
int4 S = (int4)(0, 0, 0, 0), p;
26
#define SUM_ELEM(elem, ofs) \
27
(int4)(1, (ofs), (ofs)*(ofs), (ofs)*(ofs)*(ofs))*elem
32
p = convert_int4(vload4(0, ptr));
33
#ifdef OP_MOMENTS_BINARY
36
S += (int4)(p.s0, 0, 0, 0) + (int4)(p.s1, p.s1, p.s1, p.s1) +
37
(int4)(p.s2, p.s2 * 2, p.s2 * 4, p.s2 * 8) + (int4)(p.s3, p.s3 * 3, p.s3 * 9, p.s3 * 27);
38
//SUM_ELEM(p.s0, 0) + SUM_ELEM(p.s1, 1) + SUM_ELEM(p.s2, 2) + SUM_ELEM(p.s3, 3);
42
p = convert_int4(vload4(0, ptr + 4));
43
#ifdef OP_MOMENTS_BINARY
46
S += (int4)(p.s0, p.s0 * 4, p.s0 * 16, p.s0 * 64) + (int4)(p.s1, p.s1 * 5, p.s1 * 25, p.s1 * 125) +
47
(int4)(p.s2, p.s2 * 6, p.s2 * 36, p.s2 * 216) + (int4)(p.s3, p.s3 * 7, p.s3 * 49, p.s3 * 343);
48
//SUM_ELEM(p.s0, 4) + SUM_ELEM(p.s1, 5) + SUM_ELEM(p.s2, 6) + SUM_ELEM(p.s3, 7);
52
p = convert_int4(vload4(0, ptr + 8));
53
#ifdef OP_MOMENTS_BINARY
56
S += (int4)(p.s0, p.s0 * 8, p.s0 * 64, p.s0 * 512) + (int4)(p.s1, p.s1 * 9, p.s1 * 81, p.s1 * 729) +
57
(int4)(p.s2, p.s2 * 10, p.s2 * 100, p.s2 * 1000) + (int4)(p.s3, p.s3 * 11, p.s3 * 121, p.s3 * 1331);
58
//SUM_ELEM(p.s0, 8) + SUM_ELEM(p.s1, 9) + SUM_ELEM(p.s2, 10) + SUM_ELEM(p.s3, 11);
62
p = convert_int4(vload4(0, ptr + 12));
63
#ifdef OP_MOMENTS_BINARY
66
S += (int4)(p.s0, p.s0 * 12, p.s0 * 144, p.s0 * 1728) + (int4)(p.s1, p.s1 * 13, p.s1 * 169, p.s1 * 2197) +
67
(int4)(p.s2, p.s2 * 14, p.s2 * 196, p.s2 * 2744) + (int4)(p.s3, p.s3 * 15, p.s3 * 225, p.s3 * 3375);
68
//SUM_ELEM(p.s0, 12) + SUM_ELEM(p.s1, 13) + SUM_ELEM(p.s2, 14) + SUM_ELEM(p.s3, 15);
76
p = convert_int4(vload4(0, ptr + 16));
77
#ifdef OP_MOMENTS_BINARY
80
S += (int4)(p.s0, p.s0 * 16, p.s0 * 256, p.s0 * 4096) + (int4)(p.s1, p.s1 * 17, p.s1 * 289, p.s1 * 4913) +
81
(int4)(p.s2, p.s2 * 18, p.s2 * 324, p.s2 * 5832) + (int4)(p.s3, p.s3 * 19, p.s3 * 361, p.s3 * 6859);
82
//SUM_ELEM(p.s0, 16) + SUM_ELEM(p.s1, 17) + SUM_ELEM(p.s2, 18) + SUM_ELEM(p.s3, 19);
86
p = convert_int4(vload4(0, ptr + 20));
87
#ifdef OP_MOMENTS_BINARY
90
S += (int4)(p.s0, p.s0 * 20, p.s0 * 400, p.s0 * 8000) + (int4)(p.s1, p.s1 * 21, p.s1 * 441, p.s1 * 9261) +
91
(int4)(p.s2, p.s2 * 22, p.s2 * 484, p.s2 * 10648) + (int4)(p.s3, p.s3 * 23, p.s3 * 529, p.s3 * 12167);
92
//SUM_ELEM(p.s0, 20) + SUM_ELEM(p.s1, 21) + SUM_ELEM(p.s2, 22) + SUM_ELEM(p.s3, 23);
96
p = convert_int4(vload4(0, ptr + 24));
97
#ifdef OP_MOMENTS_BINARY
100
S += (int4)(p.s0, p.s0 * 24, p.s0 * 576, p.s0 * 13824) + (int4)(p.s1, p.s1 * 25, p.s1 * 625, p.s1 * 15625) +
101
(int4)(p.s2, p.s2 * 26, p.s2 * 676, p.s2 * 17576) + (int4)(p.s3, p.s3 * 27, p.s3 * 729, p.s3 * 19683);
102
//SUM_ELEM(p.s0, 24) + SUM_ELEM(p.s1, 25) + SUM_ELEM(p.s2, 26) + SUM_ELEM(p.s3, 27);
106
p = convert_int4(vload4(0, ptr + 28));
107
#ifdef OP_MOMENTS_BINARY
110
S += (int4)(p.s0, p.s0 * 28, p.s0 * 784, p.s0 * 21952) + (int4)(p.s1, p.s1 * 29, p.s1 * 841, p.s1 * 24389) +
111
(int4)(p.s2, p.s2 * 30, p.s2 * 900, p.s2 * 27000) + (int4)(p.s3, p.s3 * 31, p.s3 * 961, p.s3 * 29791);
112
//SUM_ELEM(p.s0, 28) + SUM_ELEM(p.s1, 29) + SUM_ELEM(p.s2, 30) + SUM_ELEM(p.s3, 31);
121
#ifdef OP_MOMENTS_BINARY
124
S += SUM_ELEM(ps, x);
128
#ifdef OP_MOMENTS_BINARY
131
S += SUM_ELEM(ps, x + 1);
135
#ifdef OP_MOMENTS_BINARY
138
S += SUM_ELEM(ps, x + 2);
154
mom[y][9] = y*sy*S.s0;
157
mom[y][0] = mom[y][1] = mom[y][2] = mom[y][3] = mom[y][4] =
158
mom[y][5] = mom[y][6] = mom[y][7] = mom[y][8] = mom[y][9] = 0;
159
barrier(CLK_LOCAL_MEM_FENCE);
164
mom[y][0] += mom[y + d][0]; \
165
mom[y][1] += mom[y + d][1]; \
166
mom[y][2] += mom[y + d][2]; \
167
mom[y][3] += mom[y + d][3]; \
168
mom[y][4] += mom[y + d][4]; \
169
mom[y][5] += mom[y + d][5]; \
170
mom[y][6] += mom[y + d][6]; \
171
mom[y][7] += mom[y + d][7]; \
172
mom[y][8] += mom[y + d][8]; \
173
mom[y][9] += mom[y + d][9]; \
175
barrier(CLK_LOCAL_MEM_FENCE)
184
__global int* momout = mom0 + (y0*xtiles + x0) * 10;
185
momout[y] = mom[0][y] + mom[1][y];