Pattern Matching and Retrieving Results

This code snippet shows how to perform pattern matching operations and retrieve the results.

C++

#include <eVision/EasyMatch/EMatcher.h>
using namespace eVision;
// Image constructor
EImageBW8 srcImage;
// EMatcher constructor
EMatcher matcher;
// ...
// Load a model file
matcher.Load("myModel.mch");
// Perform the matching
std::vector<EFoundPattern> matches = matcher.Match(&srcImage);
// Retrieve the number of occurrences
size_t numOccurrences = matches.size();
// Retrieve the first occurrence
EFoundPattern myOccurrence = matches[0];
// Retrieve its score and position
float score = myOccurrence.GetScore();
float centerX = myOccurrence.GetCenter().GetX();

C#

using eVision;
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// EMatcher constructor
EMatcher matcher = new EMatcher();
// EFoundPattern constructor
EFoundPattern[] matches = null;
// ...
// Load a model file
matcher.Load("myModel.mch");
// Perform the matching
matches = matcher.Match(srcImage);
// Retrieve the number of occurrences
int numOccurrences = matches.Length;
// Retrieve the first occurrence
EFoundPattern myOccurrence = matches[0];
// Retrieve its score and position
float score = myOccurrence.Score;
float centerX = myOccurrence.Center.X;
float centerY = myOccurrence.Center.Y;

Python

import eVision
# Image constructor
src_image = eVision.EImageBW8()
# EMatcher constructor
matcher = eVision.EMatcher()
# ...
# Load a model file
matcher.Load("myModel.mch")
# Perform the matching
matches = matcher.Match(src_image)
# Retrieve the number of occurrences
numOccurrences = len(matches)
# Retrieve the first occurrence
myOccurrence = matches[0]
# Retrieve its score and position
score = myOccurrence.Score
centerX = myOccurrence.Center.X
centerY = myOccurrence.Center.Y