Skip to content

Commit a8c7a56

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents 4c1fb00 + 9d3efbd commit a8c7a56

File tree

4 files changed

+52
-149
lines changed

4 files changed

+52
-149
lines changed

modules/face/src/mace.cpp

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -204,52 +204,18 @@ struct MACEImpl CV_FINAL : MACE {
204204
minMaxLoc(re, &m1, &M1, 0, 0);
205205
double peakCorrPlaneEnergy = M1 / sqrt(sum(re)[0]);
206206
re -= m1;
207-
double value=0;
208-
double num=0;
209-
int rad_1=int(floor((double)(45.0/64.0)*(double)IMGSIZE));
210-
int rad_2=int(floor((double)(27.0/64.0)*(double)IMGSIZE));
211-
// cache a few pow's and sqrts
212-
std::vector<double> r2(IMGSIZE_2X);
213-
Mat_<double> radtab(IMGSIZE_2X,IMGSIZE_2X);
214-
for (int l=0; l<IMGSIZE_2X; l++) {
215-
r2[l] = (l-IMGSIZE) * (l-IMGSIZE);
216-
}
217-
for (int l=0; l<IMGSIZE_2X; l++) {
218-
for (int m=l+1; m<IMGSIZE_2X; m++) {
219-
double rad = sqrt(r2[m] + r2[l]);
220-
radtab(l,m) = radtab(m,l) = rad;
221-
}
222-
}
223-
// mean of the sidelobe area:
224-
for (int l=0; l<IMGSIZE_2X; l++) {
225-
for (int m=0; m<IMGSIZE_2X; m++) {
226-
double rad = radtab(l,m);
227-
if (rad < rad_1) {
228-
if (rad > rad_2) {
229-
value += re(l,m);
230-
num++;
231-
}
232-
}
233-
}
234-
}
235-
value /= num;
236-
// normalize it
237-
double std2=0;
238-
for (int l=0; l<IMGSIZE_2X; l++) {
239-
for (int m=0; m<IMGSIZE_2X; m++) {
240-
double rad = radtab(l,m);
241-
if (rad < rad_1) {
242-
if (rad > rad_2) {
243-
double d = (value - re(l,m));
244-
std2 += d * d;
245-
}
246-
}
247-
}
248-
}
249-
std2 /= num;
250-
std2 = sqrt(std2);
251-
double sca = re(IMGSIZE, IMGSIZE);
252-
double peakToSideLobeRatio = (sca - value) / std2;
207+
208+
// circle mask for the sidelobe area
209+
Mat mask(IMGSIZE_2X, IMGSIZE_2X, CV_8U, Scalar(0));
210+
int rad_1 = int(floor((double)(45.0/64.0)*(double)IMGSIZE));
211+
int rad_2 = int(floor((double)(27.0/64.0)*(double)IMGSIZE));
212+
circle(mask, Point(IMGSIZE,IMGSIZE), rad_1, Scalar(255), -1);
213+
circle(mask, Point(IMGSIZE,IMGSIZE), rad_2, Scalar(0), -1);
214+
215+
Scalar mean, dev;
216+
meanStdDev(re, mean, dev, mask);
217+
double peak = re(IMGSIZE, IMGSIZE);
218+
double peakToSideLobeRatio = (peak - mean[0]) / dev[0];
253219

254220
return 100.0 * peakToSideLobeRatio * peakCorrPlaneEnergy;
255221
}

modules/face/test/test_mace.cpp

Lines changed: 30 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,134 +7,62 @@
77

