1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549 |
- using AI.Common;
- using AI.Common.Log;
- using AI.DiagSystem;
- using AIDiagnosis.Common.Enums;
- using AIDiagnosis.Common.Models;
- using AIDiagnosisSDK.Enums;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using Vinno.AI.AIDiagnosisSDK.Interfaces;
- using Vinno.AI.AIDiagnosisSDK.Models;
- using Vinno.AI.AIDiagnosisService.Tools;
- using Vinno.AI.CommonSDK.Enums;
- using Vinno.AI.CommonSDK.Models;
- using Vinno.AI.CommonSDK.Tools;
- using Vinno.AI.Service.Common.Interfaces;
- using Vinno.AI.Service.Common.Models;
- using Vinno.AI.Service.Common.Tools;
- namespace Vinno.AI.AIDiagnosisService
- {
- public class AIDiagnosisService : IAIDiagnosisService, IDisposable, IEngine
- {
- private readonly string _modelFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
- private readonly ConcurrentStack<byte[]> _singleImageCacheForAbdomen;
- private readonly ConcurrentStack<byte[]> _singleImageCacheForBreast;
- private readonly ConcurrentStack<byte[]> _singleImageCacheForThyroid;
- private readonly ConcurrentStack<byte[]> _singleImageCacheForCarotid;
- private PipeServer _singleImagePipeServerForAbdomen;
- private PipeServer _singleImagePipeServerForBreast;
- private PipeServer _singleImagePipeServerForThyroid;
- private PipeServer _singleImagePipeServerForCarotid;
- private ImageProvider _imageProviderForAbdomen;
- private ImageProvider _imageProviderForBreast;
- private ImageProvider _imageProviderForThyroid;
- private ImageProvider _imageProviderForCarotid;
- private AIDiagnosisParameter _abdomenDiagnosisParameter;
- private AIDiagnosisParameter _breastDiagnosisParameter;
- private AIDiagnosisParameter _thyroidDiagnosisParameter;
- private AIDiagnosisParameter _carotidDiagnosisParameter;
- private global::AIDiagnosisSDK.AIDiagnosis _aiDiagnosis;
- private bool _disposed;
- public static List<FunctionInfo> AllFunctions { get; }
- static AIDiagnosisService()
- {
- AllFunctions = global::AIDiagnosisSDK.AIDiagnosis.AllFunctions.Where(x => x.FunctionName != EnumAIDiagnosisFunction.OrganIdentification.ToString()).ToList();
- }
- public static void Init(List<FunctionInfo> enableFunctions, List<FunctionInfo> currentUsedFunctions)
- {
- global::AIDiagnosisSDK.AIDiagnosis.InitForAIDiagnosis(enableFunctions, currentUsedFunctions);
- }
- public AIDiagnosisService()
- {
- try
- {
- _singleImageCacheForAbdomen = new ConcurrentStack<byte[]>();
- _singleImagePipeServerForAbdomen = new PipeServer(AIDiagnosisSystemConsts.PipeForAbdomenDiagnosisSingleImage);
- _singleImagePipeServerForAbdomen.LogMsgThrow += OnLogMsgThrow;
- _singleImagePipeServerForAbdomen.DataReceived += OnDataReceived;
- _singleImagePipeServerForAbdomen.StartAndReceive();
- _imageProviderForAbdomen = new ImageProvider(AIEnumType.AbdomenDiagnosis);
- _singleImageCacheForBreast = new ConcurrentStack<byte[]>();
- _singleImagePipeServerForBreast = new PipeServer(AIDiagnosisSystemConsts.PipeForBreastDiagnosisSingleImage);
- _singleImagePipeServerForBreast.LogMsgThrow += OnLogMsgThrow;
- _singleImagePipeServerForBreast.DataReceived += OnDataReceived;
- _singleImagePipeServerForBreast.StartAndReceive();
- _imageProviderForBreast = new ImageProvider(AIEnumType.BreastDiagnosis);
- _singleImageCacheForThyroid = new ConcurrentStack<byte[]>();
- _singleImagePipeServerForThyroid = new PipeServer(AIDiagnosisSystemConsts.PipeForThyroidDiagnosisSingleImage);
- _singleImagePipeServerForThyroid.LogMsgThrow += OnLogMsgThrow;
- _singleImagePipeServerForThyroid.DataReceived += OnDataReceived;
- _singleImagePipeServerForThyroid.StartAndReceive();
- _imageProviderForThyroid = new ImageProvider(AIEnumType.ThyroidDiagnosis);
- _singleImageCacheForCarotid = new ConcurrentStack<byte[]>();
- _singleImagePipeServerForCarotid = new PipeServer(AIDiagnosisSystemConsts.PipeForCarotidDiagnosisSingleImage);
- _singleImagePipeServerForCarotid.LogMsgThrow += OnLogMsgThrow;
- _singleImagePipeServerForCarotid.DataReceived += OnDataReceived;
- _singleImagePipeServerForCarotid.StartAndReceive();
- _imageProviderForCarotid = new ImageProvider(AIEnumType.CarotidDiagnosis);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-Constructor error:{ex}");
- }
- }
- /// <summary>
- /// 切换引擎
- /// </summary>
- /// <param name="functionInfo"></param>
- public void SwitchEngines(FunctionInfo functionInfo)
- {
- try
- {
- global::AIDiagnosisSDK.AIDiagnosis.SwitchAIEngines(functionInfo);
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.SwitchAIEngines2(functionInfo);
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SwitchEngines error:{ex}");
- }
- }
- private void OnDataReceived(object sender, byte[] e)
- {
- try
- {
- var pipeServer = (PipeServer)sender;
- switch (pipeServer.PipeName)
- {
- case AIDiagnosisSystemConsts.PipeForAbdomenDiagnosisSingleImage:
- _singleImageCacheForAbdomen.Push(e);
- break;
- case AIDiagnosisSystemConsts.PipeForBreastDiagnosisSingleImage:
- _singleImageCacheForBreast.Push(e);
- break;
- case AIDiagnosisSystemConsts.PipeForThyroidDiagnosisSingleImage:
- _singleImageCacheForThyroid.Push(e);
- break;
- case AIDiagnosisSystemConsts.PipeForCarotidDiagnosisSingleImage:
- _singleImageCacheForCarotid.Push(e);
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-OnDataReceived error:{ex}");
- }
- }
- private void OnLogMsgThrow(object sender, AILogEventArgs e)
- {
- if (e == null)
- {
- return;
- }
- switch (e.LogType)
- {
- case AIEnumLogType.ErrorLog:
- case AIEnumLogType.FatalLog:
- Logger.Error(e.Msg);
- break;
- case AIEnumLogType.WarnLog:
- Logger.Warning(e.Msg);
- break;
- case AIEnumLogType.InfoLog:
- default:
- Logger.Info(e.Msg);
- break;
- }
- }
- public void InitializeAbdomenDiagnosis(AIDiagnosisParameter abdomenDiagnosisParameter, bool hasImageProvider)
- {
- try
- {
- _abdomenDiagnosisParameter = abdomenDiagnosisParameter;
- CloseDiagnosis();
- var performance = (EnumPerformance)abdomenDiagnosisParameter.Performance;
- var detectMode = (EnumDetectMode)abdomenDiagnosisParameter.DetectMode;
- var isCropped = abdomenDiagnosisParameter.IsCropped;
- var detectTps = abdomenDiagnosisParameter.DetectTps;
- var intervalTime = abdomenDiagnosisParameter.IntervalTime;
- var enableLesionSeg = abdomenDiagnosisParameter.EnableLesionSeg;
- var enableLesionDescription = abdomenDiagnosisParameter.EnableLesionDescription;
- var enableOrganDescription = abdomenDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Abdomen, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForAbdomen : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLesionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
- _aiDiagnosis.StartEvaluation += OnStartEvaluation;
- _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
- _aiDiagnosis.NotifyError += OnNotifyError;
- _aiDiagnosis.NotifyLog += OnNotifyLog;
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-InitializeAbdomenDiagnosis error:{ex}");
- }
- }
- public void InitializeBreastDiagnosis(AIDiagnosisParameter breastDiagnosisParameter, bool hasImageProvider)
- {
- try
- {
- _breastDiagnosisParameter = breastDiagnosisParameter;
- CloseDiagnosis();
- var performance = (EnumPerformance)breastDiagnosisParameter.Performance;
- var detectMode = (EnumDetectMode)breastDiagnosisParameter.DetectMode;
- var isCropped = breastDiagnosisParameter.IsCropped;
- var detectTps = breastDiagnosisParameter.DetectTps;
- var intervalTime = breastDiagnosisParameter.IntervalTime;
- var enableLesionSeg = breastDiagnosisParameter.EnableLesionSeg;
- var enableLessionDescription = breastDiagnosisParameter.EnableLesionDescription;
- var enableOrganDescription = breastDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Breast, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForBreast : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLessionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
- _aiDiagnosis.StartEvaluation += OnStartEvaluation;
- _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
- _aiDiagnosis.NotifyError += OnNotifyError;
- _aiDiagnosis.NotifyLog += OnNotifyLog;
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-InitializeBreastDiagnosis error:{ex}");
- }
- }
- public void InitializeThyroidDiagnosis(AIDiagnosisParameter thyroidDiagnosisParameter, bool hasImageProvider)
- {
- try
- {
- _thyroidDiagnosisParameter = thyroidDiagnosisParameter;
- CloseDiagnosis();
- var performance = (EnumPerformance)thyroidDiagnosisParameter.Performance;
- var detectMode = (EnumDetectMode)thyroidDiagnosisParameter.DetectMode;
- var isCropped = thyroidDiagnosisParameter.IsCropped;
- var detectTps = thyroidDiagnosisParameter.DetectTps;
- var intervalTime = thyroidDiagnosisParameter.IntervalTime;
- var enableLesionSeg = thyroidDiagnosisParameter.EnableLesionSeg;
- var enableLessionDescription = thyroidDiagnosisParameter.EnableLesionDescription;
- var enableOrganDescription = thyroidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Thyroid, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForThyroid : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLessionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
- _aiDiagnosis.StartEvaluation += OnStartEvaluation;
- _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
- _aiDiagnosis.NotifyError += OnNotifyError;
- _aiDiagnosis.NotifyLog += OnNotifyLog;
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-InitializeBreastDiagnosis error:{ex}");
- }
- }
- public void InitializeCarotidDiagnosis(AIDiagnosisParameter carotidDiagnosisParameter, bool hasImageProvider)
- {
- try
- {
- _carotidDiagnosisParameter = carotidDiagnosisParameter;
- CloseDiagnosis();
- var performance = (EnumPerformance)carotidDiagnosisParameter.Performance;
- var detectMode = (EnumDetectMode)carotidDiagnosisParameter.DetectMode;
- var isCropped = carotidDiagnosisParameter.IsCropped;
- var detectTps = carotidDiagnosisParameter.DetectTps;
- var intervalTime = carotidDiagnosisParameter.IntervalTime;
- var enableLesionSeg = carotidDiagnosisParameter.EnableLesionSeg;
- var enableLessionDescription = carotidDiagnosisParameter.EnableLesionDescription;
- var enableOrganDescription = carotidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis = new global::AIDiagnosisSDK.AIDiagnosis(EnumAIModule.Carotid, Setting.Instance.IsSaveDetectImage, Setting.Instance.IsSaveAllImage, Logger.LogDir, hasImageProvider ? _imageProviderForCarotid : null, performance, detectMode, isCropped, detectTps, intervalTime, _modelFolder, enableLesionSeg, enableLessionDescription, Setting.Instance.CorrectAIResults, Setting.Instance.IsIntelligentIdentificationMode, Setting.Instance.IntelligentIdentificationThreshold, Setting.Instance.IntelligentIdentificationTimeRange, enableOrganDescription);
- _aiDiagnosis.StartEvaluation += OnStartEvaluation;
- _aiDiagnosis.FinishEvaluation += OnFinishEvaluation;
- _aiDiagnosis.NotifyError += OnNotifyError;
- _aiDiagnosis.NotifyLog += OnNotifyLog;
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-InitializeCarotidDiagnosis error:{ex}");
- }
- }
- public void Start()
- {
- try
- {
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.Start();
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-Start error:{ex}");
- }
- }
- public void Stop()
- {
- try
- {
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.Stop();
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-Stop error:{ex}");
- }
- }
- private void OnStartEvaluation(object sender, EventArgs e)
- {
- var aiDiagnosis = (global::AIDiagnosisSDK.AIDiagnosis)sender;
- switch (aiDiagnosis.AIModule)
- {
- case EnumAIModule.Breast:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.BreastDiagnosisStartEvaluationRaised, Params = e });
- break;
- case EnumAIModule.Abdomen:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AbdomenDiagnosisStartEvaluationRaised, Params = e });
- break;
- case EnumAIModule.Thyroid:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.ThyroidDiagnosisStartEvaluationRaised, Params = e });
- break;
- case EnumAIModule.Carotid:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.CarotidDiagnosisStartEvaluationRaised, Params = e });
- break;
- }
- }
- private void OnFinishEvaluation(object sender, global::AI.DiagSystem.AIDiagResultPerImg e)
- {
- var aiDiagnosis = (global::AIDiagnosisSDK.AIDiagnosis)sender;
- var transAIDiagresultPerImg = AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(e);
- switch (aiDiagnosis.AIModule)
- {
- case EnumAIModule.Breast:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.BreastDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
- break;
- case EnumAIModule.Abdomen:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AbdomenDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
- break;
- case EnumAIModule.Thyroid:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.ThyroidDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
- break;
- case EnumAIModule.Carotid:
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.CarotidDiagnosisFinishEvaluationRaised, Params = transAIDiagresultPerImg });
- break;
- }
- }
- private void OnNotifyError(object sender, ErrorEventArgs e)
- {
- Logger.Error($"AIDiagnosisService OnNotifyError:{e.GetException()}");
- var logEventArgs = AICommonServiceConvertHelper.ConvertErrorEventArgsToAILogEventArgs(e);
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AIDiagnosisNotifyLogRaised, Params = logEventArgs });
- }
- private void OnNotifyLog(object sender, LogEventArgs e)
- {
- if (e == null)
- {
- return;
- }
- switch (e.LogType)
- {
- case EnumLogType.InfoLog:
- Logger.Info($"AIDiagnosisService OnNotifyLog:{e.Msg}");
- break;
- case EnumLogType.WarnLog:
- Logger.Warning($"AIDiagnosisService OnNotifyLog:{e.Msg}");
- break;
- case EnumLogType.ErrorLog:
- case EnumLogType.FatalLog:
- default:
- Logger.Error($"AIDiagnosisService OnNotifyLog:{e.Msg}");
- break;
- }
- var logEventArgs = AICommonServiceConvertHelper.ConvertLogEventArgsToAILogEventArgs(e);
- NotificationSender.SendNotification(new AINotificationArgs() { NotificationType = AIEnumNotificationType.AIDiagnosisNotifyLogRaised, Params = logEventArgs });
- }
- public TransAIDiagResultPerImg DetectOneByteImage(AIEnumModuleType type)
- {
- try
- {
- byte[] byteImage = null;
- int retryCount = 0;
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Breast:
- while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Thyroid:
- while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Carotid:
- while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- }
- if (byteImage == null)
- {
- Logger.Error($"AIDiagnosisService-DetectOneByteImage Get Image Cache Fail");
- return null;
- }
- if (_aiDiagnosis == null)
- {
- Logger.Error($"Detect One Byte Image Error:AI Diagnosis is null");
- return null;
- }
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _carotidDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- }
- var result = _aiDiagnosis?.DetectOneImage(byteImage);
- return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-DetectOneByteImage error:{ex}");
- return null;
- }
- }
- /// <summary>
- /// 评估单幅图像 ,图像计算完成后,使用者希望调整结果,使部分结果在选定的矩形框内。
- /// </summary>
- /// <param name="aiRect">使用者给出的矩形框</param>
- /// <param name="transAIDiagResultPerImg">图像的初始计算结果</param>
- /// <summary>
- public TransAIDiagResultPerImg CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage(AIRect aiRect, TransAIDiagResultPerImg transAIDiagResultPerImg)
- {
- try
- {
- byte[] byteImage = null;
- int retryCount = 0;
- while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- if (byteImage == null)
- {
- Logger.Error($"AIDiagnosisService-CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage Get Image Cache Fail");
- return null;
- }
- if (_aiDiagnosis == null)
- {
- Logger.Error($"CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithBytesImage Error:AI Diagnosis is null");
- return null;
- }
- var rect = AICommonServiceConvertHelper.ConvertAIRectToRect(aiRect);
- var aiDiagResultPerImg = AIConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(transAIDiagResultPerImg);
- var result = _aiDiagnosis?.CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRect(byteImage, rect, aiDiagResultPerImg);
- return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-DetectOneByteImageWithTempSetting error:{ex}");
- return null;
- }
- }
- /// <summary>
- /// 评估单幅图像 ,图像计算完成后,使用者希望调整结果,使部分结果在选定的矩形框内。
- /// </summary>
- /// <param name="aiRect">使用者给出的矩形框</param>
- /// <param name="transAIDiagResultPerImg">图像的初始计算结果</param>
- public TransAIDiagResultPerImg CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage(int height, int width, AIEnumColorType colorType, AIRect aiRect, TransAIDiagResultPerImg transAIDiagResultPerImg)
- {
- try
- {
- byte[] byteImage = null;
- int retryCount = 0;
- while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- if (byteImage == null)
- {
- Logger.Error($"AIDiagnosisService-CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage Get Image Cache Fail");
- return null;
- }
- if (_aiDiagnosis == null)
- {
- Logger.Error($"CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage Error:AI Diagnosis is null");
- return null;
- }
- var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
- var rect = AICommonServiceConvertHelper.ConvertAIRectToRect(aiRect);
- var aiDiagResultPerImg = AIConvertHelper.ConvertTransAIDiagResultPerImgToAIDiagResultPerImg(transAIDiagResultPerImg);
- var result = _aiDiagnosis?.CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRect(rawImage, rect, aiDiagResultPerImg);
- return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-CalculateCarotidInnerDiameterAndIntimaMediaThicknessInSpecifiedRectWithRawImage error:{ex}");
- return null;
- }
- }
- public TransAIDiagResultPerImg DetectOneByteImageWithTempSetting(AIEnumModuleType type, bool enableLesionSeg, bool enableLessionDescription, bool enableOrganDescription)
- {
- try
- {
- byte[] byteImage = null;
- int retryCount = 0;
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Breast:
- while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Thyroid:
- while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Carotid:
- while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- }
- if (byteImage == null)
- {
- Logger.Error($"AIDiagnosisService-DetectOneByteImageWithTempSetting Get Image Cache Fail");
- return null;
- }
- if (_aiDiagnosis == null)
- {
- Logger.Error($"DetectOneByteImageWithTempSetting Error:AI Diagnosis is null");
- return null;
- }
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- }
- var result = _aiDiagnosis?.DetectOneImage(byteImage, enableLesionSeg, enableLessionDescription, enableOrganDescription);
- return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-DetectOneByteImageWithTempSetting error:{ex}");
- return null;
- }
- }
- public TransAIDiagResultPerImg DetectOneRawImage(AIEnumModuleType type, int height, int width, AIEnumColorType colorType)
- {
- try
- {
- byte[] byteImage = null;
- int retryCount = 0;
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Breast:
- while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Thyroid:
- while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Carotid:
- while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- }
- if (byteImage == null)
- {
- Logger.Error($"AIDiagnosisService-DetectOneRawImage Get Image Cache Fail");
- return null;
- }
- if (_aiDiagnosis == null)
- {
- Logger.Error($"Detect One Raw Image Error:AI Diagnosis is null");
- return null;
- }
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- }
- var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
- var result = _aiDiagnosis?.DetectOneImage(rawImage);
- return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-DetectOneRawImage error:{ex}");
- return null;
- }
- }
- public TransAIDiagResultPerImg DetectOneRawImageWithTempSetting(AIEnumModuleType type, int height, int width, AIEnumColorType colorType, bool enableLesionSeg, bool enableLessionDescription, bool enableOrganDescription)
- {
- try
- {
- byte[] byteImage = null;
- int retryCount = 0;
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- while (!_singleImageCacheForAbdomen.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Breast:
- while (!_singleImageCacheForBreast.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Thyroid:
- while (!_singleImageCacheForThyroid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- case AIEnumModuleType.Carotid:
- while (!_singleImageCacheForCarotid.TryPop(out byteImage) && retryCount < 50)
- {
- Thread.Sleep(10);
- retryCount++;
- }
- break;
- }
- if (byteImage == null)
- {
- Logger.Error($"AIDiagnosisService-DetectOneRawImageWithTempSetting Get Image Cache Fail");
- return null;
- }
- if (_aiDiagnosis == null)
- {
- Logger.Error($"DetectOneRawImageWithTempSetting Error:AI Diagnosis is null");
- return null;
- }
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Abdomen)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.IsCropped = _abdomenDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _abdomenDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _abdomenDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _abdomenDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_abdomenDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _abdomenDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _abdomenDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Breast)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.IsCropped = _breastDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _breastDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _breastDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _breastDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_breastDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _breastDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _breastDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Thyroid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.IsCropped = _thyroidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableLesionDescription = _thyroidDiagnosisParameter.EnableLesionDescription;
- _aiDiagnosis.EnableOrganDescription = _thyroidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _thyroidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_thyroidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _thyroidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _thyroidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- if (_aiDiagnosis.AIModule != EnumAIModule.Carotid)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.IsCropped = _carotidDiagnosisParameter.IsCropped;
- _aiDiagnosis.EnableOrganDescription = _carotidDiagnosisParameter.EnableOrganDescription;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.EnableLesionSeg = _carotidDiagnosisParameter.EnableLesionSeg;
- _aiDiagnosis.DetectMode = (EnumDetectMode)_carotidDiagnosisParameter.DetectMode;
- _aiDiagnosis.DetectTps = _carotidDiagnosisParameter.DetectTps;
- _aiDiagnosis.IntervalTime = _carotidDiagnosisParameter.IntervalTime;
- }
- }
- break;
- }
- var rawImage = new RawImage(byteImage, width, height, (EnumColorType)colorType);
- var result = _aiDiagnosis?.DetectOneImage(rawImage, enableLesionSeg, enableLessionDescription, enableOrganDescription);
- return AIConvertHelper.ConvertAIDiagResultPerImgToTransAIDiagResultPerImg(result);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-DetectOneRawImageWithTempSetting error:{ex}");
- return null;
- }
- }
- public void SetIsCropped(AIEnumModuleType type, bool isCropped)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- _abdomenDiagnosisParameter.IsCropped = isCropped;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.IsCropped = isCropped;
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- _breastDiagnosisParameter.IsCropped = isCropped;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.IsCropped = isCropped;
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- _thyroidDiagnosisParameter.IsCropped = isCropped;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.IsCropped = isCropped;
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- _carotidDiagnosisParameter.IsCropped = isCropped;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.IsCropped = isCropped;
- }
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SetIsCropped error:{ex}");
- }
- }
- public void SetDetectTps(AIEnumModuleType type, int detectTps)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- _abdomenDiagnosisParameter.DetectTps = detectTps;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.DetectTps = detectTps;
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- _breastDiagnosisParameter.DetectTps = detectTps;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.DetectTps = detectTps;
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- _thyroidDiagnosisParameter.DetectTps = detectTps;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.DetectTps = detectTps;
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- _carotidDiagnosisParameter.DetectTps = detectTps;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.DetectTps = detectTps;
- }
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SetDetectTps error:{ex}");
- }
- }
- public void SetIntervalTime(AIEnumModuleType type, int intervalTime)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- _abdomenDiagnosisParameter.IntervalTime = intervalTime;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.IntervalTime = intervalTime;
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- _breastDiagnosisParameter.IntervalTime = intervalTime;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.IntervalTime = intervalTime;
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- _thyroidDiagnosisParameter.IntervalTime = intervalTime;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.IntervalTime = intervalTime;
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- _carotidDiagnosisParameter.IntervalTime = intervalTime;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.IntervalTime = intervalTime;
- }
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SetIntervalTime error:{ex}");
- }
- }
- public void SetDetectMode(AIEnumModuleType type, AIEnumDetectMode detectMode)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- _abdomenDiagnosisParameter.DetectMode = detectMode;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- _breastDiagnosisParameter.DetectMode = detectMode;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- _thyroidDiagnosisParameter.DetectMode = detectMode;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- _carotidDiagnosisParameter.DetectMode = detectMode;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.DetectMode = (EnumDetectMode)detectMode;
- }
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SetDetectMode error:{ex}");
- }
- }
- public void SetEnableLesionSeg(AIEnumModuleType type, bool enableLesionSeg)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- _abdomenDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- _breastDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- _thyroidDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- _carotidDiagnosisParameter.EnableLesionSeg = enableLesionSeg;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.EnableLesionSeg = enableLesionSeg;
- }
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SetEnableLesionSeg error:{ex}");
- }
- }
- public void SetEnableDescription(AIEnumModuleType type, bool enableLessionDescription, bool enableOrganDescription)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- if (_abdomenDiagnosisParameter != null)
- {
- _abdomenDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
- _abdomenDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Abdomen;
- _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
- _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
- }
- break;
- case AIEnumModuleType.Breast:
- if (_breastDiagnosisParameter != null)
- {
- _breastDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
- _breastDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Breast;
- _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
- _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
- }
- break;
- case AIEnumModuleType.Thyroid:
- if (_thyroidDiagnosisParameter != null)
- {
- _thyroidDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
- _thyroidDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Thyroid;
- _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
- _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
- }
- break;
- case AIEnumModuleType.Carotid:
- if (_carotidDiagnosisParameter != null)
- {
- _carotidDiagnosisParameter.EnableLesionDescription = enableLessionDescription;
- _carotidDiagnosisParameter.EnableOrganDescription = enableOrganDescription;
- }
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.AIModule = EnumAIModule.Carotid;
- _aiDiagnosis.EnableLesionDescription = enableLessionDescription;
- _aiDiagnosis.EnableOrganDescription = enableOrganDescription;
- }
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SetEnableLesionDescription error:{ex}");
- }
- }
- public void Close(AIEnumModuleType type)
- {
- try
- {
- Logger.Info($"AIDiagnosisService-Close Invoke {type}");
- CloseDiagnosis(type);
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-Close error:{ex}");
- }
- }
- private void CloseDiagnosis(AIEnumModuleType type)
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- _abdomenDiagnosisParameter = null;
- break;
- case AIEnumModuleType.Breast:
- _breastDiagnosisParameter = null;
- break;
- case AIEnumModuleType.Thyroid:
- _thyroidDiagnosisParameter = null;
- break;
- case AIEnumModuleType.Carotid:
- _carotidDiagnosisParameter = null;
- break;
- }
- if (_abdomenDiagnosisParameter == null && _breastDiagnosisParameter == null && _thyroidDiagnosisParameter == null && _carotidDiagnosisParameter == null)
- {
- CloseDiagnosis();
- }
- }
- private void CloseDiagnosis()
- {
- if (_aiDiagnosis != null)
- {
- _aiDiagnosis.StartEvaluation -= OnStartEvaluation;
- _aiDiagnosis.FinishEvaluation -= OnFinishEvaluation;
- _aiDiagnosis.NotifyError -= OnNotifyError;
- _aiDiagnosis.NotifyLog -= OnNotifyLog;
- _aiDiagnosis.Close();
- _aiDiagnosis = null;
- }
- }
- public void Dispose()
- {
- try
- {
- if (!_disposed)
- {
- Logger.Info($"AIDiagnosisService Start Dispose");
- CloseDiagnosis(AIEnumModuleType.Abdomen);
- CloseDiagnosis(AIEnumModuleType.Breast);
- CloseDiagnosis(AIEnumModuleType.Thyroid);
- CloseDiagnosis(AIEnumModuleType.Carotid);
- if (_singleImagePipeServerForAbdomen != null)
- {
- _singleImagePipeServerForAbdomen.DataReceived -= OnDataReceived;
- _singleImagePipeServerForAbdomen.Dispose();
- _singleImagePipeServerForAbdomen.LogMsgThrow -= OnLogMsgThrow;
- _singleImagePipeServerForAbdomen = null;
- }
- if (_imageProviderForAbdomen != null)
- {
- _imageProviderForAbdomen.Dispose();
- _imageProviderForAbdomen = null;
- }
- if (_singleImagePipeServerForBreast != null)
- {
- _singleImagePipeServerForBreast.DataReceived -= OnDataReceived;
- _singleImagePipeServerForBreast.Dispose();
- _singleImagePipeServerForBreast.LogMsgThrow -= OnLogMsgThrow;
- _singleImagePipeServerForBreast = null;
- }
- if (_imageProviderForBreast != null)
- {
- _imageProviderForBreast.Dispose();
- _imageProviderForBreast = null;
- }
- if (_singleImagePipeServerForThyroid != null)
- {
- _singleImagePipeServerForThyroid.DataReceived -= OnDataReceived;
- _singleImagePipeServerForThyroid.Dispose();
- _singleImagePipeServerForThyroid.LogMsgThrow -= OnLogMsgThrow;
- _singleImagePipeServerForThyroid = null;
- }
- if (_imageProviderForThyroid != null)
- {
- _imageProviderForThyroid.Dispose();
- _imageProviderForThyroid = null;
- }
- if (_singleImagePipeServerForCarotid != null)
- {
- _singleImagePipeServerForCarotid.DataReceived -= OnDataReceived;
- _singleImagePipeServerForCarotid.Dispose();
- _singleImagePipeServerForCarotid.LogMsgThrow -= OnLogMsgThrow;
- _singleImagePipeServerForCarotid = null;
- }
- if (_imageProviderForCarotid != null)
- {
- _imageProviderForCarotid.Dispose();
- _imageProviderForCarotid = null;
- }
- _disposed = true;
- Logger.Info($"AIDiagnosisService Dispose End");
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-Dispose error:{ex}");
- }
- }
- /// <summary>
- /// Send Raw Image Data For Pipe
- /// </summary>
- /// <param name="length"></param>
- /// <param name="height"></param>
- /// <param name="width"></param>
- /// <param name="colorType"></param>
- public void SendRawImageData(AIEnumModuleType type, int height, int width, AIEnumColorType colorType)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- _imageProviderForAbdomen?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
- break;
- case AIEnumModuleType.Breast:
- _imageProviderForBreast?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
- break;
- case AIEnumModuleType.Thyroid:
- _imageProviderForThyroid?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
- break;
- case AIEnumModuleType.Carotid:
- _imageProviderForCarotid?.ReceiveRawImageData(height, width, (EnumColorType)colorType);
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SendRawImageData error:{ex}");
- }
- }
- /// <summary>
- /// Send Byte Image Data For Pipe
- /// </summary>
- /// <param name="length"></param>
- public void SendByteImageData(AIEnumModuleType type)
- {
- try
- {
- switch (type)
- {
- case AIEnumModuleType.Abdomen:
- _imageProviderForAbdomen?.ReceiveByteImageData();
- break;
- case AIEnumModuleType.Breast:
- _imageProviderForBreast?.ReceiveByteImageData();
- break;
- case AIEnumModuleType.Thyroid:
- _imageProviderForThyroid?.ReceiveByteImageData();
- break;
- case AIEnumModuleType.Carotid:
- _imageProviderForCarotid?.ReceiveByteImageData();
- break;
- }
- }
- catch (Exception ex)
- {
- Logger.Error($"AIDiagnosisService-SendByteImageData error:{ex}");
- }
- }
- }
- }
|