From 7529efa6d2d50903b168964c8d9e5b0a35cfaec1 Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Thu, 25 Jun 2020 11:03:03 +0700 Subject: [PATCH] LaneIn - Remove using Task For Event: PlateCamera_OnOneVideoFrameRequested --- AIParkingApplication/LaneIn.cs | 59 ++++++++++++++++------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index b1da451..184bc53 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -106,45 +106,42 @@ namespace AIParkingApplication } } - private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) + private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) { - Task.Factory.StartNew(new Action(async () => + try { - try - { - //TODO: check size before resizing - Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720)); - FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); + //TODO: check size before resizing + Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720)); + FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); - if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString)) + if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString)) + { + if (isRetryModeUntilOk) //TODO: TestMode { - if (isRetryModeUntilOk) //TODO: TestMode - { - Thread.Sleep(500); - CaptureAllCamera(); - } - else - { - Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode"); - Thread.Sleep(1000); - overviewCamera.RequestCaptureOneFrame(); - finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); - } + Thread.Sleep(500); + CaptureAllCamera(); } - - pictureBoxPlateImage.Invoke(new Action(() => + else { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = finalPlateResult.PlateImage; - })); + Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode"); + Thread.Sleep(1000); + overviewCamera.RequestCaptureOneFrame(); + finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); + } + } - ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); - } - catch (Exception ex) + pictureBoxPlateImage.Invoke(new Action(() => { - Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}"); - } - })); + pictureBoxPlateImage.Image?.Dispose(); + pictureBoxPlateImage.Image = finalPlateResult.PlateImage; + })); + + ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); + } + catch (Exception ex) + { + Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}"); + } } public void Stop()