Learning Using an EPolygonShape (Legacy)

This code snippet shows how to perform pattern learning and finding operations using legacy EPolygonShape to define the model.

C++

#include <eVision/EasyFind/EPatternFinder.h>
#include <eVision/EasyGauge/Legacy/EPolygonShape.h>
using namespace eVision;
using namespace eVision::Legacy;
// 1. Create an EPatternFinder instance for the model
EPatternFinder finder;

// 2. Create you vector model and get its root shape
EVectorModel myModel;
Legacy::EFrameShape& shapeMother = myModel.GetRoot();

// 3. Create your polygon
Legacy::EPolygonShape polygon;
std::vector<EPoint> vertices = { {0.f, 0.f}, {1.f, 0.f}, {1.f, 1.f}, {0.f, 1.f} };
polygon.SetPolygon(Legacy::EPolygon(vertices, true));

// 4. Attach the polygon to the root shape and adjust its parameters according to your application and needs.
polygon.Attach(&shapeMother);
polygon.SetProperty("polarity", "direct");

// 5. Learn the model
finder.Learn(myModel);

// 6. If you want to reuse it later, save the new model (.fnd file).
// finder.Save("myModel.fnd");

// 7. Find the pattern in an image
EImageBW8 srcImage;
// srcImage.Load(...);
std::vector<EFoundPattern> foundPattern = finder.Find(&srcImage);

C#

using eVision;
using Legacy = eVision.Legacy;
// 1. Create an EPatternFinder instance for the model
EPatternFinder finder = new EPatternFinder();

// 2. Create you vector model and get its root shape
EVectorModel myModel = new EVectorModel();
Legacy.EFrameShape root = myModel.Root;

// 3. Create your polygon
Legacy.EPolygonShape polygon = new Legacy.EPolygonShape();
EPoint[] vertices = new EPoint[] { new EPoint(0, 0), new EPoint(1, 0),
  new EPoint(1, 1), new EPoint(0, 1) };
Legacy.EPolygon basePolygon = new Legacy.EPolygon(vertices, true);
polygon.Polygon = basePolygon;

// 4. Attach the polygon to the root shape and adjust its parameters according to your application and needs.
polygon.Attach(root);
polygon.SetProperty("polarity", "direct");

// 5. Learn the model
finder.Learn(myModel);

// 6. If you want to reuse it later, save the new model (.fnd file).
// finder.Save("myModel.fnd");

// 7. Find the pattern in an image
EImageBW8 srcImage = new EImageBW8();
// srcImage.Load(...);
EFoundPattern[] foundPattern = null;
foundPattern = finder.Find(srcImage);

Python

import eVision
import eVision.Legacy as Legacy
# 1. Create an EPatternFinder instance for the model
finder = eVision.EPatternFinder()

# 2. Create you vector model and get its root shape
my_model = eVision.EVectorModel()
root = my_model.Root

# 3. Create your polygon
polygon = Legacy.EPolygonShape()
vertices = [eVision.EPoint(0, 0), eVision.EPoint(1, 0),
  eVision.EPoint(1, 1), eVision.EPoint(0, 1)]
base_polygon = Legacy.EPolygon(vertices, True)
polygon.Polygon = base_polygon

# 4. Attach the polygon to the root shape and adjust its parameters according to your application and needs.
polygon.Attach(root)
polygon.SetProperty("polarity", "direct")

# 5. Learn the model
finder.Learn(my_model)

# 6. If you want to reuse it later, save the new model (.fnd file).
# finder.Save("myModel.fnd")

# 7. Find the pattern in an image
src_image = eVision.EImageBW8()
# srcImage.Load(...);
found_pattern = finder.Find(src_image)