Browse Source

颈动脉调整

Jeremy 2 years ago
parent
commit
0c6a6fb790
1 changed files with 57 additions and 3 deletions
  1. 57 3
      Service/AIDiagnosisService.cs

+ 57 - 3
Service/AIDiagnosisService.cs

@@ -9,11 +9,8 @@ using Vinno.vCloud.Common.Vid2;
 using WingAIDiagnosisService.Manage;
 using WingAIDiagnosisService.Carotid;
 using Newtonsoft.Json;
-using Emgu.CV;
-using Emgu.CV.CvEnum;
 using AI.DiagSystem;
 using WingServerCommon.Log;
-using Emgu.CV.Structure;
 using System.IO;
 using System;
 using System.Threading.Tasks;
@@ -30,6 +27,9 @@ using WingInterfaceLibrary.Result.AIDiagnosis;
 using WingInterfaceLibrary.Request.AIDiagnosis;
 using WingInterfaceLibrary.DTO.Record;
 using WingInterfaceLibrary.DTO.Comment;
+using Emgu.CV;
+using Emgu.CV.CvEnum;
+using Emgu.CV.Structure;
 
 namespace WingAIDiagnosisService.Service
 {
@@ -269,6 +269,20 @@ namespace WingAIDiagnosisService.Service
                     }
                     File.Delete(resampleInputData.PlaqueAIImagePath);
                 }
+                var surfaceImageList = new List<string>();
+                if (!string.IsNullOrWhiteSpace(resampleInputData.SurfaceFilePath) && File.Exists(resampleInputData.SurfaceFilePath))
+                {
+                    surfaceImageList = await SurfaceFile(resampleInputData.SurfaceFilePath);
+                    var fileUrl = await UploadFileAsync(resampleInputData.SurfaceFilePath, Path.GetFileName(resampleInputData.SurfaceFilePath));
+                    File.Delete(resampleInputData.SurfaceFilePath);
+                    resampleInputData.SurfaceFilePath = fileUrl;
+                }
+                if (!string.IsNullOrWhiteSpace(resampleInputData.MdlFilePath) && File.Exists(resampleInputData.MdlFilePath))
+                {
+                    var fileUrl = await UploadFileAsync(resampleInputData.MdlFilePath, Path.GetFileName(resampleInputData.MdlFilePath));
+                    File.Delete(resampleInputData.MdlFilePath);
+                    resampleInputData.MdlFilePath = fileUrl;
+                }
 
                 var result = new CarotidResultDTO
                 {
@@ -278,6 +292,8 @@ namespace WingAIDiagnosisService.Service
                     MdlFile = resampleInputData.MdlFilePath,
                     MeasureImageFiles = carotidAIImageTokens.Select(x => new MeasureImageFileDTO { ImageType = (CarotidAIImageTypeEnum)x.AIImageType, ImageFile = x.AIImageToken }).ToList(),
                     MeasureResult = JsonConvert.SerializeObject(resampleResult.CarotidAIMeasureResult),
+                    SurfaceImageList = surfaceImageList,
+
                 };
                 return result;
             }
@@ -322,6 +338,44 @@ namespace WingAIDiagnosisService.Service
             return resampleResult;
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="filePath"></param>
+        private async Task<List<string>> SurfaceFile(string filePath)
+        {
+            var fileUrls = new List<string>();
+            using (var stream = new FileStream(filePath, FileMode.Open))
+            {
+                var reader = new Carotid3DStreamReader(stream);
+                var width = reader.ReadInt();
+                var height = reader.ReadInt();
+                var depth = reader.ReadInt();
+                var physicalData = VinnoCarotid3DPhysicalData.FromBytes(reader.ReadBytes());
+                var imageCount = reader.ReadInt();
+                var fileName = $"{Guid.NewGuid():N}";
+                for (var i = 0; i < imageCount; i++)
+                {
+                    var readBytes = reader.ReadBytes();
+                    if (readBytes.Any())
+                    {
+                        using var img = new Mat();
+                        CvInvoke.Imdecode(readBytes, ImreadModes.Color, img);
+                        var buf = new Emgu.CV.Util.VectorOfByte();
+                        using var image = img.ToImage<Gray, byte>();
+                        CvInvoke.Imencode(".jpg", image, buf, new KeyValuePair<ImwriteFlags, int>(ImwriteFlags.JpegQuality, 80));
+                        var jpgByte = buf.ToArray();
+                        var localPath = Path.Combine(_tempFolder, $"{fileName}_{i + 1}.jpg");
+                        File.WriteAllBytes(localPath, jpgByte);
+                        var fileUrl = await UploadFileAsync(localPath, Path.GetFileName(localPath));
+                        fileUrls.Add(fileUrl);
+                        File.Delete(localPath);
+                    }
+                }
+            }
+            return fileUrls;
+        }
+
         private SKBitmap CreateBitmap(VinnoImage vinnoImage)
         {
             try