bool trainable()

This is a virtual function. Check if the distance is trainable. The default version returns true. Distances that are not trainable should derive from UntrainableDistance instead.

  • function defintion:

    virtual bool trainable()
    
  • parameters: NONE

  • output: (bool) Returns true if the distance is trainable, false otherwise.

void train(const TemplateList &src)

This is a pure virtual function. Train the distance on a provided TemplateList of data. The structure of the data is dependent on the distance to be trained. Distances that are not trainable should derive from UntrainableDistance so they do not have to overload this function.

  • function definition:

    virtual void train(const TemplateList &src) = 0
    
  • parameters:

    Parameter Type Description
    src const TemplateList & Training data for the distance.
  • output: (void)

  • example:
    // Create data for a 2-class classification problem
    Template t1("training_pic1.jpg");
    t1.file.set("Label", 0);
    Template t2("training_pic2.jpg");
    t2.file.set("Label", 0);
    Template t3("training_pic3.jpg");
    t3.file.set("Label", 1);
    Template t4("training_pic4.jpg");
    t4.file.set("Label", 1);
    
    TemplateList training_data(QList<Template>() << t1 << t2 << t3 << t4);
    
    Transform *distance = Distance::fromAlgorithm("Enrollment:Distance");
    distance->train(training_data); // Images are enrolled through Enrollment and the passed to Distance for training
    

void compare(const TemplateList &target, const [TemplateList] &query, Output)

This is a virtual function. Compare two TemplateLists and store the results in a provided output.

  • function definition:

    virtual void compare(const TemplateList &target, const TemplateList &query, Output *output) const
    
  • parameters:

    Parameter Type Description
    target const TemplateList & List of templates to compare the query against
    query const TemplateList & List of templates to compare against the target
    output Output * Output plugin to use to store the results of the comparisons
  • output: (void)

QList<float> compare(const TemplateList &target, const Template &query)

This is a virtual function. Compare a query against a list of targets. Each comparison results in a floating point response which is the distance between the query and a specific target.

  • function definition:

    virtual QList<float> compare(const TemplateList &targets, const Template &query) const
    
  • parameters:

    Parameter Type Description
    targets const TemplateList & List of templates to compare the query against
    query const Template & Query template to be compared
  • output: (QList<float>) Returns a list of the responses from each comparison between the query and a target.

  • example:
    Template t1("target_picture1.jpg");
    Template t2("target_picture2.jpg");
    Template t3("target_picture3.jpg");
    
    TemplateList targets = TemplateList() << t1 << t2 << t3;
    
    Template query("query_picture.jpg");
    
    algorithm = "Enrollment:Distance";
    
    Transform *transform = Transform::fromAlgorithm(algorithm);
    Distance *distance = Distance::fromAlgorithm(algorithm);
    
    targets >> *transform;
    query   >> *transform;
    
    distance->compare(targets, query); // returns [0.37, -0.56, 4.35] *Note results are made up!
    

float compare(const Template &a, const Template &b)

This is a virtual function. Compare two templates and get the difference between them.

  • function definition:

    virtual float compare(const Template &a, const Template &b) const
    
  • parameters:

    Parameter Type Description
    a const Template & First template to compare
    b const Template & Second template to compare
  • output: (float) Returns the calculated difference between the provided templates

  • example:

Template a("picture_a.jpg"); Template b("picture_b.jpg");

algorithm = "Enrollment:Distance";

Transform transform = Transform::fromAlgorithm(algorithm); Distance distance = Distance::fromAlgorithm(algorithm);

a >> transform; b >> transform;

distance->compare(a, b); // returns 16.43 *Note results are made up!

float compare(const Mat &a, const Mat &b)

This is a virtual function. Compare two Mats and get the difference between them.

  • function definition:

    virtual float compare(const Mat &a, const Mat &b) const
    
  • parameters:

    Parameter Type Description
    a const Mat & First matrix to compare
    b const Mat & Second matrix to compare
  • output: (float) Returns the calculated difference between the provided Mats

  • example:
    Template a("picture_a.jpg");
    Template b("picture_b.jpg");
    
    algorithm = "Enrollment:Distance";
    
    Transform *transform = Transform::fromAlgorithm(algorithm);
    Distance *distance = Distance::fromAlgorithm(algorithm);
    
    a >> *transform;
    b >> *transform;
    
    distance->compare(a.m(), b.m()); // returns 16.43 *Note results are made up!
    

float compare(const uchar *a, const uchar *b, size_t size)

This is a virtual function. Compare two buffers and get the difference between them

  • function definition:

    virtual float compare(const uchar *a, const uchar *b, size_t size) const
    
  • parameters:

    Parameter Type Description
    a const uchar * First buffer to compare
    b const uchar * Second buffer to compare
    size size_t Size of buffers a and b (they must be the same size)
  • output: (float) Returns the calculated difference between the provided buffers

  • example:
    Template a("picture_a.jpg");
    Template b("picture_b.jpg");
    
    algorithm = "Enrollment:Distance";
    
    Transform *transform = Transform::fromAlgorithm(algorithm);
    Distance *distance = Distance::fromAlgorithm(algorithm);
    
    a >> *transform;
    b >> *transform;
    
    distance->compare(a.m().ptr(), b.m().ptr()); // returns -4.32 *Note results are made up!
    

Distance *make(const QString &description)

This is a protected function. Makes a child distance from a provided description by calling make with parent = this.

  • function definition:

    inline Distance *make(const QString &description)
    
  • parameters:

    Parameter Type Description
    description const QString & Description of the child distance
  • output: (Distance *) Returns a pointer to the created child distance