diff --git a/detect.gui/Models/Entities/DetectTaskEntity.cs b/detect.gui/Models/Entities/DetectTaskEntity.cs index f8ac994..e15557a 100644 --- a/detect.gui/Models/Entities/DetectTaskEntity.cs +++ b/detect.gui/Models/Entities/DetectTaskEntity.cs @@ -67,5 +67,24 @@ public class DetectTaskEntity [Column("results")] public string? Results { get; set; } + [StringLength(255), Comment("墙体类型")] + [JsonProperty(PropertyName = "wallType")] + [Column("wall_type")] + public string? WallType { get; set; } + + [StringLength(255), Comment("方向")] + [JsonProperty(PropertyName = "direction")] + [Column("direction")] + public string? Direction { get; set; } + + [StringLength(255), Comment("堆芯A点")] + [JsonProperty(PropertyName = "coreA")] + [Column("core_a")] + public string? CoreA { get; set; } + + [StringLength(255), Comment("堆芯B点")] + [JsonProperty(PropertyName = "coreB")] + [Column("core_b")] + public string? CoreB { get; set; } } \ No newline at end of file diff --git a/detect.gui/Services/OCRService.cs b/detect.gui/Services/OCRService.cs index fa4a6a1..d20ea76 100644 --- a/detect.gui/Services/OCRService.cs +++ b/detect.gui/Services/OCRService.cs @@ -15,12 +15,6 @@ namespace detect.gui.Services; public class OCRService { - // private static OCRService? _instance; - // - // public static OCRService Instance() - // { - // return _instance ??= new OCRService(); - // } private readonly PaddleOCREngine? _engine; public OCRService() { @@ -28,69 +22,11 @@ public class OCRService var parameter = new OCRParameter(); _engine = new PaddleOCREngine(config, parameter); } - - private ApiResponse ImportImageOCR(string base64ImageString) - { - // var fileName = DateTime.Now.ToString("yyyyMMddHHmmss"); - // fileName = GetImage(base64ImageString, fileName); - var result = ""; - // using (var ocrEngine = new TesseractEngine(@".", "chi_sim", EngineMode.Default)) - // { - // using (var img = Pix.LoadFromFile(fileName)) - // { - // using (var page = ocrEngine.Process(img)) - // { - // var text = page.GetText().Replace("\n\n", ""); - // var start = text.IndexOf('\n'); - // if (start < 0) return new ApiResponse(0, "success", result); - // text = text.Substring(start).Replace("”", "").Replace("|", ""); - // while (text.Contains(" ")) - // { - // text = text.Replace(" ", " "); - // } - // - // var lines = text.Split('\n'); - // var data = new List(); - // foreach (var line in lines) - // { - // if (string.IsNullOrWhiteSpace(line)) continue; - // var items = line.Split(" "); - // try - // { - // data.Add(new - // { - // code = ReplaceChars(items[1]), - // type = ReplaceChars(items[2]), - // x = ReplaceChars(items[3]), - // y = ReplaceChars(items[4]), - // center = ReplaceChars(items[5]), - // w = ReplaceChars(items[2].Split("x")[0]), - // h = ReplaceChars(items[2].Split("x")[1]), - // }); - // } - // catch - // { - // } - // } - // - // if (data.Count > 0) - // result = JsonSerializer.Serialize(data, - // new JsonSerializerOptions - // { WriteIndented = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) }); - // } - // } - // } - - return new ApiResponse(0, "success", result); - } public Task ImportByOCR(string base64ImageString) { return Task.Run(() => { - // var fileName = DateTime.Now.ToString("yyyyMMddHHmmss"); - // fileName = GetImage(base64ImageString, fileName); - // var result = _engine?.DetectText(new Bitmap(fileName)); var image = GetImage(base64ImageString); if (image is null) return ""; var result = _engine?.DetectText(image); @@ -101,49 +37,13 @@ public class OCRService d.Index = index; return d; }).ToList(); - // var items = resultList.Where(d => !string.IsNullOrEmpty(d.Text) && d.Text.ToUpper().Contains("定位信息表")).ToList(); - // if (items.Any() && !string.IsNullOrEmpty(items.First().Text)) - // { - // wallCode = items.First().Text!.Replace("定位信息表", "").Replace("预埋件", "").Replace("墙", ""); - // } - // var tempList = new List(); - // if (!string.IsNullOrWhiteSpace(wallCode)) - // { - // tempList = resultList.Where(d => !string.IsNullOrEmpty(d.Text) && d.Text.ToUpper().Contains(wallCode.ToUpper())).ToList(); - // } - // else - // { + // 获取预埋件信息 var tempList = resultList.Where(d => !string.IsNullOrEmpty(d.Text) && - (d.Text.ToUpper().Contains("PA") || - d.Text.ToUpper().Contains("PB") || - d.Text.ToUpper().Contains("PC") || - d.Text.ToUpper().Contains("PD") || - d.Text.ToUpper().Contains("PE") || - d.Text.ToUpper().Contains("PF") || - d.Text.ToUpper().Contains("PG") || - d.Text.ToUpper().Contains("PH") || - d.Text.ToUpper().Contains("PI") || - d.Text.ToUpper().Contains("PJ") || - d.Text.ToUpper().Contains("PK") || - d.Text.ToUpper().Contains("PL") || - d.Text.ToUpper().Contains("PM") || - d.Text.ToUpper().Contains("PN") || - d.Text.ToUpper().Contains("PO") || - d.Text.ToUpper().Contains("PP") || - d.Text.ToUpper().Contains("PO") || - d.Text.ToUpper().Contains("PR") || - d.Text.ToUpper().Contains("PS") || - d.Text.ToUpper().Contains("PT") || - d.Text.ToUpper().Contains("PU") || - d.Text.ToUpper().Contains("PV") || - d.Text.ToUpper().Contains("PW") || - d.Text.ToUpper().Contains("PX") || - d.Text.ToUpper().Contains("PY") || - d.Text.ToUpper().Contains("PZ") || - d.Text.ToUpper().Contains("VB") || - d.Text.ToUpper().Contains("BS"))) + (Enumerable.Range('A', 'Z' - 'A' + 1) + .Select(i => "P" + (char)i) + .Any(substring => d.Text.ToUpper().Contains(substring)) || + d.Text.ToUpper().Contains("VB"))) .ToList(); - // } var data = new List(); foreach (var item in tempList) { @@ -153,8 +53,6 @@ public class OCRService var h = "0"; var type = ReplaceChars(resultList[item.Index + 1].Text); if (string.IsNullOrWhiteSpace(type)) continue; - // if (type.Contains('P', StringComparison.CurrentCultureIgnoreCase) && type.Contains('L', StringComparison.CurrentCultureIgnoreCase)) - // { type = Regex.Replace(type, "[A-Z]", string.Empty); if (type.Contains('-', StringComparison.CurrentCultureIgnoreCase)) { @@ -177,13 +75,6 @@ public class OCRService } else continue; - - // } - // else - // { - // w = type.Split("x")[1]; - // h = type.Split("x")[0]; - // } data.Add(new { sn = ReplaceChars(resultList[item.Index - 1].Text), @@ -194,26 +85,10 @@ public class OCRService center = ReplaceChars(resultList[item.Index + 4].Text), w = w, h = h, - // w = ReplaceChars(resultList[item.Index + 1].Text).Split("x")[1], - // h = ReplaceChars(resultList[item.Index + 1].Text).Split("x")[0], angle = ReplaceChars(resultList[item.Index + 5].Text), }); } - catch - { - // data.Add(new - // { - // sn = "", - // code = "", - // type = "", - // x = "0", - // y = "0", - // center = "0", - // w = "0", - // h = "0", - // angle = "0", - // }); - } + catch {} // 出错则忽略 } return data.Count > 0 @@ -229,6 +104,7 @@ public class OCRService return string.IsNullOrEmpty(text) ? "" : text.Replace("\u00d7", "x").Replace("_", "").Replace(",", "").Replace(":", "").Replace(";", "").Replace(" ", "").Replace(",", ""); } + // 根据类型 返回图片 private Image? GetImage(string base64ImageString) { var imageType = System.Drawing.Imaging.ImageFormat.Gif; @@ -265,12 +141,7 @@ public class OCRService var image = System.Drawing.Image.FromStream(ms); using var bmpStream = new MemoryStream(); image.Save(bmpStream, imageType); - // var bmpBytes = bmpStream.ToArray(); - // File.WriteAllBytes(fileName, bmpBytes); - return image; - // image.Dispose(); - // return fileName; } catch {