Skip to content

Commit fd63e17

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 9110ccb + 6bd26d3 commit fd63e17

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

modules/face/src/mace.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ struct MACEImpl CV_FINAL : MACE {
119119
int IMGSIZE_2X = IMGSIZE * 2;
120120
int TOTALPIXEL = IMGSIZE_2X * IMGSIZE_2X;
121121

122-
Mat_<Vec2d> D(TOTALPIXEL, 1, 0.0);
123-
Mat_<Vec2d> S(TOTALPIXEL, size, 0.0);
124-
Mat_<Vec2d> SPLUS(size, TOTALPIXEL, 0.0);
122+
Mat_<double> D(TOTALPIXEL, 1, 0.0);
123+
Mat_<Vec2d> S(TOTALPIXEL, size, Vec2d(0,0));
124+
Mat_<Vec2d> SPLUS(size, TOTALPIXEL, Vec2d(0,0));
125125
for (int i=0; i<size; i++) {
126126
Mat_<Vec2d> dftImg = isdft ? images[i] : dftImage(images[i]);
127127
for (int l=0; l<IMGSIZE_2X; l++) {
@@ -130,35 +130,24 @@ struct MACEImpl CV_FINAL : MACE {
130130
Vec2d s = dftImg(l, m);
131131
S(j, i) = s;
132132
SPLUS(i, j) = Vec2d(s[0], -s[1]);
133-
D(j, 0)[0] += (s[0]*s[0]) + (s[1]*s[1]);
133+
D(j, 0) += (s[0]*s[0]) + (s[1]*s[1]);
134134
}
135135
}
136136
}
137+
Mat_<double> DSQ; cv::sqrt(D, DSQ);
138+
Mat_<double> DINV = TOTALPIXEL * size / DSQ;
137139

138-
#if 0 // https://github.com/opencv/opencv_contrib/issues/1848
139-
// FIXIT What is expected here? complex numbers math?
140-
// D(,)[1] is 0 (always)
141-
Mat sq; cv::sqrt(D, sq); // Per-element sqrt(): sq(,)[1] is 0 (always)
142-
Mat_<Vec2d> DINV = TOTALPIXEL * size / sq; // "per-element" division which provides "Inf"
143-
#else
144-
Mat sq; cv::sqrt(D.reshape(1).col(0), sq);
145-
Mat_<Vec2d> DINV(TOTALPIXEL, 1, Vec2d(0, 0));
146-
DINV.reshape(1).col(0) = TOTALPIXEL * size / sq;
147-
#endif
148-
Mat_<Vec2d> DINV_S(TOTALPIXEL, size, 0.0);
149-
Mat_<Vec2d> SPLUS_DINV(size, TOTALPIXEL, 0.0);
140+
Mat_<Vec2d> DINV_S(TOTALPIXEL, size);
141+
Mat_<Vec2d> SPLUS_DINV(size, TOTALPIXEL);
150142
for (int l=0; l<size; l++) {
151143
for (int m=0; m<TOTALPIXEL; m++) {
152-
SPLUS_DINV(l, m)[0] = SPLUS(l,m)[0] * DINV(m,0)[0];
153-
SPLUS_DINV(l, m)[1] = SPLUS(l,m)[1] * DINV(m,0)[1]; // FIXIT: DINV(,)[1] is 0 (always)
154-
DINV_S(m, l)[0] = S(m,l)[0] * DINV(m,0)[0];
155-
DINV_S(m, l)[1] = S(m,l)[1] * DINV(m,0)[1];
144+
DINV_S(m, l) = S(m,l) * DINV(m,0);
145+
SPLUS_DINV(l, m) = SPLUS(l,m) * DINV(m,0);
156146
}
157147
}
158148

159149
Mat_<Vec2d> SPLUS_DINV_S = SPLUS_DINV * S;
160-
Mat_<Vec2d> SPLUS_DINV_S_INV(size, size);
161-
Mat_<double> SPLUS_DINV_S_INV_1(2*size, 2*size);
150+
Mat_<double> SPLUS_DINV_S_INV_1(2*size, 2*size, 0.0);
162151
for (int l=0; l<size; l++) {
163152
for (int m=0; m<size; m++) {
164153
Vec2d s = SPLUS_DINV_S(l, m);
@@ -170,14 +159,15 @@ struct MACEImpl CV_FINAL : MACE {
170159
}
171160
invert(SPLUS_DINV_S_INV_1, SPLUS_DINV_S_INV_1);
172161

162+
Mat_<Vec2d> SPLUS_DINV_S_INV(size, size);
173163
for (int l=0; l<size; l++) {
174164
for (int m=0; m<size; m++) {
175165
SPLUS_DINV_S_INV(l, m) = Vec2d(SPLUS_DINV_S_INV_1(l,m), SPLUS_DINV_S_INV_1(l,m+size));
176166
}
177167
}
178168

179169
Mat_<Vec2d> Hmace = DINV_S * SPLUS_DINV_S_INV;
180-
Mat_<Vec2d> C(size,1, Vec2d(1,0));
170+
Mat_<Vec2d> C(size, 1, Vec2d(1,0));
181171
maceFilter = Mat(Hmace * C).reshape(2,IMGSIZE_2X);
182172
}
183173

modules/tracking/src/trackerKCF.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ namespace cv{
675675
if(region.width>img.cols)region.width=img.cols;
676676
if(region.height>img.rows)region.height=img.rows;
677677

678+
// return false if region is empty
679+
if (region.empty())
680+
return false;
681+
678682
patch=img(region).clone();
679683

680684
// add some padding to compensate when the patch is outside image border

0 commit comments

Comments
 (0)