-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevss_learning_kernel.cpp
163 lines (136 loc) · 4.4 KB
/
evss_learning_kernel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "log.h"
#include "param.h"
#include "TLDUtil.h"
#include "evss_learning_kernel.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
void learnNN(learningLocalData* krnl, vector<patchNorm> &patches)
{
// REMOVED... This is a sample code only
}
void updatePosteriors(learningLocalData* krnl, vx_int32* featureVector, vx_bool positive)
{
// REMOVED... This is a sample code only
}
void learnFern(learningLocalData* krnl, vx_uint8* img, vx_int32 s, vx_uint32 x, vx_uint32 y,
vx_bool positive, vx_int32* featureVector)
{
// REMOVED... This is a sample code only
}
vx_status setupKernel(learningLocalData* krnl)
{
// REMOVED... This is a sample code only
num = 0;
status |= vxQueryArray(trackArr, VX_ARRAY_ATTRIBUTE_NUMITEMS, &num, sizeof(num));
if(!status && num == 1){
arrPtr = NULL;
status |= vxAccessArrayRange(trackArr, 0, 1, &stride, &arrPtr, VX_READ_ONLY);
krnl->internal.trackBB_r = vxArrayItem(vx_rectangle_t, arrPtr, 0, stride);
krnl->internal.numTracks = (vx_uint32)num;
status |= vxCommitArrayRange(trackArr, 0, 1, arrPtr);
/**
* preserve target aspect ratio
* and boundry check
*/
// REMOVED... This is a sample code only
vx_float32 ar = krnl->constants.objHeight/(vx_float32)krnl->constants.objWidth;
vx_float32 height = krnl->internal.trackBB_r.end_y - krnl->internal.trackBB_r.start_y;
vx_int32 offset = (ar-1) * height / 2.f;
krnl->internal.trackBB_r.start_y -= offset;
krnl->internal.trackBB_r.end_y += offset;
}
// REMOVED... This is a sample code only
return status;
}
void fuseDetections(learningLocalData* krnl)
{
// REMOVED... This is a sample code only
}
vx_status vxSnpsLearning(learningLocalData* krnl)
{
vx_status status = setupKernel(krnl);
if(status){
error_print("vxSnpsLearning::setupKernel() returned with error code %d\n", status);
return status;
}
fuseDetections(krnl);
if(!krnl->internal.valid){
// REMOVED... This is a sample code only
}
/**
* learning starts from here.
*/
vx_image input = krnl->arg.input;
vx_rectangle_t fusedBB = krnl->internal.fusedBB;
vx_uint32 imgWidth = krnl->constants.imgWidth;
void* src_base = NULL;
void* msk_base = NULL;
// REMOVED... This is a sample code only
vx_uint8* imgPtr = (vx_uint8*) src_base;
vx_uint8* mskPtr = (vx_uint8*) msk_base;
vx_int32 featureVector[FERN_SIZE];
vx_uint32 x, y, i = 0, sIdx = 0;
vx_int32 s = 0;
for(s = krnl->constants.minScale; s <= krnl->constants.maxScale; s++){
vx_float32 scale = powf(1.2f, (float)s);
vx_uint32 w = krnl->constants.objWidth * scale;
vx_uint32 h = krnl->constants.objHeight * scale;
// REMOVED... This is a sample code only
sIdx++;
for( y = 1 ; (y + h) <= krnl->constants.imgHeight; y += sH){
int cntrY = (y + hHalf) * imgWidth;
int quartY1 = cntrY + hQuart;
int quartY2 = cntrY - hQuart;
for( x = 1; (x + w) <= imgWidth; x += sW){
int cntrX = x + wHalf;
if( mskPtr[cntrY + cntrX] == 0){
continue;
}
int quartX = cntrX + wQuart;
if( mskPtr[quartY1 + quartX] == 0){
continue;
}
// REMOVED... This is a sample code only
vx_float32 overlap = calcOverlapRectRect(&fusedBB, &tmp_r);
if(overlap > 0.6f){
positiveIndices.push_back(pair<int, float>(i, overlap));
}
if(overlap < 0.2f){
// REMOVED... This is a sample code only
}
i++;
}
}
}
// REMOVED... This is a sample code only
for( i = 0; i < negativeIndices.size() && !status ; i++){
// REMOVED... This is a sample code only
learnFern(krnl, imgPtr, scalesIdx[idx],xywh_r.start_x, xywh_r.start_y, vx_false_e, featureVector);
}
// REMOVED... This is a sample code only
if(status == VX_SUCCESS){
learnNN(krnl, patches);
}
/**
* clear data
*/
positiveIndices.clear();
negativeIndices.clear();
patches.clear();
xywh.clear();
scalesIdx.clear();
/// TODO: commit range?
status |= vxCommitArrayRange(krnl->arg.intArray, 0, 0, int_base);
status |= vxCommitArrayRange(krnl->arg.intSqArray, 0, 0, intSq_base);
status |= vxCommitImagePatch(input, NULL, 0, &src_addr, src_base);
if(status){
error_print("vxSnpsLearning::commit returned error code %d\n", status);
}
return status;
}
vx_status calcNormalizedRect(vx_image input, vx_rectangle_t *rect, vx_float32 *patch)
{
// REMOVED... This is a sample code only
}