LaneIn - Make ProcessFrameImage Return Result.

This commit is contained in:
DucDangAnh 2020-06-25 16:36:20 +07:00
parent 059e79924c
commit 48e900b353

View File

@ -106,13 +106,13 @@ namespace AIParkingApplication
} }
} }
private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) private async Task<FinalPlateResult> ProcessFrameImage(Mat frame, bool isRetryMode, bool isRetryModeUntilOk)
{ {
try try
{ {
//TODO: check size before resizing //TODO: check size before resizing
Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720)); Cv2.Resize(frame, frame, new Size(1280, 720));
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame);
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString)) if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
{ {
@ -123,27 +123,36 @@ namespace AIParkingApplication
} }
else else
{ {
Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode"); Console.WriteLine("ProcessFrameImage Retry Mode");
Thread.Sleep(1000); Thread.Sleep(1000);
overviewCamera.RequestCaptureOneFrame(); overviewCamera.RequestCaptureOneFrame();
finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); finalPlateResult = await plateProcessor.ProcessPlate(frame);
} }
} }
return finalPlateResult;
pictureBoxPlateImage.Invoke(new Action(() =>
{
pictureBoxPlateImage.Image?.Dispose();
pictureBoxPlateImage.Image = finalPlateResult.PlateImage;
}));
ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
} }
catch (Exception ex) 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() public void Stop()
{ {
plateCamera.Stop(); plateCamera.Stop();