@@ -77,19 +77,24 @@ namespace cv
77
77
Point2f currCenter, prevCenter;
78
78
Rect2f targetPatchRect, searchPatchRect;
79
79
Mat targetPatch, searchPatch;
80
+ Mat prevFramePadded, currFramePadded;
80
81
81
82
// Crop Target Patch
82
83
84
+ // Padding
85
+
83
86
// Previous frame GTBBs center
84
87
prevCenter.x = prevBB.x + prevBB.width / 2 ;
85
88
prevCenter.y = prevBB.y + prevBB.height / 2 ;
86
89
87
- targetPatchRect.x = (float )(prevCenter.x - prevBB.width *padTarget / 2.0 );
88
- targetPatchRect.y = (float )(prevCenter.y - prevBB.height *padTarget / 2.0 );
89
90
targetPatchRect.width = (float )(prevBB.width *padTarget);
90
91
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);
91
96
92
- targetPatch = prevFrame (targetPatchRect);
97
+ targetPatch = prevFramePadded (targetPatchRect);
93
98
94
99
95
100
for (int i = 0 ; i < samplesInFrame; i++)
@@ -106,25 +111,27 @@ namespace cv
106
111
dy = generateRandomLaplacian (bY, 0 )*prevBB.height ;
107
112
ds = generateRandomLaplacian (bS, 1 );
108
113
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 );
110
119
ds = min (ds, Ymax);
111
120
ds = max (ds, Ymin);
112
121
113
- // cout << dx << " " << dy << " " << ds << endl;
114
-
115
122
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);
121
128
122
129
// Calculate Relative GTBB in search patch
123
130
Rect2f relGTBB;
124
131
relGTBB.width = currBB.width ;
125
132
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 ;
128
135
129
136
// Link to the sample struct
130
137
sample.targetPatch = targetPatch.clone ();
0 commit comments