88
namespace opencv_test { namespace {
99

10-
//
11-
// train on one person, and test against the other
12-
//
13-
#define TESTSET_NAMES testing::Values("david","dudek")
14-
15-
const string TRACKING_DIR = "tracking";
16-
const string FOLDER_IMG = "data";
17-
10+
const string FACE_DIR = "face";
11+
const int WINDOW_SIZE = 64;
1812

1913
class MaceTest
2014
{
2115
public:
2216

23-
MaceTest(string _video, bool salt);
17+
MaceTest(bool salt);
2418
void run();
2519

2620
protected:
27-
vector<Rect> boxes(const string &fn);
28-
vector<Mat> samples(const string &name, int N,int off=0);
29-
int found(const string &vid);
30-
3121
Ptr<MACE> mace;
32-
33-
string video; // train
34-
string vidA; // test
35-
36-
int nSampsTest;
37-
int nSampsTrain;
38-
int nStep;
3922
bool salt;
4023
};
4124

42-
MaceTest::MaceTest(string _video, bool use_salt)
25+
MaceTest::MaceTest(bool use_salt)
4326
{
44-
int Z = 64; // window size
45-
mace = MACE::create(Z);
46-
47-
video = _video;
48-
if (video=="david") { vidA="dudek"; }
49-
if (video=="dudek") { vidA="david"; }
50-
51-
nStep = 2;
52-
nSampsTest = 5;
53-
nSampsTrain = 35;
27+
mace = MACE::create(WINDOW_SIZE);
5428
salt = use_salt;
5529
}
5630

57-
vector<Rect> MaceTest::boxes(const string &fn)
58-
{
59-
std::ifstream in(fn.c_str());
60-
int x,y,w,h;
61-
char sep;
62-
vector<Rect> _boxes;
63-
while (in.good() && (in >> x >> sep >> y >> sep >> w >> sep >> h))
64-
{
65-
_boxes.push_back( Rect(x,y,w,h) );
66-
}
67-
return _boxes;
68-
}
69-
7031
void MaceTest::run()
7132
{
72-
vector<Mat> sam_train = samples(video, nSampsTrain, 0);
73-
if (salt) mace->salt(video); // "owner's" salt with "two factor"
33+
Rect david1 (125,66,58,56);
34+
Rect david2 (132,69,73,74);
35+
Rect detect (199,124,256,274);
36+
string folder = cvtest::TS::ptr()->get_data_path() + FACE_DIR;
37+
Mat train = imread(folder + "/david2.jpg", 0);
38+
Mat tst_p = imread(folder + "/david1.jpg", 0);
39+
Mat tst_n = imread(folder + "/detect.jpg", 0);
40+
vector<Mat> sam_train;
41+
sam_train.push_back( train(Rect(132,69,73,74)) );
42+
sam_train.push_back( train(Rect(130,69,73,72)) );
43+
sam_train.push_back( train(Rect(134,67,73,74)) );
44+
sam_train.push_back( tst_p(Rect(125,66,58,56)) );
45+
sam_train.push_back( tst_p(Rect(123,67,55,58)) );
46+
sam_train.push_back( tst_p(Rect(125,65,58,60)) );
47+
48+
if (salt) mace->salt("it's david"); // "owner's" salt
7449
mace->train(sam_train);
75-
int self_ok = found(video);
76-
if (salt) mace->salt(vidA); // "other's" salt
77-
int false_A = found(vidA);
78-
ASSERT_GE(self_ok, nSampsTest/2); // it may miss positives
79-
ASSERT_EQ(false_A, 0); // but *absolutely* no false positives allowed.
50+
bool self_ok = mace->same(train(david2));
51+
if (salt) mace->salt("this is a test"); // "other's" salt
52+
bool false_A = mace->same(tst_n(detect));
53+
ASSERT_TRUE(self_ok);
54+
ASSERT_FALSE(false_A);
8055
}
8156

82-
int MaceTest::found(const string &vid)
83-
{
84-
vector<Mat> sam_test = samples(vid, nSampsTest, (1+nStep*nSampsTrain));
85-
int hits = 0;
86-
for (size_t i=0; i<sam_test.size(); i++)
87-
{
88-
hits += mace->same(sam_test[i]);
89-
}
90-
return hits;
91-
}
92-
93-
vector<Mat> MaceTest::samples(const string &name, int N, int off)
94-
{
95-
string folder = cvtest::TS::ptr()->get_data_path() + TRACKING_DIR + "/" + name;
96-
string vid = folder + "/" + FOLDER_IMG + "/" + name + ".webm";
97-
string anno = folder + "/gt.txt";
98-
vector<Rect> bb = boxes(anno);
99-
int startFrame = (name=="david") ? 300 : 0;
100-
VideoCapture c;
101-
EXPECT_TRUE(c.open(vid));
102-
vector<Mat> samps;
103-
while (samps.size() < size_t(N))
104-
{
105-
int frameNo = startFrame + off;
106-
c.set(CAP_PROP_POS_FRAMES, frameNo);
107-
Mat frame;
108-
c >> frame;
109-
Rect r = bb[off];
110-
off += nStep;
111-
samps.push_back(frame(r));
112-
}
113-
c.release();
114-
return samps;
115-
}
11657

117-
//[TESTDATA]
118-
PARAM_TEST_CASE(MACE_, string)
58+
TEST(MACE_, unsalted)
11959
{
120-
string dataset;
121-
virtual void SetUp()
122-
{
123-
dataset = GET_PARAM(0);
124-
}
125-
};
126-
127-
128-
TEST_P(MACE_, unsalted)
129-
{
130-
MaceTest test(dataset, false); test.run();
60+
MaceTest test(false); test.run();
13161
}
132-
TEST_P(MACE_, salted)
62+
TEST(MACE_, salted)
13363
{
134-
MaceTest test(dataset, true); test.run();
64+
MaceTest test(true); test.run();
13565
}
13666

13767

138-
INSTANTIATE_TEST_CASE_P(Face, MACE_, TESTSET_NAMES);
139-
14068
}} // namespace

modules/ximgproc/src/l0_smooth.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ namespace cv
252252
CV_Assert(!S.empty());
253253
CV_Assert(S.depth() == CV_8U || S.depth() == CV_16U
254254
|| S.depth() == CV_32F || S.depth() == CV_64F);
255+
CV_Assert(lambda > 0.0);
256+
CV_Assert(kappa > 1.0);
255257

256258
dst.create(src.size(), src.type());
257259

modules/xobjdetect/src/waldboost.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,14 @@ void WaldBoost::fit(Mat& data_pos, Mat& data_neg)
333333

334334

335335
if (loss < 1e-50 || min_err > 0.5) {
336-
std::cerr << "Stopping early" << std::endl;
336+
std::cerr << "Stopping early. loss=" << loss << " min_err=" << min_err << std::endl;
337+
weak_count_ = i + 1;
338+
break;
339+
}
340+
341+
// Avoid crashing on next Mat creation
342+
if (pos <= 1) {
343+
std::cerr << "Stopping early. pos=" << pos << std::endl;
337344
weak_count_ = i + 1;
338345
break;
339346
}

0 commit comments

Comments
 (0)