2026-01-26 14:51:28 +09:00

121 lines
4.3 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using VisionCommon;
using Hermes;
using Newtonsoft.Json;
using System;
using System.IO;
namespace MilPattern {
public class StrReadParamExt : ICloneable {
public bool Enabled { get; set; } = true;
public object Clone() {
return new StrReadParamExt() {
Enabled = this.Enabled,
};
}
}
public class OcrReadParamExt : ICloneable {
public bool Enabled { get; set; } = false;
public object Clone() {
return new OcrReadParamExt() {
Enabled = this.Enabled,
};
}
}
public class TesseractParamExt : ICloneable {
public bool Enabled { get; set; } = false;
public string WhiteList { get; set; } = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "; // 대문자+숫자+공백
public string BlackList { get; set; } = "abcdefghijklmnopqrstuvwxyz!@#$%^&*+=[]{}|;:'\",<>/?"; // 소문자+특수문자
public object Clone() {
return new TesseractParamExt() {
Enabled = this.Enabled,
WhiteList = this.WhiteList,
BlackList = this.BlackList
};
}
}
public class OcrParamExt : ICloneable {
private const string FILE_NAME = "OcrParamExt.json";
public StrReadParamExt StrReadParamExt { get; set; } = new StrReadParamExt();
public OcrReadParamExt OcrReadParamExt { get; set;} = new OcrReadParamExt();
public TesseractParamExt TesseractParamExt { get; set; } = new TesseractParamExt();
public bool NoLengthLimit { get; set; } = true; // 판독할 문자열 길이 제한X
public int CustomTextLength { get; set; } = 10; // 판독할 문자열 길이 (정확한 문자열 길이를 입력해야 정답으로 판정됨.)
public double Acceptance { get; set; } = 70;
public ROI FindROI { get; set; } = new ROI();
public OcrParamExt() {
}
public OcrParamExt(
StrReadParamExt strReadParamExt, OcrReadParamExt ocrReadParamExt, TesseractParamExt tesseractParamExt,
bool noLengthLimit, int customTextLength, double acceptance, ROI findRoi) {
StrReadParamExt = strReadParamExt.Clone() as StrReadParamExt;
OcrReadParamExt = ocrReadParamExt.Clone() as OcrReadParamExt;
TesseractParamExt = tesseractParamExt.Clone() as TesseractParamExt;
NoLengthLimit = noLengthLimit;
CustomTextLength = customTextLength;
Acceptance = acceptance;
FindROI = findRoi.Clone() as ROI;
}
public object Clone() {
return new OcrParamExt() {
StrReadParamExt = this.StrReadParamExt.Clone() as StrReadParamExt,
OcrReadParamExt = this.OcrReadParamExt.Clone() as OcrReadParamExt,
TesseractParamExt = this.TesseractParamExt.Clone() as TesseractParamExt,
NoLengthLimit = this.NoLengthLimit,
CustomTextLength = this.CustomTextLength,
Acceptance = this.Acceptance,
FindROI = this.FindROI.Clone() as ROI
};
}
public static bool Exists(string dirPath) {
string filePath = Path.Combine(dirPath, FILE_NAME);
return File.Exists(filePath);
}
internal static OcrParamExt Load(string dirPath) {
string filePath = Path.Combine(dirPath, FILE_NAME);
if (File.Exists(filePath)) {
return JsonConvert.DeserializeObject(
File.ReadAllText(filePath), typeof(OcrParamExt)) as OcrParamExt;
}
return new OcrParamExt();
}
public static int Save(string dirPath, OcrParamExt paramExt) {
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, paramExt);
}
return E1.OK;
}
}
}