|
@@ -3,6 +3,14 @@ using WingInterfaceLibrary.Interface;
|
|
|
using System.Threading.Tasks;
|
|
|
using WingServerCommon.Log;
|
|
|
using WingInterfaceLibrary.Request.AIDiagnosis;
|
|
|
+using AutoTraceLib;
|
|
|
+using System.IO;
|
|
|
+using AI.Common.Log;
|
|
|
+using AI.Common;
|
|
|
+using SkiaSharp;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System;
|
|
|
|
|
|
namespace WingAIDiagnosisService.Service
|
|
|
{
|
|
@@ -11,6 +19,22 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public partial class AIDiagnosisService : JsonRpcService, IAIDiagnosisService
|
|
|
{
|
|
|
+ private VetAutoTrace _vetAutoTrace;
|
|
|
+
|
|
|
+ private VetAutoTrace VetAutoTrace
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (_vetAutoTrace == null)
|
|
|
+ {
|
|
|
+ _vetAutoTrace = new VetAutoTrace();
|
|
|
+ _vetAutoTrace.NotifyError += VetAutoTrace_NotifyError;
|
|
|
+ _vetAutoTrace.NotifyLog += VetAutoTrace_NotifyLog;
|
|
|
+ }
|
|
|
+ return _vetAutoTrace;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -20,8 +44,76 @@ namespace WingAIDiagnosisService.Service
|
|
|
|
|
|
public async Task<VetAutoTraceImageResult> VetAutoTraceImageAsync(VetAutoTraceImageRequest request)
|
|
|
{
|
|
|
- return null;
|
|
|
+ var resultData = new VetAutoTraceImageResult { PWTraceInfos = new Dictionary<int, PWTraceDTO>() };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var imageReq = request.ImageInfo;
|
|
|
+ var rowImage = new RawImage(imageReq.Data, imageReq.Width, imageReq.Height, MapTo((SKColorType)imageReq.SKColorType));
|
|
|
+ var rectReq = request.RectInfo;
|
|
|
+ var rect = new Rect(rectReq.Left, rectReq.Top, rectReq.Width, rectReq.Height);
|
|
|
+ var autoRes = VetAutoTrace.ProcessOneImage(rowImage, rect);
|
|
|
+ if (autoRes != null && autoRes.Any())
|
|
|
+ {
|
|
|
+ foreach (var key in autoRes.Keys)
|
|
|
+ {
|
|
|
+ var item = autoRes[key];
|
|
|
+ var traceInfo = new PWTraceDTO();
|
|
|
+ traceInfo.EnableCalCycle = item.enableCalCycle;
|
|
|
+ traceInfo.Contour = item.Contour?.Select(c => new PWTracePointDTO
|
|
|
+ {
|
|
|
+ X = c.X,
|
|
|
+ Y = c.Y,
|
|
|
+ })?.ToList() ?? new List<PWTracePointDTO>();
|
|
|
+ traceInfo.CycleInfos = item.CycleInfos?.Select(c => new PWTraceCycleDTO
|
|
|
+ {
|
|
|
+ CycleStart = c.CycleStart,
|
|
|
+ CycleEnd = c.CycleEnd,
|
|
|
+ Epeak = c.Epeak,
|
|
|
+ Apeak = c.Apeak,
|
|
|
+ })?.ToList() ?? new List<PWTraceCycleDTO>();
|
|
|
+ traceInfo.BestCycles = new PWTraceBestCycleDTO
|
|
|
+ {
|
|
|
+ OneBestCycle = new PWTraceBestCycleIndexDTO { BestStart = item.BestCycles.OneBestCycle.BestStart, BestEnd = item.BestCycles.OneBestCycle.BestEnd },
|
|
|
+ TwoBestCycle = new PWTraceBestCycleIndexDTO { BestStart = item.BestCycles.TwoBestCycle.BestStart, BestEnd = item.BestCycles.TwoBestCycle.BestEnd },
|
|
|
+ ThreeBestCycle = new PWTraceBestCycleIndexDTO { BestStart = item.BestCycles.ThreeBestCycle.BestStart, BestEnd = item.BestCycles.ThreeBestCycle.BestEnd },
|
|
|
+ FourBestCycle = new PWTraceBestCycleIndexDTO { BestStart = item.BestCycles.FourBestCycle.BestStart, BestEnd = item.BestCycles.FourBestCycle.BestEnd },
|
|
|
+ FiveBestCycle = new PWTraceBestCycleIndexDTO { BestStart = item.BestCycles.FiveBestCycle.BestStart, BestEnd = item.BestCycles.FiveBestCycle.BestEnd },
|
|
|
+ };
|
|
|
+ resultData.PWTraceInfos.Add((int)key, traceInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"AIDiagnosisService VetAutoTraceImageAsync fail, ex:{ex}");
|
|
|
+ }
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void VetAutoTrace_NotifyError(object sender, ErrorEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"AIDiagnosisService VetAutoTrace_NotifyError: {e.GetException()}");
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
}
|
|
|
+ private void VetAutoTrace_NotifyLog(object sender, LogEventArgs e)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (e?.LogType == EnumLogType.WarnLog || e?.LogType == EnumLogType.ErrorLog)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"AIDiagnosisService VetAutoTrace_NotifyLog. LogType: {e.LogType}, Msg: {e.Msg}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.WriteLineInfo($"AIDiagnosisService VetAutoTrace_NotifyLog. LogType: {e.LogType}, Msg: {e.Msg}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|