Skip to content

face_MACE

faceclassOpenCV 5.0.0
import { face_MACE } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSface_MACE
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits Algorithm.

Minimum Average Correlation Energy Filter useful for authentication with (cancellable) biometrical features. (does not need many positives to train (10-50), and no negatives at all, also robust to noise/salting)

see also: [Savvides04]

this implementation is largely based on: https://code.google.com/archive/p/pam-face-authentication (GSOC 2009)

use it like:

    Ptr<face::MACE> mace = face::MACE::create(64);

    vector<Mat> pos_images = ...
    mace->train(pos_images);

    Mat query = ...
    bool same = mace->same(query);
you can also use two-factor authentication, with an additional passphrase:
    String owners_passphrase = "ilikehotdogs";
    Ptr<face::MACE> mace = face::MACE::create(64);
    mace->salt(owners_passphrase);
    vector<Mat> pos_images = ...
    mace->train(pos_images);

    // now, users have to give a valid passphrase, along with the image:
    Mat query = ...
    cout << "enter passphrase: ";
    string pass;
    getline(cin, pass);
    mace->salt(pass);
    bool same = mace->same(query);
    
save/load your model:
    Ptr<face::MACE> mace = face::MACE::create(64);
    mace->train(pos_images);
    mace->save("my_mace.xml");

    // later:
    Ptr<MACE> reloaded = MACE::load("my_mace.xml");
    reloaded->same(some_image);
    

Constructors and members

static load

face_MACE.load: constructor

load(filename: EmbindString, objname: EmbindString): face_MACE | null;
2 available overloads
load(filename: EmbindString): face_MACE | null;
load(filename: EmbindString, objname: EmbindString): face_MACE | null;
filename

build a new MACE instance from a pre-serialized FileStorage

objname

(optional) top-level node in the FileStorage

Returns

The face_MACE | null result.

static create

face_MACE.create: constructor

create(IMGSIZE: number): face_MACE | null;
2 available overloads
create(): face_MACE | null;
create(IMGSIZE: number): face_MACE | null;
IMGSIZE

images will get resized to this (should be an even number)

Returns

The face_MACE | null result.

clone

Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.

clone(): this;
Returns

The this result.

salt

optionally encrypt images with random convolution

salt(passphrase: EmbindString): void;
passphrase

a crc64 random seed will get generated from this

train

train it on positive features compute the mace filter: h = D(-1) * X * (X(+) * D(-1) * X)(-1) * C also calculate a minimal threshold for this class, the smallest self-similarity from the train images

train(images: MatVector): void;
images

a vector<Mat> with the train images

same

correlate query img and threshold to min class value

same(query: Mat): boolean;
query

a Mat with query image

Returns

The boolean result.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.