2026-06-05 13:44:39 +09:00

62 lines
1.7 KiB
C#

using VisionCommon;
using Hermes;
using Newtonsoft.Json;
using System;
using System.IO;
namespace MilPattern {
public class BlobParamExt : ICloneable {
private const string FILE_NAME = "BlobParamExt.json";
public double AreaLow { get; set; } = 0;
public double AreaHigh { get; set; } = 0;
public ROI FindROI { get; set; } = new ROI();
public BlobParamExt() {
}
public BlobParamExt(ROI findRoi) {
FindROI = findRoi.Clone() as ROI;
}
public object Clone() {
return new BlobParamExt() {
AreaLow = AreaLow,
AreaHigh = AreaHigh,
FindROI = FindROI.Clone() as ROI
};
}
internal static BlobParamExt Load(string dirPath) {
string filePath = Path.Combine(dirPath, FILE_NAME);
if (File.Exists(filePath)) {
return JsonConvert.DeserializeObject(
File.ReadAllText(filePath), typeof(BlobParamExt)) as BlobParamExt;
}
return new BlobParamExt();
}
internal static int Save(string dirPath, BlobParamExt blobParamExt) {
string filePath = Path.Combine(dirPath, FILE_NAME);
if (!Directory.Exists(dirPath)) {
Directory.CreateDirectory(dirPath);
}
using (var fs = File.Create(filePath))
using (var sw = new StreamWriter(fs))
using (var jtw = new JsonTextWriter(sw) {
Formatting = Formatting.Indented,
Indentation = 2,
}) {
(new JsonSerializer()).Serialize(jtw, blobParamExt);
}
return E1.OK;
}
}
}