File: test_mace.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (68 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download | duplicates (3)
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
// This file is part of the OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#include "test_precomp.hpp"
#include <fstream>

namespace opencv_test { namespace {

const string FACE_DIR = "face";
const int WINDOW_SIZE = 64;

class MaceTest
{
public:

    MaceTest(bool salt);
    void run();

protected:
    Ptr<MACE> mace;
    bool salt;
};

MaceTest::MaceTest(bool use_salt)
{
    mace = MACE::create(WINDOW_SIZE);
    salt = use_salt;
}

void MaceTest::run()
{
    Rect david1 (125,66,58,56);
    Rect david2 (132,69,73,74);
    Rect detect (199,124,256,274);
    string folder = cvtest::TS::ptr()->get_data_path() + FACE_DIR;
    Mat train = imread(folder + "/david2.jpg", 0);
    Mat tst_p = imread(folder + "/david1.jpg", 0);
    Mat tst_n = imread(folder + "/detect.jpg", 0);
    vector<Mat> sam_train;
    sam_train.push_back( train(Rect(132,69,73,74)) );
    sam_train.push_back( train(Rect(130,69,73,72)) );
    sam_train.push_back( train(Rect(134,67,73,74)) );
    sam_train.push_back( tst_p(Rect(125,66,58,56)) );
    sam_train.push_back( tst_p(Rect(123,67,55,58)) );
    sam_train.push_back( tst_p(Rect(125,65,58,60)) );

    if (salt) mace->salt("it's david"); // "owner's" salt
    mace->train(sam_train);
    bool self_ok = mace->same(train(david2));
    if (salt) mace->salt("this is a test"); // "other's" salt
    bool false_A = mace->same(tst_n(detect));
    ASSERT_TRUE(self_ok);
    ASSERT_FALSE(false_A);
}


TEST(MACE_, unsalted)
{
    MaceTest test(false); test.run();
}
TEST(MACE_, salted)
{
    MaceTest test(true); test.run();
}


}} // namespace