diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index 184bc53..98fc01e 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -106,13 +106,13 @@ namespace AIParkingApplication } } - private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) + private async Task ProcessFrameImage(Mat frame, bool isRetryMode, bool isRetryModeUntilOk) { try { //TODO: check size before resizing - Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720)); - FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); + Cv2.Resize(frame, frame, new Size(1280, 720)); + FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame); if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString)) { @@ -123,27 +123,36 @@ namespace AIParkingApplication } else { - Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode"); + Console.WriteLine("ProcessFrameImage Retry Mode"); Thread.Sleep(1000); overviewCamera.RequestCaptureOneFrame(); - finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); + finalPlateResult = await plateProcessor.ProcessPlate(frame); } } - - pictureBoxPlateImage.Invoke(new Action(() => - { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = finalPlateResult.PlateImage; - })); - - ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); + return finalPlateResult; } catch (Exception ex) { - Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}"); + Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}"); + return new FinalPlateResult + { + PlateImage = frame.ToBitmap(), + PlateString = string.Empty + }; } } + private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) + { + FinalPlateResult result = await ProcessFrameImage(videoFrame, isRetryMode, isRetryModeUntilOk); + pictureBoxPlateImage.Invoke(new Action(() => + { + pictureBoxPlateImage.Image?.Dispose(); + pictureBoxPlateImage.Image = result.PlateImage; + })); + ShowCardInfoOnUI("224", result.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); + } + public void Stop() { plateCamera.Stop();