hawkeye camera support(not tested)
This commit is contained in:
14
Hawkeye.VisionBuilder.Workflow/.claude/settings.local.json
Normal file
14
Hawkeye.VisionBuilder.Workflow/.claude/settings.local.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(find:*)",
|
||||
"Bash(for file in UnionOperation.cs HatsOperation.cs OpeningOperation.cs DilationOperation.cs ClosingOperation.cs)",
|
||||
"Bash(do echo \"=== $file ===\")",
|
||||
"Bash(tail:*)",
|
||||
"Bash(done)",
|
||||
"Bash(dotnet build:*)",
|
||||
"Bash(ls:*)"
|
||||
],
|
||||
"deny": []
|
||||
}
|
||||
}
|
||||
@@ -90,8 +90,9 @@ namespace Hawkeye.VisionBuilder.Workflow
|
||||
{
|
||||
return Regex.Replace(typeName.Replace("Operation", ""), "(\\B[A-Z]+?(?=[A-Z][^A-Z])|\\B[A-Z]+?(?=[^A-Z]))", (useSpaces?" ":"")+"$1");
|
||||
}
|
||||
|
||||
[NotForTool]
|
||||
public bool Result { get; set; } = true;
|
||||
[NotForTool]
|
||||
public string ResultString
|
||||
{
|
||||
get
|
||||
@@ -104,7 +105,12 @@ namespace Hawkeye.VisionBuilder.Workflow
|
||||
[NotForTool]
|
||||
public string Label { get; set; }
|
||||
|
||||
[NotForTool]
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
[NotForTool]
|
||||
public TimeSpan ExecutionTime { get; set; }
|
||||
[NotForTool]
|
||||
public string ExecutionTimeString
|
||||
{
|
||||
get
|
||||
@@ -132,7 +138,7 @@ namespace Hawkeye.VisionBuilder.Workflow
|
||||
public Dictionary<string, object> GetParameters()
|
||||
{
|
||||
|
||||
var props = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
|
||||
var props = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(x=>!x.HasAttribute(typeof(NotForToolAttribute)));
|
||||
return props.ToDictionary(x => x.Name, x => x.GetValue(this)!);
|
||||
}
|
||||
@@ -142,7 +148,7 @@ namespace Hawkeye.VisionBuilder.Workflow
|
||||
foreach (KeyValuePair<string, object> pair in parameters)
|
||||
{
|
||||
this.GetType().GetProperty(pair.Key,
|
||||
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
|
||||
BindingFlags.Public | BindingFlags.Instance )
|
||||
?.SetValue(this,pair.Value);
|
||||
}
|
||||
}
|
||||
@@ -275,6 +281,23 @@ namespace Hawkeye.VisionBuilder.Workflow
|
||||
Label = br.ReadString();
|
||||
}
|
||||
|
||||
public virtual void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
dict[nameof(Id)] = Id.ToString();
|
||||
dict[nameof(Label)] = Label;
|
||||
dict[nameof(Enabled)] = Enabled;
|
||||
}
|
||||
|
||||
public virtual void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
if (dict.ContainsKey(nameof(Id)))
|
||||
Id = new Guid(dict[nameof(Id)].ToString());
|
||||
if (dict.ContainsKey(nameof(Label)))
|
||||
Label = dict[nameof(Label)].ToString();
|
||||
if (dict.ContainsKey(nameof(Enabled)))
|
||||
Enabled = Convert.ToBoolean(dict[nameof(Enabled)]);
|
||||
}
|
||||
|
||||
public void SetError(string eMessage)
|
||||
{
|
||||
Status=eMessage;
|
||||
|
||||
@@ -9,6 +9,7 @@ public class BaseOperationDecorator
|
||||
_baseOperation = baseOperation;
|
||||
}
|
||||
|
||||
|
||||
public bool Result => Operation.Result;
|
||||
public string ResultString => Operation.ToString();
|
||||
public string TypeName => Operation.TypeName;
|
||||
@@ -21,4 +22,10 @@ public class BaseOperationDecorator
|
||||
public string ExecutionTimeString => Operation.ExecutionTimeString;
|
||||
|
||||
public BaseOperation Operation => _baseOperation;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _baseOperation.Enabled;
|
||||
set => _baseOperation.Enabled = value;
|
||||
}
|
||||
}
|
||||
@@ -122,4 +122,17 @@ public class AnomalyAI: BaseOperation
|
||||
_modelFilePath.Format = br.ReadString();
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -181,4 +181,54 @@ public class ArrayModelMatchingOperation:BaseOperation
|
||||
SearchArea.Load(br);
|
||||
ReloadModelInfo();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ReferenceId)] = ReferenceId.ToString();
|
||||
dict[nameof(Margin)] = Margin;
|
||||
dict[nameof(Amount)] = Amount;
|
||||
dict[nameof(ModelName)] = ModelName;
|
||||
|
||||
// Save ArrayHorizontalElement SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_BlockSizeX"] = SearchArea.BlockSize.X;
|
||||
dict["SearchArea_BlockSizeY"] = SearchArea.BlockSize.Y;
|
||||
dict["SearchArea_BlockCount"] = SearchArea.BlockCount;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ReferenceId)))
|
||||
ReferenceId = new Guid(dict[nameof(ReferenceId)].ToString());
|
||||
if (dict.ContainsKey(nameof(Margin)))
|
||||
Margin = Convert.ToInt32(dict[nameof(Margin)]);
|
||||
if (dict.ContainsKey(nameof(Amount)))
|
||||
Amount = Convert.ToInt32(dict[nameof(Amount)]);
|
||||
if (dict.ContainsKey(nameof(ModelName)))
|
||||
ModelName = dict[nameof(ModelName)].ToString();
|
||||
|
||||
// Load ArrayHorizontalElement SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable") || dict.ContainsKey("SearchArea_LocationX") || dict.ContainsKey("SearchArea_BlockSizeX"))
|
||||
{
|
||||
SearchArea = new ArrayHorizontalElement();
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_BlockSizeX") && dict.ContainsKey("SearchArea_BlockSizeY"))
|
||||
SearchArea.BlockSize = new Vector2(Convert.ToSingle(dict["SearchArea_BlockSizeX"]), Convert.ToSingle(dict["SearchArea_BlockSizeY"]));
|
||||
if (dict.ContainsKey("SearchArea_BlockCount"))
|
||||
SearchArea.BlockCount = Convert.ToInt32(dict["SearchArea_BlockCount"]);
|
||||
}
|
||||
|
||||
ReloadModelInfo();
|
||||
}
|
||||
}
|
||||
@@ -120,5 +120,18 @@ public class BackgroundSeparationModelOperation:BaseOperation,IHaveOrigin
|
||||
ModelName = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ModelName)] = ModelName;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ModelName)))
|
||||
ModelName = dict[nameof(ModelName)].ToString();
|
||||
}
|
||||
|
||||
public OriginElement Origin { get; set; }
|
||||
}
|
||||
@@ -30,4 +30,20 @@ public class Color128BinaryOperation:ColorAIOperation
|
||||
FilterClasses = br.ReadString();
|
||||
ModelFilePath.Path = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(FilterClasses)] = FilterClasses;
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(FilterClasses)))
|
||||
FilterClasses = dict[nameof(FilterClasses)].ToString();
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -110,4 +110,20 @@ public class Color128HalfOperation:BaseOperation
|
||||
FilterClasses = br.ReadString();
|
||||
ModelFilePath.Path = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(FilterClasses)] = FilterClasses;
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(FilterClasses)))
|
||||
FilterClasses = dict[nameof(FilterClasses)].ToString();
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -33,4 +33,20 @@ public class Color128SimpleOperation: ColorAIOperation
|
||||
FilterClasses = br.ReadString();
|
||||
ModelFilePath.Path = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(FilterClasses)] = FilterClasses;
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(FilterClasses)))
|
||||
FilterClasses = dict[nameof(FilterClasses)].ToString();
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,27 @@ public class ColorModelOperation : ColorAIOperation
|
||||
var absPath = Path.GetFullPath(Path.Combine(dir, ModelFilePath.Path));
|
||||
ModelFilePath.Path = absPath;
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(FilterClasses)] = FilterClasses;
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(FilterClasses)))
|
||||
FilterClasses = dict[nameof(FilterClasses)].ToString();
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
{
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
// get current directory
|
||||
var dir = Directory.GetCurrentDirectory();
|
||||
// get absolute path
|
||||
var absPath = Path.GetFullPath(Path.Combine(dir, ModelFilePath.Path));
|
||||
ModelFilePath.Path = absPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,4 +156,23 @@ public class ModelAIOperation: BaseOperation
|
||||
FilterClasses = br.ReadString();
|
||||
IsCategorical = br.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
dict[nameof(FilterClasses)] = FilterClasses;
|
||||
dict[nameof(IsCategorical)] = IsCategorical;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
if (dict.ContainsKey(nameof(FilterClasses)))
|
||||
FilterClasses = dict[nameof(FilterClasses)].ToString();
|
||||
if (dict.ContainsKey(nameof(IsCategorical)))
|
||||
IsCategorical = Convert.ToBoolean(dict[nameof(IsCategorical)]);
|
||||
}
|
||||
}
|
||||
@@ -145,4 +145,17 @@ public class MultichannelAI: BaseOperation
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -147,4 +147,23 @@ public class RawModelAIOperation: BaseOperation
|
||||
FilterClasses = br.ReadString();
|
||||
IsCategorical = br.ReadBoolean();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
dict[nameof(FilterClasses)] = FilterClasses;
|
||||
dict[nameof(IsCategorical)] = IsCategorical;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
if (dict.ContainsKey(nameof(FilterClasses)))
|
||||
FilterClasses = dict[nameof(FilterClasses)].ToString();
|
||||
if (dict.ContainsKey(nameof(IsCategorical)))
|
||||
IsCategorical = Convert.ToBoolean(dict[nameof(IsCategorical)]);
|
||||
}
|
||||
}
|
||||
@@ -139,4 +139,17 @@ public class YoloDetectionOperation:BaseOperation
|
||||
base.Load(br);
|
||||
ModelFilePath.Path = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ModelFilePath)] = ModelFilePath.Path;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ModelFilePath)))
|
||||
ModelFilePath.Path = dict[nameof(ModelFilePath)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -112,4 +112,38 @@ public class YoloPickDetected:BaseOperation
|
||||
MinArea = br.ReadInt32();
|
||||
MaxArea = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(SlotName)] = SlotName;
|
||||
dict[nameof(TypeId)] = TypeId;
|
||||
dict[nameof(MinWidth)] = MinWidth;
|
||||
dict[nameof(MaxWidth)] = MaxWidth;
|
||||
dict[nameof(MinHeight)] = MinHeight;
|
||||
dict[nameof(MaxHeight)] = MaxHeight;
|
||||
dict[nameof(MinArea)] = MinArea;
|
||||
dict[nameof(MaxArea)] = MaxArea;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(SlotName)))
|
||||
SlotName = dict[nameof(SlotName)].ToString();
|
||||
if (dict.ContainsKey(nameof(TypeId)))
|
||||
TypeId = Convert.ToInt32(dict[nameof(TypeId)]);
|
||||
if (dict.ContainsKey(nameof(MinWidth)))
|
||||
MinWidth = Convert.ToInt32(dict[nameof(MinWidth)]);
|
||||
if (dict.ContainsKey(nameof(MaxWidth)))
|
||||
MaxWidth = Convert.ToInt32(dict[nameof(MaxWidth)]);
|
||||
if (dict.ContainsKey(nameof(MinHeight)))
|
||||
MinHeight = Convert.ToInt32(dict[nameof(MinHeight)]);
|
||||
if (dict.ContainsKey(nameof(MaxHeight)))
|
||||
MaxHeight = Convert.ToInt32(dict[nameof(MaxHeight)]);
|
||||
if (dict.ContainsKey(nameof(MinArea)))
|
||||
MinArea = Convert.ToInt32(dict[nameof(MinArea)]);
|
||||
if (dict.ContainsKey(nameof(MaxArea)))
|
||||
MaxArea = Convert.ToInt32(dict[nameof(MaxArea)]);
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,20 @@ public class CannyOperation:BaseOperation
|
||||
Threshold1 = br.ReadInt32();
|
||||
Threshold2 = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Threshold1)] = Threshold1;
|
||||
dict[nameof(Threshold2)] = Threshold2;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Threshold1)))
|
||||
Threshold1 = Convert.ToInt32(dict[nameof(Threshold1)]);
|
||||
if (dict.ContainsKey(nameof(Threshold2)))
|
||||
Threshold2 = Convert.ToInt32(dict[nameof(Threshold2)]);
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,20 @@ public class DetectionPaddingOperation:BaseOperation
|
||||
HorizontalPadding = br.ReadInt32();
|
||||
VerticalPadding = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(HorizontalPadding)] = HorizontalPadding;
|
||||
dict[nameof(VerticalPadding)] = VerticalPadding;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(HorizontalPadding)))
|
||||
HorizontalPadding = Convert.ToInt32(dict[nameof(HorizontalPadding)]);
|
||||
if (dict.ContainsKey(nameof(VerticalPadding)))
|
||||
VerticalPadding = Convert.ToInt32(dict[nameof(VerticalPadding)]);
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,17 @@ public class GaussianBlurOperation : BaseOperation
|
||||
KernelSize.Script = br.ReadString();
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(KernelSize)] = KernelSize.Script;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(KernelSize)))
|
||||
KernelSize.Script = dict[nameof(KernelSize)].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,29 @@ public class PorabollisticHoughOperation:BaseOperation
|
||||
MinLineLength = br.ReadInt32();
|
||||
MaxLineGap = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(DistanceResolution)] = DistanceResolution;
|
||||
dict[nameof(AngleResolution)] = AngleResolution;
|
||||
dict[nameof(Threshold)] = Threshold;
|
||||
dict[nameof(MinLineLength)] = MinLineLength;
|
||||
dict[nameof(MaxLineGap)] = MaxLineGap;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(DistanceResolution)))
|
||||
DistanceResolution = Convert.ToDouble(dict[nameof(DistanceResolution)]);
|
||||
if (dict.ContainsKey(nameof(AngleResolution)))
|
||||
AngleResolution = Convert.ToDouble(dict[nameof(AngleResolution)]);
|
||||
if (dict.ContainsKey(nameof(Threshold)))
|
||||
Threshold = Convert.ToInt32(dict[nameof(Threshold)]);
|
||||
if (dict.ContainsKey(nameof(MinLineLength)))
|
||||
MinLineLength = Convert.ToInt32(dict[nameof(MinLineLength)]);
|
||||
if (dict.ContainsKey(nameof(MaxLineGap)))
|
||||
MaxLineGap = Convert.ToInt32(dict[nameof(MaxLineGap)]);
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,20 @@ public class ThresholdMinMaxOperation : BaseOperation
|
||||
ThresholdMin.Script = br.ReadString();
|
||||
ThresholdMax.Script = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ThresholdMin)] = ThresholdMin.Script;
|
||||
dict[nameof(ThresholdMax)] = ThresholdMax.Script;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ThresholdMin)))
|
||||
ThresholdMin.Script = dict[nameof(ThresholdMin)].ToString();
|
||||
if (dict.ContainsKey(nameof(ThresholdMax)))
|
||||
ThresholdMax.Script = dict[nameof(ThresholdMax)].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,17 @@ public class ThresholdOperation:BaseOperation
|
||||
ThresholdMin.Script = br.ReadString();
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ThresholdMin)] = ThresholdMin.Script;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ThresholdMin)))
|
||||
ThresholdMin.Script = dict[nameof(ThresholdMin)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,23 @@ public class ColorProfileOperation:BaseOperation
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ColorProfilePath)] = ColorProfilePath.Path;
|
||||
dict[nameof(Category)] = Category.Value;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ColorProfilePath)))
|
||||
ColorProfilePath.Path = EnsureRelativePath(dict[nameof(ColorProfilePath)].ToString());
|
||||
if (dict.ContainsKey(nameof(Category)))
|
||||
Category.Value = dict[nameof(Category)].ToString();
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
string EnsureRelativePath(string path)
|
||||
{
|
||||
if (path.StartsWith(".."))
|
||||
|
||||
@@ -94,4 +94,35 @@ public class GaborFilterOperation : BaseOperation
|
||||
ThetaToAngle = br.ReadDouble();
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(KSize)] = KSize;
|
||||
dict[nameof(Sigma)] = Sigma;
|
||||
dict[nameof(NumFilters)] = NumFilters;
|
||||
dict[nameof(Lambda)] = Lambda;
|
||||
dict[nameof(Gamma)] = Gamma;
|
||||
dict[nameof(ThetaFromAngle)] = ThetaFromAngle;
|
||||
dict[nameof(ThetaToAngle)] = ThetaToAngle;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(KSize)))
|
||||
KSize = Convert.ToInt32(dict[nameof(KSize)]);
|
||||
if (dict.ContainsKey(nameof(Sigma)))
|
||||
Sigma = Convert.ToDouble(dict[nameof(Sigma)]);
|
||||
if (dict.ContainsKey(nameof(NumFilters)))
|
||||
NumFilters = Convert.ToInt32(dict[nameof(NumFilters)]);
|
||||
if (dict.ContainsKey(nameof(Lambda)))
|
||||
Lambda = Convert.ToDouble(dict[nameof(Lambda)]);
|
||||
if (dict.ContainsKey(nameof(Gamma)))
|
||||
Gamma = Convert.ToDouble(dict[nameof(Gamma)]);
|
||||
if (dict.ContainsKey(nameof(ThetaFromAngle)))
|
||||
ThetaFromAngle = Convert.ToDouble(dict[nameof(ThetaFromAngle)]);
|
||||
if (dict.ContainsKey(nameof(ThetaToAngle)))
|
||||
ThetaToAngle = Convert.ToDouble(dict[nameof(ThetaToAngle)]);
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,27 @@ public class LUTFilterOperation : BaseOperation
|
||||
base.Load(br);
|
||||
LutData.Deserialize(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
// Save LutData as serialized representation
|
||||
using var ms = new MemoryStream();
|
||||
using var bw = new BinaryWriter(ms);
|
||||
LutData.Serialize(bw);
|
||||
dict[nameof(LutData)] = Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(LutData)))
|
||||
{
|
||||
var base64Data = dict[nameof(LutData)].ToString();
|
||||
var bytes = Convert.FromBase64String(base64Data);
|
||||
using var ms = new MemoryStream(bytes);
|
||||
using var br = new BinaryReader(ms);
|
||||
LutData.Deserialize(br);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,4 +38,17 @@ public class NoiseFilterOperation:BaseOperation
|
||||
base.Load(br);
|
||||
NoiseSize = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(NoiseSize)] = NoiseSize;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(NoiseSize)))
|
||||
NoiseSize = Convert.ToInt32(dict[nameof(NoiseSize)]);
|
||||
}
|
||||
}
|
||||
@@ -51,5 +51,33 @@ public class RangeFilterOperation: BaseOperation
|
||||
C3Max = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(C1Min)] = C1Min;
|
||||
dict[nameof(C1Max)] = C1Max;
|
||||
dict[nameof(C2Min)] = C2Min;
|
||||
dict[nameof(C2Max)] = C2Max;
|
||||
dict[nameof(C3Min)] = C3Min;
|
||||
dict[nameof(C3Max)] = C3Max;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(C1Min)))
|
||||
C1Min = Convert.ToInt32(dict[nameof(C1Min)]);
|
||||
if (dict.ContainsKey(nameof(C1Max)))
|
||||
C1Max = Convert.ToInt32(dict[nameof(C1Max)]);
|
||||
if (dict.ContainsKey(nameof(C2Min)))
|
||||
C2Min = Convert.ToInt32(dict[nameof(C2Min)]);
|
||||
if (dict.ContainsKey(nameof(C2Max)))
|
||||
C2Max = Convert.ToInt32(dict[nameof(C2Max)]);
|
||||
if (dict.ContainsKey(nameof(C3Min)))
|
||||
C3Min = Convert.ToInt32(dict[nameof(C3Min)]);
|
||||
if (dict.ContainsKey(nameof(C3Max)))
|
||||
C3Max = Convert.ToInt32(dict[nameof(C3Max)]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -68,4 +68,22 @@ public class GetImageOperation:BaseOperation,IHaveImage
|
||||
Id = new Guid(br.ReadString());
|
||||
Label = br.ReadString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the operation to the dictionary
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the operation from the dictionary
|
||||
/// </summary>
|
||||
/// <param name="dict"></param>
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
}
|
||||
}
|
||||
@@ -35,4 +35,17 @@ public class GetChannelOperation: BaseOperation
|
||||
base.Load(br);
|
||||
Channel = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Channel)] = Channel;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Channel)))
|
||||
Channel = Convert.ToInt32(dict[nameof(Channel)]);
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,20 @@ public class ImageSizeProportionOperation:BaseOperation
|
||||
Width = br.ReadDouble();
|
||||
Height = br.ReadDouble();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Width)] = Width;
|
||||
dict[nameof(Height)] = Height;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Width)))
|
||||
Width = Convert.ToDouble(dict[nameof(Width)]);
|
||||
if (dict.ContainsKey(nameof(Height)))
|
||||
Height = Convert.ToDouble(dict[nameof(Height)]);
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,17 @@ public class ImageFromMemoryOperation:BaseOperation
|
||||
base.Load(br);
|
||||
SlotName = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(SlotName)] = SlotName;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(SlotName)))
|
||||
SlotName = dict[nameof(SlotName)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -33,4 +33,17 @@ public class ImageToMemoryOperation:BaseOperation
|
||||
base.Load(br);
|
||||
SlotName = br.ReadString();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(SlotName)] = SlotName;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(SlotName)))
|
||||
SlotName = dict[nameof(SlotName)].ToString();
|
||||
}
|
||||
}
|
||||
@@ -40,4 +40,17 @@ public class ClosingOperation:BaseOperation
|
||||
base.Load(br);
|
||||
Closing = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Closing)] = Closing;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Closing)))
|
||||
Closing = Convert.ToInt32(dict[nameof(Closing)]);
|
||||
}
|
||||
}
|
||||
@@ -80,4 +80,43 @@ public class CutOperation:BaseOperation
|
||||
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ReferencePoint)] = ReferencePoint.ToString();
|
||||
|
||||
// Save SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_IsGood"] = SearchArea.IsGood;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_SizeX"] = SearchArea.Size.X;
|
||||
dict["SearchArea_SizeY"] = SearchArea.Size.Y;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ReferencePoint)))
|
||||
ReferencePoint = new Guid(dict[nameof(ReferencePoint)].ToString());
|
||||
|
||||
// Load SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable") || dict.ContainsKey("SearchArea_IsGood") || dict.ContainsKey("SearchArea_LocationX"))
|
||||
{
|
||||
SearchArea = new RectangleElement();
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_IsGood"))
|
||||
SearchArea.IsGood = Convert.ToBoolean(dict["SearchArea_IsGood"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_SizeX") && dict.ContainsKey("SearchArea_SizeY"))
|
||||
SearchArea.Size = new Vector2(Convert.ToSingle(dict["SearchArea_SizeX"]), Convert.ToSingle(dict["SearchArea_SizeY"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,17 @@ public class DilationOperation:BaseOperation
|
||||
base.Load(br);
|
||||
Dilation = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Dilation)] = Dilation;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Dilation)))
|
||||
Dilation = Convert.ToInt32(dict[nameof(Dilation)]);
|
||||
}
|
||||
}
|
||||
@@ -40,4 +40,17 @@ public class HatsOperation : BaseOperation
|
||||
base.Load(br);
|
||||
HatSize = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(HatSize)] = HatSize;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(HatSize)))
|
||||
HatSize = Convert.ToInt32(dict[nameof(HatSize)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,4 +40,17 @@ public class OpeningOperation : BaseOperation
|
||||
base.Load(br);
|
||||
Opening = br.ReadInt32();
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Opening)] = Opening;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Opening)))
|
||||
Opening = Convert.ToInt32(dict[nameof(Opening)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,4 +45,14 @@ public class SubtractOperation : BaseOperation
|
||||
{
|
||||
base.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,14 @@ public class TakeBiggestOperation : BaseOperation
|
||||
{
|
||||
base.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,14 @@ public class UnionOperation : BaseOperation
|
||||
{
|
||||
base.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,4 +155,54 @@ public class FindBlobOperation : BaseOperation, IHaveOrigin, IHaveSearchArea
|
||||
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(MinArea)] = MinArea;
|
||||
dict[nameof(MaxArea)] = MaxArea;
|
||||
dict[nameof(MinRadius)] = MinRadius;
|
||||
dict[nameof(MaxRadius)] = MaxRadius;
|
||||
dict[nameof(BadIfFound)] = BadIfFound;
|
||||
dict[nameof(ReferenceId)] = ReferenceId.ToString();
|
||||
|
||||
// Save SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_IsGood"] = SearchArea.IsGood;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_SizeX"] = SearchArea.Size.X;
|
||||
dict["SearchArea_SizeY"] = SearchArea.Size.Y;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(MinArea)))
|
||||
MinArea = Convert.ToInt32(dict[nameof(MinArea)]);
|
||||
if (dict.ContainsKey(nameof(MaxArea)))
|
||||
MaxArea = Convert.ToInt32(dict[nameof(MaxArea)]);
|
||||
if (dict.ContainsKey(nameof(MinRadius)))
|
||||
MinRadius = Convert.ToInt32(dict[nameof(MinRadius)]);
|
||||
if (dict.ContainsKey(nameof(MaxRadius)))
|
||||
MaxRadius = Convert.ToInt32(dict[nameof(MaxRadius)]);
|
||||
if (dict.ContainsKey(nameof(BadIfFound)))
|
||||
BadIfFound = Convert.ToBoolean(dict[nameof(BadIfFound)]);
|
||||
if (dict.ContainsKey(nameof(ReferenceId)))
|
||||
ReferenceId = new Guid(dict[nameof(ReferenceId)].ToString());
|
||||
|
||||
// Load SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_IsGood"))
|
||||
SearchArea.IsGood = Convert.ToBoolean(dict["SearchArea_IsGood"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_SizeX") && dict.ContainsKey("SearchArea_SizeY"))
|
||||
SearchArea.Size = new Vector2(Convert.ToSingle(dict["SearchArea_SizeX"]), Convert.ToSingle(dict["SearchArea_SizeY"]));
|
||||
}
|
||||
}
|
||||
@@ -230,4 +230,78 @@ public class FindManyBlobsExtOperation : BaseOperation
|
||||
ReferenceId = new Guid(br.ReadString());
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(MinArea)] = MinArea;
|
||||
dict[nameof(MaxArea)] = MaxArea;
|
||||
dict[nameof(MinRadius)] = MinRadius;
|
||||
dict[nameof(MaxRadius)] = MaxRadius;
|
||||
dict[nameof(CheckInternalRadius)] = CheckInternalRadius;
|
||||
dict[nameof(MinInternalRadius)] = MinInternalRadius;
|
||||
dict[nameof(MaxInternalRadius)] = MaxInternalRadius;
|
||||
dict[nameof(CheckWidth)] = CheckWidth;
|
||||
dict[nameof(MinWidth)] = MinWidth;
|
||||
dict[nameof(MaxWidth)] = MaxWidth;
|
||||
dict[nameof(CheckHeight)] = CheckHeight;
|
||||
dict[nameof(MinHeight)] = MinHeight;
|
||||
dict[nameof(MaxHeight)] = MaxHeight;
|
||||
dict[nameof(ReferenceId)] = ReferenceId.ToString();
|
||||
|
||||
// Save SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_IsGood"] = SearchArea.IsGood;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_SizeX"] = SearchArea.Size.X;
|
||||
dict["SearchArea_SizeY"] = SearchArea.Size.Y;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(MinArea)))
|
||||
MinArea = Convert.ToInt32(dict[nameof(MinArea)]);
|
||||
if (dict.ContainsKey(nameof(MaxArea)))
|
||||
MaxArea = Convert.ToInt32(dict[nameof(MaxArea)]);
|
||||
if (dict.ContainsKey(nameof(MinRadius)))
|
||||
MinRadius = Convert.ToInt32(dict[nameof(MinRadius)]);
|
||||
if (dict.ContainsKey(nameof(MaxRadius)))
|
||||
MaxRadius = Convert.ToInt32(dict[nameof(MaxRadius)]);
|
||||
if (dict.ContainsKey(nameof(CheckInternalRadius)))
|
||||
CheckInternalRadius = Convert.ToBoolean(dict[nameof(CheckInternalRadius)]);
|
||||
if (dict.ContainsKey(nameof(MinInternalRadius)))
|
||||
MinInternalRadius = Convert.ToInt32(dict[nameof(MinInternalRadius)]);
|
||||
if (dict.ContainsKey(nameof(MaxInternalRadius)))
|
||||
MaxInternalRadius = Convert.ToInt32(dict[nameof(MaxInternalRadius)]);
|
||||
if (dict.ContainsKey(nameof(CheckWidth)))
|
||||
CheckWidth = Convert.ToBoolean(dict[nameof(CheckWidth)]);
|
||||
if (dict.ContainsKey(nameof(MinWidth)))
|
||||
MinWidth = Convert.ToInt32(dict[nameof(MinWidth)]);
|
||||
if (dict.ContainsKey(nameof(MaxWidth)))
|
||||
MaxWidth = Convert.ToInt32(dict[nameof(MaxWidth)]);
|
||||
if (dict.ContainsKey(nameof(CheckHeight)))
|
||||
CheckHeight = Convert.ToBoolean(dict[nameof(CheckHeight)]);
|
||||
if (dict.ContainsKey(nameof(MinHeight)))
|
||||
MinHeight = Convert.ToInt32(dict[nameof(MinHeight)]);
|
||||
if (dict.ContainsKey(nameof(MaxHeight)))
|
||||
MaxHeight = Convert.ToInt32(dict[nameof(MaxHeight)]);
|
||||
if (dict.ContainsKey(nameof(ReferenceId)))
|
||||
ReferenceId = new Guid(dict[nameof(ReferenceId)].ToString());
|
||||
|
||||
// Load SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_IsGood"))
|
||||
SearchArea.IsGood = Convert.ToBoolean(dict["SearchArea_IsGood"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_SizeX") && dict.ContainsKey("SearchArea_SizeY"))
|
||||
SearchArea.Size = new Vector2(Convert.ToSingle(dict["SearchArea_SizeX"]), Convert.ToSingle(dict["SearchArea_SizeY"]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,4 +172,51 @@ public class FindManyBlobsOperation:BaseOperation
|
||||
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(MinArea)] = MinArea;
|
||||
dict[nameof(MaxArea)] = MaxArea;
|
||||
dict[nameof(MinRadius)] = MinRadius;
|
||||
dict[nameof(MaxRadius)] = MaxRadius;
|
||||
dict[nameof(ReferenceId)] = ReferenceId.ToString();
|
||||
|
||||
// Save SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_IsGood"] = SearchArea.IsGood;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_SizeX"] = SearchArea.Size.X;
|
||||
dict["SearchArea_SizeY"] = SearchArea.Size.Y;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(MinArea)))
|
||||
MinArea = Convert.ToInt32(dict[nameof(MinArea)]);
|
||||
if (dict.ContainsKey(nameof(MaxArea)))
|
||||
MaxArea = Convert.ToInt32(dict[nameof(MaxArea)]);
|
||||
if (dict.ContainsKey(nameof(MinRadius)))
|
||||
MinRadius = Convert.ToInt32(dict[nameof(MinRadius)]);
|
||||
if (dict.ContainsKey(nameof(MaxRadius)))
|
||||
MaxRadius = Convert.ToInt32(dict[nameof(MaxRadius)]);
|
||||
if (dict.ContainsKey(nameof(ReferenceId)))
|
||||
ReferenceId = new Guid(dict[nameof(ReferenceId)].ToString());
|
||||
|
||||
// Load SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_IsGood"))
|
||||
SearchArea.IsGood = Convert.ToBoolean(dict["SearchArea_IsGood"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_SizeX") && dict.ContainsKey("SearchArea_SizeY"))
|
||||
SearchArea.Size = new Vector2(Convert.ToSingle(dict["SearchArea_SizeX"]), Convert.ToSingle(dict["SearchArea_SizeY"]));
|
||||
}
|
||||
}
|
||||
@@ -109,4 +109,54 @@ public class FindRectangleOperation:BaseOperation
|
||||
BadIfFound = br.ReadBoolean();
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(MinWidth)] = MinWidth;
|
||||
dict[nameof(MaxWidth)] = MaxWidth;
|
||||
dict[nameof(MinHeight)] = MinHeight;
|
||||
dict[nameof(MaxHeight)] = MaxHeight;
|
||||
dict[nameof(BadIfFound)] = BadIfFound;
|
||||
dict[nameof(ReferenceId)] = ReferenceId.ToString();
|
||||
|
||||
// Save SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_IsGood"] = SearchArea.IsGood;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_SizeX"] = SearchArea.Size.X;
|
||||
dict["SearchArea_SizeY"] = SearchArea.Size.Y;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(MinWidth)))
|
||||
MinWidth = Convert.ToInt32(dict[nameof(MinWidth)]);
|
||||
if (dict.ContainsKey(nameof(MaxWidth)))
|
||||
MaxWidth = Convert.ToInt32(dict[nameof(MaxWidth)]);
|
||||
if (dict.ContainsKey(nameof(MinHeight)))
|
||||
MinHeight = Convert.ToInt32(dict[nameof(MinHeight)]);
|
||||
if (dict.ContainsKey(nameof(MaxHeight)))
|
||||
MaxHeight = Convert.ToInt32(dict[nameof(MaxHeight)]);
|
||||
if (dict.ContainsKey(nameof(BadIfFound)))
|
||||
BadIfFound = Convert.ToBoolean(dict[nameof(BadIfFound)]);
|
||||
if (dict.ContainsKey(nameof(ReferenceId)))
|
||||
ReferenceId = new Guid(dict[nameof(ReferenceId)].ToString());
|
||||
|
||||
// Load SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_IsGood"))
|
||||
SearchArea.IsGood = Convert.ToBoolean(dict["SearchArea_IsGood"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_SizeX") && dict.ContainsKey("SearchArea_SizeY"))
|
||||
SearchArea.Size = new Vector2(Convert.ToSingle(dict["SearchArea_SizeX"]), Convert.ToSingle(dict["SearchArea_SizeY"]));
|
||||
}
|
||||
}
|
||||
@@ -103,4 +103,23 @@ public class TwoBlobsAlign:BaseOperation,IHaveOrigin
|
||||
DesiredAngle = br.ReadInt32();
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(Reference1)] = Reference1.ToString();
|
||||
dict[nameof(Reference2)] = Reference2.ToString();
|
||||
dict[nameof(DesiredAngle)] = DesiredAngle;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(Reference1)))
|
||||
Reference1 = new Guid(dict[nameof(Reference1)].ToString());
|
||||
if (dict.ContainsKey(nameof(Reference2)))
|
||||
Reference2 = new Guid(dict[nameof(Reference2)].ToString());
|
||||
if (dict.ContainsKey(nameof(DesiredAngle)))
|
||||
DesiredAngle = Convert.ToInt32(dict[nameof(DesiredAngle)]);
|
||||
}
|
||||
}
|
||||
@@ -100,5 +100,21 @@ public class EdgeIntersectionOperation : BaseOperation, IHaveOrigin
|
||||
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ReferenceEdge1)] = ReferenceEdge1.ToString();
|
||||
dict[nameof(ReferenceEdge2)] = ReferenceEdge2.ToString();
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ReferenceEdge1)))
|
||||
ReferenceEdge1 = new Guid(dict[nameof(ReferenceEdge1)].ToString());
|
||||
if (dict.ContainsKey(nameof(ReferenceEdge2)))
|
||||
ReferenceEdge2 = new Guid(dict[nameof(ReferenceEdge2)].ToString());
|
||||
}
|
||||
|
||||
public OriginElement Origin { get; set; } = OriginElement.Default;
|
||||
}
|
||||
@@ -124,6 +124,48 @@ public class FindEdgeOperation : BaseOperation, IHaveEdge, IHaveOrigin
|
||||
SearchArea.Load(br);
|
||||
}
|
||||
|
||||
public override void Save(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Save(dict);
|
||||
dict[nameof(ReferenceId)] = ReferenceId.ToString();
|
||||
|
||||
// Save RotatedRectangleElement SearchArea properties manually
|
||||
dict["SearchArea_Editable"] = SearchArea.Editable;
|
||||
dict["SearchArea_IsGood"] = SearchArea.IsGood;
|
||||
dict["SearchArea_LocationX"] = SearchArea.Location.X;
|
||||
dict["SearchArea_LocationY"] = SearchArea.Location.Y;
|
||||
dict["SearchArea_OffsetX"] = SearchArea.Offset.X;
|
||||
dict["SearchArea_OffsetY"] = SearchArea.Offset.Y;
|
||||
dict["SearchArea_HeightX"] = SearchArea.Height.X;
|
||||
dict["SearchArea_HeightY"] = SearchArea.Height.Y;
|
||||
dict["SearchArea_HalfWidth"] = SearchArea.HalfWidth;
|
||||
}
|
||||
|
||||
public override void Load(Dictionary<string, object> dict)
|
||||
{
|
||||
base.Load(dict);
|
||||
if (dict.ContainsKey(nameof(ReferenceId)))
|
||||
ReferenceId = new Guid(dict[nameof(ReferenceId)].ToString());
|
||||
|
||||
// Load RotatedRectangleElement SearchArea properties manually
|
||||
if (dict.ContainsKey("SearchArea_Editable") || dict.ContainsKey("SearchArea_LocationX") || dict.ContainsKey("SearchArea_HeightX"))
|
||||
{
|
||||
SearchArea = new RotatedRectangleElement();
|
||||
if (dict.ContainsKey("SearchArea_Editable"))
|
||||
SearchArea.Editable = Convert.ToBoolean(dict["SearchArea_Editable"]);
|
||||
if (dict.ContainsKey("SearchArea_IsGood"))
|
||||
SearchArea.IsGood = Convert.ToBoolean(dict["SearchArea_IsGood"]);
|
||||
if (dict.ContainsKey("SearchArea_LocationX") && dict.ContainsKey("SearchArea_LocationY"))
|
||||
SearchArea.Location = new Vector2(Convert.ToSingle(dict["SearchArea_LocationX"]), Convert.ToSingle(dict["SearchArea_LocationY"]));
|
||||
if (dict.ContainsKey("SearchArea_OffsetX") && dict.ContainsKey("SearchArea_OffsetY"))
|
||||
SearchArea.Offset = new Vector2(Convert.ToSingle(dict["SearchArea_OffsetX"]), Convert.ToSingle(dict["SearchArea_OffsetY"]));
|
||||
if (dict.ContainsKey("SearchArea_HeightX") && dict.ContainsKey("SearchArea_HeightY"))
|
||||
SearchArea.Height = new Vector2(Convert.ToSingle(dict["SearchArea_HeightX"]), Convert.ToSingle(dict["SearchArea_HeightY"]));
|
||||
if (dict.ContainsKey("SearchArea_HalfWidth"))
|
||||
SearchArea.HalfWidth = Convert.ToSingle(dict["SearchArea_HalfWidth"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RotatedRectangleElement SearchArea { get; set; }
|
||||
public OriginElement Origin { get; set; }
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.ComponentModel.Design.Serialization;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text.Json;
|
||||
using System.Xml;
|
||||
using VisionBuilder.UI.Common.RecipeProcessing;
|
||||
using Size = OpenCvSharp.Size;
|
||||
@@ -32,6 +33,11 @@ public class WorkflowList
|
||||
long total = 0;
|
||||
foreach (BaseOperation operation in Operations)
|
||||
{
|
||||
if (!operation.Enabled)
|
||||
{
|
||||
operation.Result=true;
|
||||
continue;
|
||||
}
|
||||
if (Context.CancellationToken.IsCancellationRequested) break;
|
||||
operation.Interpret(Context);
|
||||
}
|
||||
@@ -62,6 +68,7 @@ public class WorkflowList
|
||||
UpdateConfigVariables();
|
||||
foreach (BaseOperation operation in Operations)
|
||||
{
|
||||
if(!operation.Enabled)continue;
|
||||
if(operation == op) break;
|
||||
operation.Interpret(Context);
|
||||
}
|
||||
@@ -275,7 +282,194 @@ public class WorkflowList
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, object> ConvertJsonElementsToNatives(Dictionary<string, object> dict)
|
||||
{
|
||||
var result = new Dictionary<string, object>();
|
||||
|
||||
foreach (var kvp in dict)
|
||||
{
|
||||
result[kvp.Key] = ConvertJsonElementToNative(kvp.Value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private object ConvertJsonElementToNative(object value)
|
||||
{
|
||||
if (value is JsonElement element)
|
||||
{
|
||||
return element.ValueKind switch
|
||||
{
|
||||
JsonValueKind.String => element.GetString(),
|
||||
JsonValueKind.Number => element.TryGetInt32(out var intVal) ? intVal :
|
||||
element.TryGetDouble(out var doubleVal) ? doubleVal :
|
||||
element.GetDecimal(),
|
||||
JsonValueKind.True => true,
|
||||
JsonValueKind.False => false,
|
||||
JsonValueKind.Null => null,
|
||||
JsonValueKind.Object => ConvertJsonElementsToNatives(
|
||||
JsonSerializer.Deserialize<Dictionary<string, object>>(element.GetRawText())),
|
||||
JsonValueKind.Array => element.EnumerateArray()
|
||||
.Select(x => ConvertJsonElementToNative(x)).ToArray(),
|
||||
_ => value
|
||||
};
|
||||
}
|
||||
else if (value is Dictionary<string, object> nestedDict)
|
||||
{
|
||||
return ConvertJsonElementsToNatives(nestedDict);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public void SaveJSON(string fileName)
|
||||
{
|
||||
var workflowData = new Dictionary<string, object>();
|
||||
|
||||
// Save Configuration
|
||||
var configData = new Dictionary<string, object>
|
||||
{
|
||||
["RuntimeCameraType"] = Configuration.RuntimeCameraType.ToString(),
|
||||
["DevelopmentCameraType"] = Configuration.DevelopmentCameraType.ToString(),
|
||||
["Outputs"] = Configuration.Outputs.ToString(),
|
||||
["EmulationPath"] = Configuration.EmulationPath,
|
||||
["PythonPath"] = Configuration.PythonPath,
|
||||
["ResultPin"] = Configuration.ResultPin,
|
||||
["SerialPort"] = Configuration.SerialPort,
|
||||
["Delay"] = Configuration.Delay
|
||||
};
|
||||
workflowData["Configuration"] = configData;
|
||||
|
||||
// Save Operations
|
||||
var operationsData = new List<Dictionary<string, object>>();
|
||||
foreach (BaseOperation operation in Operations)
|
||||
{
|
||||
var operationData = new Dictionary<string, object>
|
||||
{
|
||||
["Type"] = operation.GetType().AssemblyQualifiedName
|
||||
};
|
||||
|
||||
var operationDict = new Dictionary<string, object>();
|
||||
operation.Save(operationDict);
|
||||
operationData["Data"] = operationDict;
|
||||
|
||||
operationsData.Add(operationData);
|
||||
}
|
||||
workflowData["Operations"] = operationsData;
|
||||
|
||||
// Save Recipe Image
|
||||
if (RecipeImage == null)
|
||||
{
|
||||
var mat = new Mat(128, 128, MatType.CV_8UC3, Scalar.Gray);
|
||||
var image = mat.ToBytes();
|
||||
workflowData["RecipeImage"] = Convert.ToBase64String(image);
|
||||
}
|
||||
else
|
||||
{
|
||||
var mat = RecipeImage;
|
||||
var image = mat.Resize(new Size(128, 128)).ToBytes();
|
||||
workflowData["RecipeImage"] = Convert.ToBase64String(image);
|
||||
}
|
||||
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
};
|
||||
string jsonString = JsonSerializer.Serialize(workflowData, options);
|
||||
File.WriteAllText(fileName, jsonString);
|
||||
}
|
||||
|
||||
public void LoadJSON(string fileName, OperationDiscoveryService operationDiscoveryService)
|
||||
{
|
||||
string jsonString = File.ReadAllText(fileName);
|
||||
var workflowData = JsonSerializer.Deserialize<Dictionary<string, object>>(jsonString);
|
||||
|
||||
if (workflowData == null) return;
|
||||
|
||||
// Load Configuration
|
||||
if (workflowData.ContainsKey("Configuration"))
|
||||
{
|
||||
var configElement = (JsonElement)workflowData["Configuration"];
|
||||
var configData = JsonSerializer.Deserialize<Dictionary<string, object>>(configElement.GetRawText());
|
||||
|
||||
if (configData != null)
|
||||
{
|
||||
var convertedConfigData = ConvertJsonElementsToNatives(configData);
|
||||
|
||||
if (convertedConfigData.ContainsKey("RuntimeCameraType"))
|
||||
Configuration.RuntimeCameraType = Enum.Parse<ECameraType>(convertedConfigData["RuntimeCameraType"].ToString());
|
||||
if (convertedConfigData.ContainsKey("DevelopmentCameraType"))
|
||||
Configuration.DevelopmentCameraType = Enum.Parse<ECameraType>(convertedConfigData["DevelopmentCameraType"].ToString());
|
||||
if (convertedConfigData.ContainsKey("Outputs"))
|
||||
Configuration.Outputs = Enum.Parse<EOutputs>(convertedConfigData["Outputs"].ToString());
|
||||
if (convertedConfigData.ContainsKey("EmulationPath"))
|
||||
Configuration.EmulationPath = convertedConfigData["EmulationPath"].ToString();
|
||||
if (convertedConfigData.ContainsKey("PythonPath"))
|
||||
Configuration.PythonPath = convertedConfigData["PythonPath"].ToString();
|
||||
if (convertedConfigData.ContainsKey("ResultPin"))
|
||||
Configuration.ResultPin = (int)convertedConfigData["ResultPin"];
|
||||
if (convertedConfigData.ContainsKey("SerialPort"))
|
||||
Configuration.SerialPort = convertedConfigData["SerialPort"].ToString();
|
||||
if (convertedConfigData.ContainsKey("Delay"))
|
||||
Configuration.Delay = (int)convertedConfigData["Delay"];
|
||||
}
|
||||
}
|
||||
|
||||
if (!File.Exists(Configuration.PythonPath))
|
||||
PythonMissing();
|
||||
|
||||
// Load Operations
|
||||
Operations.Clear();
|
||||
if (workflowData.ContainsKey("Operations"))
|
||||
{
|
||||
var operationsElement = (JsonElement)workflowData["Operations"];
|
||||
var operationsArray = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(operationsElement.GetRawText());
|
||||
|
||||
if (operationsArray != null)
|
||||
{
|
||||
foreach (var operationData in operationsArray)
|
||||
{
|
||||
if (operationData.ContainsKey("Type") && operationData.ContainsKey("Data"))
|
||||
{
|
||||
string operationType = operationData["Type"].ToString();
|
||||
var type = Type.GetType(operationType);
|
||||
if (type != null)
|
||||
{
|
||||
BaseOperation operation = operationDiscoveryService.CreateInstance(type);
|
||||
|
||||
var dataElement = (JsonElement)operationData["Data"];
|
||||
var operationDict = JsonSerializer.Deserialize<Dictionary<string, object>>(dataElement.GetRawText());
|
||||
|
||||
if (operationDict != null)
|
||||
{
|
||||
var convertedDict = ConvertJsonElementsToNatives(operationDict);
|
||||
operation.Load(convertedDict);
|
||||
}
|
||||
|
||||
Operations.Add(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load Recipe Image
|
||||
if (workflowData.ContainsKey("RecipeImage"))
|
||||
{
|
||||
string base64Image = workflowData["RecipeImage"].ToString();
|
||||
if (!string.IsNullOrEmpty(base64Image))
|
||||
{
|
||||
byte[] imageData = Convert.FromBase64String(base64Image);
|
||||
RecipeImage = Mat.FromImageData(imageData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WorkflowList LoadJSONFromFile(string fileName)
|
||||
{
|
||||
var workflowList = new WorkflowList();
|
||||
workflowList.LoadJSON(fileName, new OperationDiscoveryService(workflowList));
|
||||
return workflowList;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user