check point
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class ClosingOperation:BaseOperation
|
||||
{
|
||||
public ClosingOperation()
|
||||
{
|
||||
CanHaveProcessingError = false;
|
||||
}
|
||||
|
||||
public int Closing { 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(Closing, Closing));
|
||||
context.ActiveImage = new HawkeyeImage()
|
||||
{
|
||||
ImageData = context.ActiveImage!.ImageData.MorphologyEx(MorphTypes.Close, element)
|
||||
};
|
||||
|
||||
Status = $"Closing {Closing}";
|
||||
Result = true;
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
bw.Write(Closing);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
Closing = br.ReadInt32();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Rectangle;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class CutOperation:BaseOperation
|
||||
{
|
||||
|
||||
private readonly WorkflowList _workflowList;
|
||||
public Guid ReferencePoint { get; set; } = new Guid();
|
||||
|
||||
public RectangleElement? SearchArea { get; set; } = null;
|
||||
|
||||
public CutOperation(WorkflowList workflowList)
|
||||
{
|
||||
_workflowList = workflowList;
|
||||
SearchArea = new RectangleElement()
|
||||
{
|
||||
Editable = true,
|
||||
Location = Vector2.One * 5,
|
||||
Size = new Vector2(100, 100),
|
||||
IsGood = true
|
||||
};
|
||||
|
||||
CanHaveProcessingError = false;
|
||||
|
||||
}
|
||||
|
||||
public override void SetParameters(Dictionary<string, object> parameters)
|
||||
{
|
||||
base.SetParameters(parameters);
|
||||
|
||||
SearchArea.SetPivot(_workflowList.GetOriginById(ReferencePoint).Origin.Location);
|
||||
}
|
||||
|
||||
protected override void InterpretInternal(Context context)
|
||||
{
|
||||
if (!CheckImageExists(context))return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SearchArea.MovePivot(_workflowList.GetOriginById(ReferencePoint).Origin.Location);
|
||||
context.GraphicsElements.Add(SearchArea);
|
||||
|
||||
var img = context.ActiveImage.ImageData;
|
||||
var mat = new Mat(img.Size(), img.Type(), Scalar.Black);
|
||||
SearchArea.FillMat(mat);
|
||||
|
||||
var cut = img.BitwiseAnd(mat).ToMat();
|
||||
|
||||
context.ActiveImage=new HawkeyeImage()
|
||||
{
|
||||
ImageData = cut
|
||||
};
|
||||
|
||||
Status="Cut";
|
||||
Result = true;
|
||||
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
bw.Write(ReferencePoint.ToString());
|
||||
|
||||
SearchArea.Save(bw);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
ReferencePoint = new Guid(br.ReadString());
|
||||
SearchArea = new RectangleElement();
|
||||
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class HatsOperation : BaseOperation
|
||||
{
|
||||
public HatsOperation()
|
||||
{
|
||||
CanHaveProcessingError = false;
|
||||
}
|
||||
|
||||
public int HatSize { get; set; } = 1;
|
||||
|
||||
protected override void InterpretInternal(Context context)
|
||||
{
|
||||
if (!CheckImageExists(context)) return;
|
||||
if (!CheckGrayscale(context)) return;
|
||||
|
||||
var element = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(HatSize, HatSize));
|
||||
context.ActiveImage = new HawkeyeImage()
|
||||
{
|
||||
ImageData = context.ActiveImage!.ImageData.MorphologyEx(MorphTypes.TopHat, element)
|
||||
};
|
||||
|
||||
Status = $"Black Hat {HatSize}";
|
||||
Result = true;
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
bw.Write(HatSize);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
HatSize = br.ReadInt32();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class OpeningOperation : BaseOperation
|
||||
{
|
||||
public OpeningOperation()
|
||||
{
|
||||
CanHaveProcessingError = false;
|
||||
}
|
||||
|
||||
public int Opening { get; set; } = 1;
|
||||
|
||||
protected override void InterpretInternal(Context context)
|
||||
{
|
||||
if (!CheckImageExists(context)) return;
|
||||
if (!CheckGrayscale(context)) return;
|
||||
|
||||
var element = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(Opening, Opening));
|
||||
context.ActiveImage = new HawkeyeImage()
|
||||
{
|
||||
ImageData = context.ActiveImage!.ImageData.MorphologyEx(MorphTypes.Open, element)
|
||||
};
|
||||
|
||||
Status = $"Opening {Opening}";
|
||||
Result = true;
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
bw.Write(Opening);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
Opening = br.ReadInt32();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class SubtractOperation : BaseOperation
|
||||
{
|
||||
public string SlotName { get; set; } = "Image";
|
||||
|
||||
public SubtractOperation()
|
||||
{
|
||||
CanHaveProcessingError = false;
|
||||
}
|
||||
|
||||
protected override void InterpretInternal(Context context)
|
||||
{
|
||||
if (!CheckImageExists(context)) return;
|
||||
if (!CheckGrayscale(context)) return;
|
||||
|
||||
if (!context.Memory.ContainsKey(SlotName))
|
||||
{
|
||||
Status = "Slot not found";
|
||||
Result = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var first = context.ActiveImage;
|
||||
var second = context.Memory[SlotName];
|
||||
|
||||
context.ActiveImage = new HawkeyeImage()
|
||||
{
|
||||
ImageData = first.ImageData - second.ImageData
|
||||
};
|
||||
|
||||
Result = true;
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections;
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class TakeBiggestOperation : BaseOperation
|
||||
{
|
||||
public TakeBiggestOperation()
|
||||
{
|
||||
CanHaveProcessingError = false;
|
||||
}
|
||||
|
||||
protected override void InterpretInternal(Context context)
|
||||
{
|
||||
if (!CheckImageExists(context)) return;
|
||||
if (!CheckGrayscale(context)) return;
|
||||
|
||||
var image = context.ActiveImage!.ImageData;
|
||||
|
||||
Cv2.FindContours(image, out var contours, out var hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
|
||||
|
||||
if (contours.Length == 0)
|
||||
{
|
||||
SetError("No blobs found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var largestContour = contours.OrderByDescending(c => Cv2.ContourArea(c)).First();
|
||||
var mask = Mat.Zeros(image.Size(), MatType.CV_8UC1).ToMat();
|
||||
|
||||
Cv2.DrawContours(mask, new[] {largestContour}, -1, 255, -1);
|
||||
|
||||
context.ActiveImage = new HawkeyeImage()
|
||||
{
|
||||
ImageData = mask
|
||||
};
|
||||
|
||||
Status = "Biggest blob extracted";
|
||||
Result = true;
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Operations.Morphology;
|
||||
|
||||
[Category("Morphology")]
|
||||
public class UnionOperation : BaseOperation
|
||||
{
|
||||
public string SlotName { get; set; } = "Image";
|
||||
|
||||
public UnionOperation()
|
||||
{
|
||||
CanHaveProcessingError = false;
|
||||
}
|
||||
|
||||
protected override void InterpretInternal(Context context)
|
||||
{
|
||||
if (!CheckImageExists(context)) return;
|
||||
if (!CheckGrayscale(context)) return;
|
||||
|
||||
if (!context.Memory.ContainsKey(SlotName))
|
||||
{
|
||||
Status = "Slot not found";
|
||||
Result = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var first = context.ActiveImage;
|
||||
var second = context.Memory[SlotName];
|
||||
|
||||
context.ActiveImage = new HawkeyeImage()
|
||||
{
|
||||
ImageData = first.ImageData.BitwiseOr(second.ImageData)
|
||||
};
|
||||
|
||||
|
||||
|
||||
Result = true;
|
||||
}
|
||||
|
||||
public override void Save(BinaryWriter bw)
|
||||
{
|
||||
base.Save(bw);
|
||||
}
|
||||
|
||||
public override void Load(BinaryReader br)
|
||||
{
|
||||
base.Load(br);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user