44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
|
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
|
using OpenCvSharp;
|
|
|
|
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
|
|
|
[Category("Morphology")]
|
|
public class DilationOperation:BaseOperation
|
|
{
|
|
|
|
public DilationOperation()
|
|
{
|
|
CanHaveProcessingError = false;
|
|
}
|
|
|
|
public int Dilation { get; set; } = 1;
|
|
|
|
protected override void InterpretInternal(Context context)
|
|
{
|
|
if (!CheckImageExists(context)) return;
|
|
if (!CheckGrayscale(context)) return;
|
|
|
|
var element=Cv2.GetStructuringElement(MorphShapes.Ellipse, new Size(Dilation, Dilation));
|
|
context.ActiveImage = new HawkeyeImage()
|
|
{
|
|
ImageData = context.ActiveImage!.ImageData.Dilate(element)
|
|
};
|
|
|
|
Status="Dilation "+Dilation;
|
|
Result = true;
|
|
}
|
|
|
|
public override void Save(BinaryWriter bw)
|
|
{
|
|
base.Save(bw);
|
|
bw.Write(Dilation);
|
|
}
|
|
|
|
public override void Load(BinaryReader br)
|
|
{
|
|
base.Load(br);
|
|
Dilation = br.ReadInt32();
|
|
}
|
|
} |