diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index f8ec612..6f58f56 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -3,6 +3,7 @@ using OpenCvSharp.Extensions; using System; using System.Drawing; using System.IO; +using System.Threading.Tasks; using System.Windows.Forms; namespace AIParkingApplication @@ -44,37 +45,38 @@ namespace AIParkingApplication private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) { - Cv2.Resize(videoFrame, videoFrame, new OpenCvSharp.Size(1280, 720)); - Mat result = squarePlateDetector.DetectPlate(videoFrame); - - Cv2.Resize(result, result, new OpenCvSharp.Size(272, 272)); - var response = Util.SendEngineRequestAsync(result, PlateType.Square); - - Bitmap resultPlateImage; - OcrResult ocrResult = response.Result; - if (!string.IsNullOrEmpty(ocrResult.Ocr) && !string.IsNullOrEmpty(ocrResult.Plate)) + Task.Factory.StartNew(new Action(async () => { - var imageData = Convert.FromBase64String(ocrResult.Plate); - using (var ms = new MemoryStream(imageData)) + Cv2.Resize(videoFrame, videoFrame, new OpenCvSharp.Size(1280, 720)); + Mat result = squarePlateDetector.DetectPlate(videoFrame); + + Cv2.Resize(result, result, new OpenCvSharp.Size(272, 272)); + OcrResult ocrResult = await Util.SendEngineRequestAsync(result, PlateType.Square); + + Bitmap resultPlateImage; + if (!string.IsNullOrEmpty(ocrResult.Ocr) && !string.IsNullOrEmpty(ocrResult.Plate)) { - resultPlateImage = new Bitmap(ms); + var imageData = Convert.FromBase64String(ocrResult.Plate); + using (var ms = new MemoryStream(imageData)) + { + resultPlateImage = new Bitmap(ms); + } + } + else + { + resultPlateImage = result.ToBitmap(); } - } - else - { - resultPlateImage = result.ToBitmap(); - } + lblPlateString.Invoke(new Action(() => + { + lblPlateString.Text = ocrResult.Ocr; + })); - lblPlateString.Invoke(new Action(() => - { - lblPlateString.Text = ocrResult.Ocr; - })); - - pictureBoxPlateImage.Invoke(new Action(() => - { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = resultPlateImage; + pictureBoxPlateImage.Invoke(new Action(() => + { + pictureBoxPlateImage.Image?.Dispose(); + pictureBoxPlateImage.Image = resultPlateImage; + })); })); }