check point

This commit is contained in:
meelstorm
2025-07-14 12:03:59 +02:00
commit d3cb790bd9
431 changed files with 44078 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
[Category("Basic")]
public class CannyOperation:BaseOperation
{
public int Threshold1 { get; set; } = 100;
public int Threshold2 { get; set; } = 200;
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
context.ActiveImage = new HawkeyeImage()
{
ImageData = context.ActiveImage.ImageData.Canny(Threshold1, Threshold2)
};
Status = $"Canny with Threshold1={Threshold1} and Threshold2={Threshold2}";
Result = true;
}
public override void Save(BinaryWriter bw)
{
base.Save(bw);
bw.Write(Threshold1);
bw.Write(Threshold2);
}
public override void Load(BinaryReader br)
{
base.Load(br);
Threshold1 = br.ReadInt32();
Threshold2 = br.ReadInt32();
}
}

View File

@@ -0,0 +1,55 @@
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp;
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
[Category("Basic")]
public class DetectionPaddingOperation:BaseOperation
{
public int HorizontalPadding { get; set; }
public int VerticalPadding { get; set; }
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
if (!CheckGrayscale(context)) return;
// fill edges with black on top and bottom without changing the image size
var image = context.ActiveImage;
var newImage = new Mat(image.ImageData.Rows, image.ImageData.Cols, MatType.CV_8UC1, Scalar.Black);
var mask = new Mat(image.ImageData.Rows, image.ImageData.Cols, MatType.CV_8UC1, Scalar.Black);
var maskRoi = mask[VerticalPadding, image.ImageData.Rows - VerticalPadding, HorizontalPadding, image.ImageData.Cols - HorizontalPadding];
//fill the mask with white
maskRoi.SetTo(Scalar.White);
image.ImageData.CopyTo(newImage, mask);
mask.Dispose();
maskRoi.Dispose();
context.ActiveImage = new HawkeyeImage()
{
ImageData = newImage
};
}
public override void Save(BinaryWriter bw)
{
base.Save(bw);
bw.Write(HorizontalPadding);
bw.Write(VerticalPadding);
}
public override void Load(BinaryReader br)
{
base.Load(br);
HorizontalPadding = br.ReadInt32();
VerticalPadding = br.ReadInt32();
}
}

View File

@@ -0,0 +1,50 @@
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
[Category("Basic")]
public class GaussianBlurOperation : BaseOperation
{
public ScriptValue KernelSize { get; set; } = new ScriptValue() { Script = "3" };
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
var kernelSize = GetScriptValue<int>(KernelSize);
if (kernelSize < 1||IsEven(kernelSize))
{
Status = $"{nameof(KernelSize)} should be more than 0 and be odd number";
Result = false;
return;
}
context.ActiveImage = new HawkeyeImage()
{
ImageData = context.ActiveImage.ImageData.GaussianBlur(new OpenCvSharp.Size(kernelSize, kernelSize), 0, 0)
};
Status = $"Gaussian blur with kernel size {KernelSize}";
Result = true;
}
private bool IsEven(int kernelSize)
{
return kernelSize % 2 == 0;
}
public override void Save(BinaryWriter bw)
{
base.Save(bw);
bw.Write(KernelSize.Script);
}
public override void Load(BinaryReader br)
{
base.Load(br);
KernelSize.Script = br.ReadString();
}
}

View File

