Skip to content

Commit eb0f4a8

Browse files
committed
Bug Fix opencv#1
1. Added frame padding in order to handle cases where the target is close to borders of image 2. Reduced scale parameters for Laplace distribution
1 parent 34356d8 commit eb0f4a8

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

modules/tracking/src/gtrUtils.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,24 @@ namespace cv
7777
Point2f currCenter, prevCenter;
7878
Rect2f targetPatchRect, searchPatchRect;
7979
Mat targetPatch, searchPatch;
80+
Mat prevFramePadded, currFramePadded;
8081

8182
//Crop Target Patch
8283

84+
//Padding
85+
8386
//Previous frame GTBBs center
8487
prevCenter.x = prevBB.x + prevBB.width / 2;
8588
prevCenter.y = prevBB.y + prevBB.height / 2;
8689

87-
targetPatchRect.x = (float)(prevCenter.x - prevBB.width*padTarget / 2.0);
88-
targetPatchRect.y = (float)(prevCenter.y - prevBB.height*padTarget / 2.0);
8990
targetPatchRect.width = (float)(prevBB.width*padTarget);
9091
targetPatchRect.height = (float)(prevBB.height*padTarget);
92+
targetPatchRect.x = (float)(prevCenter.x - prevBB.width*padTarget / 2.0 + targetPatchRect.width);
93+
targetPatchRect.y = (float)(prevCenter.y - prevBB.height*padTarget / 2.0 + targetPatchRect.height);
94+
95+
copyMakeBorder(prevFrame, prevFramePadded, targetPatchRect.height, targetPatchRect.height, targetPatchRect.width, targetPatchRect.width, BORDER_REPLICATE);
9196

92-
targetPatch = prevFrame(targetPatchRect);
97+
targetPatch = prevFramePadded(targetPatchRect);
9398

9499

95100
for (int i = 0; i < samplesInFrame; i++)
@@ -106,25 +111,27 @@ namespace cv
106111
dy = generateRandomLaplacian(bY, 0)*prevBB.height;
107112
ds = generateRandomLaplacian(bS, 1);
108113

109-
//Limit scale coefficient
114+
//Limit coefficients
115+
dx = min(dx, (double)prevBB.width);
116+
dx = max(dx, (double)-prevBB.width);
117+
dy = min(dy, (double)prevBB.height);
118+
dy = max(dy, (double)-prevBB.height);
110119
ds = min(ds, Ymax);
111120
ds = max(ds, Ymin);
112121

113-
//cout << dx << " " << dy << " " << ds << endl;
114-
115122
searchPatchRect.width = (float)(prevBB.width*padSearch*ds);
116-
searchPatchRect.height = (float)(prevBB.height*padSearch*ds);
117-
searchPatchRect.x = (float)(currCenter.x + dx - searchPatchRect.width / 2.0);
118-
searchPatchRect.y = (float)(currCenter.y + dy - searchPatchRect.height / 2.0);
119-
120-
searchPatch = currFrame(searchPatchRect);
123+
searchPatchRect.height =(float)(prevBB.height*padSearch*ds);
124+
searchPatchRect.x = (float)(currCenter.x + dx - searchPatchRect.width / 2.0 + searchPatchRect.width);
125+
searchPatchRect.y = (float)(currCenter.y + dy - searchPatchRect.height / 2.0 + searchPatchRect.height);
126+
copyMakeBorder(currFrame, currFramePadded, searchPatchRect.height, searchPatchRect.height, searchPatchRect.width, searchPatchRect.width, BORDER_REPLICATE);
127+
searchPatch = currFramePadded(searchPatchRect);
121128

122129
//Calculate Relative GTBB in search patch
123130
Rect2f relGTBB;
124131
relGTBB.width = currBB.width;
125132
relGTBB.height = currBB.height;
126-
relGTBB.x = currBB.x - searchPatchRect.x;
127-
relGTBB.y = currBB.y - searchPatchRect.y;
133+
relGTBB.x = currBB.x - searchPatchRect.x + searchPatchRect.width;
134+
relGTBB.y = currBB.y - searchPatchRect.y + searchPatchRect.height;
128135

129136
//Link to the sample struct
130137
sample.targetPatch = targetPatch.clone();

modules/tracking/src/gtrUtils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace cv
2424
const double padSearch = 2.0;
2525

2626
//Scale parameters for Lablace distribution for Translation/Scale
27-
const double bX = 1.0/5;
28-
const double bY = 1.0 / 5;
27+
const double bX = 1.0/10;
28+
const double bY = 1.0/10;
2929
const double bS = 1.0/15;
3030

3131
//Limits of scale changes

0 commit comments

Comments
 (0)