2026-01-26 18:56:53 +09:00

62 lines
1.8 KiB
C#

using VisionCommon;
using Hermes;
using Newtonsoft.Json;
using System;
using System.IO;
namespace MilPattern {
public class BrightnessParamExt : ICloneable {
private const string FILE_NAME = "BrightnessParamExt.json";
public double AvgLow { get; set; } = 0;
public double AvgHigh { get; set; } = 0;
public ROI FindROI { get; set; } = new ROI();
public BrightnessParamExt() {
}
public BrightnessParamExt(ROI findRoi) {
FindROI = findRoi.Clone() as ROI;
}
public object Clone() {
return new BrightnessParamExt() {
AvgLow = AvgLow,
AvgHigh = AvgHigh,
FindROI = FindROI.Clone() as ROI
};
}
internal static BrightnessParamExt Load(string dirPath) {
string filePath = Path.Combine(dirPath, FILE_NAME);
if (File.Exists(filePath)) {
return JsonConvert.DeserializeObject(
File.ReadAllText(filePath), typeof(BrightnessParamExt)) as BrightnessParamExt;
}
return new BrightnessParamExt();
}
internal static int Save(string dirPath, BrightnessParamExt brightnessParamExt) {
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, brightnessParamExt);
}
return E1.OK;
}
}
}