Skip to content

Commit 5a4184b

Browse files
committed
2-nd level of parallelization + detector remake
1. Added 2-nd level of parallelization of NN on OpenCL 2. Restructured detector - now all filters work independently: Variance Filter->Ensemble->NN, through "buffers"
1 parent 38d5db7 commit 5a4184b

File tree

5 files changed

+397
-58
lines changed

5 files changed

+397
-58
lines changed

modules/tracking/samples/tld_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
using namespace std;
4949
using namespace cv;
5050

51-
#define NUM_TEST_FRAMES 500
52-
#define TEST_VIDEO_INDEX 1 //TLD Dataset Video Index from 1-10
51+
#define NUM_TEST_FRAMES 100
52+
#define TEST_VIDEO_INDEX 7 //TLD Dataset Video Index from 1-10
5353
//#define RECORD_VIDEO_FLG
5454

5555
static Mat image;

modules/tracking/src/opencl/tldDetector.cl

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ __kernel void NCC(__global const uchar *patch,
3131
int s1 = 0, s2 = 0, n1 = 0, n2 = 0, prod = 0;
3232
float sq1 = 0, sq2 = 0, ares = 0;
3333
int N = 225;
34-
//NCC with positive patch
34+
//NCC with positive sample
3535
if (posFlg && id < posNum)
3636
{
3737
for (int i = 0; i < N; i++)
3838
{
39-
4039
s1 += positiveSamples[id * N + i];
4140
s2 += patch[i];
4241
n1 += positiveSamples[id * N + i] * positiveSamples[id * N + i];
@@ -46,10 +45,10 @@ __kernel void NCC(__global const uchar *patch,
4645
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
4746
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
4847
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
49-
ncc[id] = ares;
48+
ncc[id] = ares;
5049
}
5150

52-
//NCC with negative patch
51+
//NCC with negative sample
5352
if (!posFlg && id < negNum)
5453
{
5554
for (int i = 0; i < N; i++)
@@ -67,3 +66,68 @@ __kernel void NCC(__global const uchar *patch,
6766
ncc[id+500] = ares;
6867
}
6968
}
69+
70+
__kernel void batchNCC(__global const uchar *patches,
71+
__global const uchar *positiveSamples,
72+
__global const uchar *negativeSamples,
73+
__global float *posNcc,
74+
__global float *negNcc,
75+
int posNum,
76+
int negNum,
77+
int patchNum)
78+
{
79+
int id = get_global_id(0);
80+
bool posFlg;
81+
82+
if (id < 500*patchNum)
83+
posFlg = true;
84+
if (id >= 500*patchNum)
85+
{
86+
//Negative index
87+
id = id - 500*patchNum;
88+
posFlg = false;
89+
}
90+
91+
int modelSampleID = id % 500;
92+
int patchID = id / 500;
93+
94+
//Variables
95+
int s1 = 0, s2 = 0, n1 = 0, n2 = 0, prod = 0;
96+
float sq1 = 0, sq2 = 0, ares = 0;
97+
int N = 225;
98+
99+
//NCC with positive sample
100+
if (posFlg && modelSampleID < posNum)
101+
{
102+
for (int i = 0; i < N; i++)
103+
{
104+
s1 += positiveSamples[modelSampleID * N + i];
105+
s2 += patches[patchID*N + i];
106+
n1 += positiveSamples[modelSampleID * N + i] * positiveSamples[modelSampleID * N + i];
107+
n2 += patches[patchID*N + i] * patches[patchID*N + i];
108+
prod += positiveSamples[modelSampleID * N + i] * patches[patchID*N + i];
109+
}
110+
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
111+
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
112+
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
113+
posNcc[id] = ares;
114+
}
115+
116+
//NCC with negative sample
117+
if (!posFlg && modelSampleID < negNum)
118+
{
119+
for (int i = 0; i < N; i++)
120+
{
121+
122+
s1 += negativeSamples[modelSampleID * N + i];
123+
s2 += patches[patchID*N + i];
124+
n1 += negativeSamples[modelSampleID * N + i] * negativeSamples[modelSampleID * N + i];
125+
n2 += patches[patchID*N + i] * patches[patchID*N + i];
126+
prod += negativeSamples[modelSampleID * N + i] * patches[patchID*N + i];
127+
}
128+
sq1 = sqrt(max(0.0, n1 - 1.0 * s1 * s1 / N));
129+
sq2 = sqrt(max(0.0, n2 - 1.0 * s2 * s2 / N));
130+
ares = (sq2 == 0) ? sq1 / fabs(sq1) : (prod - s1 * s2 / N) / sq1 / sq2;
131+
negNcc[id] = ares;
132+
}
133+
}

0 commit comments

Comments
 (0)