63 lines
1.4 KiB
C#
63 lines
1.4 KiB
C#
using Hawkeye.VisionBuilder.Workflow;
|
|
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements;
|
|
using OpenCvSharp;
|
|
|
|
namespace VisionBuilder.UI.Recipes.HawkeyeRecipe;
|
|
|
|
public class OpenCVCanvas:ICanvas
|
|
{
|
|
private readonly Mat _image;
|
|
|
|
public OpenCVCanvas(Mat image)
|
|
{
|
|
_image = image;
|
|
}
|
|
|
|
public void DrawRectangle(Vector2 start, Vector2 size, bool isGood)
|
|
{
|
|
_image.Rectangle(
|
|
new Point(start.X, start.Y),
|
|
new Point(start.X + size.X, start.Y + size.Y),
|
|
isGood ? Scalar.Green : Scalar.Red,
|
|
2);
|
|
}
|
|
|
|
public void DrawLine(Vector2 start, Vector2 end, LineType type)
|
|
{
|
|
var color = type switch
|
|
{
|
|
LineType.Good => Scalar.Green,
|
|
LineType.Bad => Scalar.Red,
|
|
_ => Scalar.White
|
|
};
|
|
_image.Line(
|
|
new Point(start.X, start.Y),
|
|
new Point(end.X, end.Y),
|
|
color,
|
|
2);
|
|
|
|
}
|
|
|
|
public void DrawPoly(Vector2[] points, bool isGood)
|
|
{
|
|
var color = isGood ? Scalar.Green : Scalar.Red;
|
|
var cvPoints = points.Select(p => new Point(p.X, p.Y)).ToArray();
|
|
_image.Polylines([cvPoints], true, color, 2);
|
|
|
|
}
|
|
|
|
public void DrawCross(Vector2 location)
|
|
{
|
|
|
|
}
|
|
|
|
public void DrawNode(Vector2 location)
|
|
{
|
|
|
|
}
|
|
|
|
public void DrawArrow(Vector2 location, Vector2 direction)
|
|
{
|
|
|
|
}
|
|
} |