171 lines
4.4 KiB
C#
171 lines
4.4 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace Poe2Trade.Screen;
|
|
|
|
public class OcrWord
|
|
{
|
|
[JsonPropertyName("text")] public string Text { get; set; } = "";
|
|
[JsonPropertyName("x")] public int X { get; set; }
|
|
[JsonPropertyName("y")] public int Y { get; set; }
|
|
[JsonPropertyName("width")] public int Width { get; set; }
|
|
[JsonPropertyName("height")] public int Height { get; set; }
|
|
}
|
|
|
|
public class OcrLine
|
|
{
|
|
[JsonPropertyName("text")] public string Text { get; set; } = "";
|
|
[JsonPropertyName("words")] public List<OcrWord> Words { get; set; } = [];
|
|
}
|
|
|
|
public class OcrResponse
|
|
{
|
|
public string Text { get; set; } = "";
|
|
public List<OcrLine> Lines { get; set; } = [];
|
|
}
|
|
|
|
public class GridItem
|
|
{
|
|
[JsonPropertyName("row")] public int Row { get; set; }
|
|
[JsonPropertyName("col")] public int Col { get; set; }
|
|
[JsonPropertyName("w")] public int W { get; set; }
|
|
[JsonPropertyName("h")] public int H { get; set; }
|
|
}
|
|
|
|
public class GridMatch
|
|
{
|
|
[JsonPropertyName("row")] public int Row { get; set; }
|
|
[JsonPropertyName("col")] public int Col { get; set; }
|
|
[JsonPropertyName("similarity")] public double Similarity { get; set; }
|
|
}
|
|
|
|
public class GridScanResult
|
|
{
|
|
public bool[][] Cells { get; set; } = [];
|
|
public List<GridItem> Items { get; set; } = [];
|
|
public List<GridMatch>? Matches { get; set; }
|
|
}
|
|
|
|
public class DiffOcrResponse
|
|
{
|
|
public string Text { get; set; } = "";
|
|
public List<OcrLine> Lines { get; set; } = [];
|
|
public Poe2Trade.Core.Region? Region { get; set; }
|
|
}
|
|
|
|
public class TemplateMatchResult
|
|
{
|
|
public int X { get; set; }
|
|
public int Y { get; set; }
|
|
public int Width { get; set; }
|
|
public int Height { get; set; }
|
|
public double Confidence { get; set; }
|
|
}
|
|
|
|
// -- Parameter types --
|
|
|
|
public sealed class DiffCropParams
|
|
{
|
|
[JsonPropertyName("diffThresh")]
|
|
public int DiffThresh { get; set; } = 20;
|
|
|
|
[JsonPropertyName("rowThreshDiv")]
|
|
public int RowThreshDiv { get; set; } = 40;
|
|
|
|
[JsonPropertyName("colThreshDiv")]
|
|
public int ColThreshDiv { get; set; } = 8;
|
|
|
|
[JsonPropertyName("maxGap")]
|
|
public int MaxGap { get; set; } = 20;
|
|
|
|
[JsonPropertyName("trimCutoff")]
|
|
public double TrimCutoff { get; set; } = 0.4;
|
|
|
|
[JsonPropertyName("ocrPad")]
|
|
public int OcrPad { get; set; } = 10;
|
|
}
|
|
|
|
public sealed class OcrParams
|
|
{
|
|
// preprocessing
|
|
[JsonPropertyName("kernelSize")]
|
|
public int KernelSize { get; set; } = 41;
|
|
|
|
[JsonPropertyName("upscale")]
|
|
public int Upscale { get; set; } = 2;
|
|
|
|
[JsonPropertyName("useBackgroundSub")]
|
|
public bool UseBackgroundSub { get; set; } = true;
|
|
|
|
[JsonPropertyName("dimPercentile")]
|
|
public int DimPercentile { get; set; } = 40;
|
|
|
|
[JsonPropertyName("textThresh")]
|
|
public int TextThresh { get; set; } = 60;
|
|
|
|
[JsonPropertyName("softThreshold")]
|
|
public bool SoftThreshold { get; set; } = false;
|
|
|
|
// EasyOCR tuning
|
|
[JsonPropertyName("mergeGap")]
|
|
public int MergeGap { get; set; } = 0;
|
|
|
|
[JsonPropertyName("linkThreshold")]
|
|
public double? LinkThreshold { get; set; }
|
|
|
|
[JsonPropertyName("textThreshold")]
|
|
public double? TextThreshold { get; set; }
|
|
|
|
[JsonPropertyName("lowText")]
|
|
public double? LowText { get; set; }
|
|
|
|
[JsonPropertyName("widthThs")]
|
|
public double? WidthThs { get; set; }
|
|
|
|
[JsonPropertyName("paragraph")]
|
|
public bool? Paragraph { get; set; }
|
|
}
|
|
|
|
public sealed class DiffOcrParams
|
|
{
|
|
[JsonPropertyName("crop")]
|
|
public DiffCropParams Crop { get; set; } = new();
|
|
|
|
[JsonPropertyName("ocr")]
|
|
public OcrParams Ocr { get; set; } = new();
|
|
}
|
|
|
|
public sealed class EdgeCropParams
|
|
{
|
|
[JsonPropertyName("darkThresh")]
|
|
public int DarkThresh { get; set; } = 40;
|
|
|
|
[JsonPropertyName("minDarkRun")]
|
|
public int MinDarkRun { get; set; } = 200;
|
|
|
|
[JsonPropertyName("runGapTolerance")]
|
|
public int RunGapTolerance { get; set; } = 15;
|
|
|
|
[JsonPropertyName("rowThreshDiv")]
|
|
public int RowThreshDiv { get; set; } = 40;
|
|
|
|
[JsonPropertyName("colThreshDiv")]
|
|
public int ColThreshDiv { get; set; } = 8;
|
|
|
|
[JsonPropertyName("maxGap")]
|
|
public int MaxGap { get; set; } = 15;
|
|
|
|
[JsonPropertyName("trimCutoff")]
|
|
public double TrimCutoff { get; set; } = 0.3;
|
|
|
|
[JsonPropertyName("ocrPad")]
|
|
public int OcrPad { get; set; } = 10;
|
|
}
|
|
|
|
public sealed class EdgeOcrParams
|
|
{
|
|
[JsonPropertyName("crop")]
|
|
public EdgeCropParams Crop { get; set; } = new();
|
|
|
|
[JsonPropertyName("ocr")]
|
|
public OcrParams Ocr { get; set; } = new();
|
|
}
|