Rectangle Fitting (Legacy)

This code snippet shows how to create a rectangle measurement tool, adjust the transition parameters, set the nominal gauge position, perform the measurement and retrieve the result using the legacy EasyGauge API.

C++

#include <eVision/EasyGauge/Legacy/ERectangleGauge.h>
using namespace eVision;
using namespace eVision::Legacy;
// Image constructor
EImageBW8 srcImage;
// ERectangleGauge constructor
Legacy::ERectangleGauge rectangleGauge;
// Adjust the transition parameters
rectangleGauge.SetTransitionType(ETransitionType_Bw);
rectangleGauge.SetTransitionChoice(ETransitionChoice_LargestAmplitude);
// Set the rectangle fitting gauge position,
// size (50x30 units) and orientation (15)
EPoint center(256.f, 256.f);
Legacy::ERectangle rectangle(center, 50.f, 30.f, Easy::FromDegrees(15.f));
rectangleGauge.SetRectangle(rectangle);
// Measure
rectangleGauge.Measure(&srcImage);
// Get the size and the rotation angle of the fitted rectangle
float sizeX = rectangleGauge.GetMeasuredRectangle().GetSizeX();
float sizeY = rectangleGauge.GetMeasuredRectangle().GetSizeY();
float angle = rectangleGauge.GetMeasuredRectangle().GetAngle();
// Save the point gauge measurement context
rectangleGauge.Save("myRectangleGauge.gge");

C#

using eVision;
using Legacy = eVision.Legacy;
// Image constructor
EImageBW8 srcImage = new EImageBW8();
// ERectangleGauge constructor
Legacy.ERectangleGauge rectangleGauge = new Legacy.ERectangleGauge();
// Adjust the transition parameters
rectangleGauge.TransitionType = ETransitionType.Bw;
rectangleGauge.TransitionChoice = ETransitionChoice.LargestAmplitude;
// Set the rectangle fitting gauge position,
// size (50x30 units) and orientation (15°)
rectangleGauge.SetCenterXY(256.0f, 256.0f);
rectangleGauge.SetSize(50.0f, 30.0f);
rectangleGauge.Angle = Easy.FromDegrees(15.0f);
// Measure
rectangleGauge.Measure(srcImage);
// Get the size and the rotation angle of the fitted rectangle
float sizeX = rectangleGauge.MeasuredRectangle.SizeX;
float sizeY = rectangleGauge.MeasuredRectangle.SizeY;
float angle = rectangleGauge.MeasuredRectangle.Angle;
// Save the point gauge measurement context
rectangleGauge.Save("myRectangleGauge.gge");

Python

import eVision
import eVision.Legacy as Legacy
# Image constructor
src_image = eVision.EImageBW8()
# ERectangleGauge constructor
rectangle_gauge = Legacy.ERectangleGauge()
# Adjust the transition parameters
rectangle_gauge.TransitionType = eVision.ETransitionType.Bw
rectangle_gauge.TransitionChoice = eVision.ETransitionChoice.LargestAmplitude
# Set the rectangle fitting gauge position,
# size (50x30 units) and orientation (15°)
rectangle_gauge.SetCenterXY(256.0, 256.0)
rectangle_gauge.SetSize(50.0, 30.0)
rectangle_gauge.Angle = eVision.Easy.FromDegrees(15.0)
# Measure
rectangle_gauge.Measure(src_image)
# Get the size and the rotation angle of the fitted rectangle
sizeX = rectangle_gauge.MeasuredRectangle.SizeX
sizeY = rectangle_gauge.MeasuredRectangle.SizeY
angle = rectangle_gauge.MeasuredRectangle.Angle
# Save the point gauge measurement context
rectangle_gauge.Save("myRectangleGauge.gge")