@@ -0,0 +1,54 @@
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Line;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp.Extensions;
using Point = OpenCvSharp.Point;
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
[Category("Basic")]
public class PorabollisticHoughOperation:BaseOperation
{
public double DistanceResolution { get; set; } = 1;
public double AngleResolution { get; set; } = Math.PI / 180.0;
public int Threshold { get; set; } = 50;
public int MinLineLength { get; set; } = 50;
public int MaxLineGap { get; set; } = 10;
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
var segments = context.ActiveImage.ImageData.HoughLinesP(DistanceResolution, AngleResolution, Threshold, MinLineLength, MaxLineGap);
foreach (var segment in segments)
{
context.GraphicsElements.Add(new LineElement()
{
Start = new Vector2(segment.P1.X, segment.P1.Y),
End = new Vector2(segment.P2.X, segment.P2.Y)
});
}
Result = true;
}
public override void Save(BinaryWriter bw)
{
base.Save(bw);
bw.Write(DistanceResolution);
bw.Write(AngleResolution);
bw.Write(Threshold);
bw.Write(MinLineLength);
bw.Write(MaxLineGap);
}
public override void Load(BinaryReader br)
{
base.Load(br);
DistanceResolution = br.ReadDouble();
AngleResolution = br.ReadDouble();
Threshold = br.ReadInt32();
MinLineLength = br.ReadInt32();
MaxLineGap = br.ReadInt32();
}
}

View File

@@ -0,0 +1,40 @@
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp;
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
[Category("Basic")]
public class SkeletonOperation:BaseOperation
{
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
if(!CheckGrayscale(context)) return;
var skeleton = new Mat(context.ActiveImage.ImageData.Size(), MatType.CV_8UC1, 0);
var temp = context.ActiveImage.ImageData.Clone();
var element = Cv2.GetStructuringElement(MorphShapes.Cross, new OpenCvSharp.Size(3, 3));
var image = context.ActiveImage.ImageData.Clone();
do
{
var eroded = image.Erode(element);
temp =eroded.Dilate(element);
Cv2.Subtract(image,temp, temp);
Cv2.BitwiseOr(skeleton, temp, skeleton);
eroded.CopyTo(image);
} while (Cv2.CountNonZero(image) != 0);
context.ActiveImage = new HawkeyeImage()
{
ImageData = skeleton
};
Result = true;
}
}

View File

@@ -0,0 +1,47 @@
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
using global::Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp;
[Category("Basic")]
public class ThresholdMinMaxOperation : BaseOperation
{
public ScriptValue ThresholdMin { get; set; } = new ScriptValue() { Script = "128" };
public ScriptValue ThresholdMax { get; set; } = new ScriptValue() { Script = "255" };
public ThresholdMinMaxOperation()
{
CanHaveProcessingError = false;
}
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
if (!CheckGrayscale(context)) return;
context.ActiveImage = new HawkeyeImage()
{
ImageData = context.ActiveImage.ImageData.InRange(GetScriptValue<float>(ThresholdMin), GetScriptValue<float>(ThresholdMax))
};
Result = true;
}
public override void Save(BinaryWriter bw)
{
base.Save(bw);
bw.Write(ThresholdMin.Script);
bw.Write(ThresholdMax.Script);
}
public override void Load(BinaryReader br)
{
base.Load(br);
ThresholdMin.Script = br.ReadString();
ThresholdMax.Script = br.ReadString();
}
}

View File

@@ -0,0 +1,44 @@
using Hawkeye.VisionBuilder.Workflow.Datatypes;
using Hawkeye.VisionBuilder.Workflow.Operations.Attributes;
using OpenCvSharp;
namespace Hawkeye.VisionBuilder.Workflow.Operations.Basic;
[Category("Basic")]
public class ThresholdOperation:BaseOperation
{
public ScriptValue ThresholdMin { get; set; } = new ScriptValue(){Script = "128"};
public ThresholdOperation()
{
CanHaveProcessingError = false;
}
protected override void InterpretInternal(Context context)
{
if (!CheckImageExists(context)) return;
if(!CheckGrayscale(context))return;
context.ActiveImage = new HawkeyeImage()
{
ImageData = context.ActiveImage.ImageData.Threshold(GetScriptValue<float>(ThresholdMin), 255,ThresholdTypes.Binary)
};
Result = true;
}
public override void Save(BinaryWriter bw)
{
base.Save(bw);
bw.Write(ThresholdMin.Script);
}
public override void Load(BinaryReader br)
{
base.Load(br);
ThresholdMin.Script = br.ReadString();
}
}