From 2bd45cf43ff950edd4f0d099460257e7d6ea56e7 Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Fri, 19 Jun 2020 10:13:22 +0700 Subject: [PATCH] LaneIn - Add TryCatch For Methods: OverviewCamera_OnOneVideoFrameRequested, PlateCamera_OnOneVideoFrameRequested, OverviewCameraOnVideoFrameReceived, PlateCameraOnVideoFrameReceived --- AIParkingApplication/LaneIn.cs | 73 ++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index 85d33a8..9606294 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -15,7 +15,8 @@ namespace AIParkingApplication public LaneIn() { InitializeComponent(); - string overviewCameraVideo = @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; //@"C:\HS_test.mp4" + string overviewCameraVideo = @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; + //string overviewCameraVideo = @"C:\HS_test.mp4"; string plateCameraVideo = @"C:\HS_test.mp4"; //string plateCameraVideo = @"C:\CongRa_1.mp4"; @@ -36,48 +37,76 @@ namespace AIParkingApplication private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame) { - pictureBoxOverviewImage.Invoke(new Action(() => + try { - pictureBoxOverviewImage.Image?.Dispose(); - pictureBoxOverviewImage.Image = videoFrame.ToBitmap(); - })); + pictureBoxOverviewImage.Invoke(new Action(() => + { + pictureBoxOverviewImage.Image?.Dispose(); + pictureBoxOverviewImage.Image = videoFrame.ToBitmap(); + })); + } + catch (Exception ex) + { + Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}"); + } } private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) { Task.Factory.StartNew(new Action(async () => { - var finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); - - lblPlateString.Invoke(new Action(() => + try { - lblPlateString.Text = finalPlateResult.PlateString; - })); + var finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); - pictureBoxPlateImage.Invoke(new Action(() => + lblPlateString.Invoke(new Action(() => + { + lblPlateString.Text = finalPlateResult.PlateString; + })); + + pictureBoxPlateImage.Invoke(new Action(() => + { + pictureBoxPlateImage.Image?.Dispose(); + pictureBoxPlateImage.Image = finalPlateResult.PlateImage; + })); + } + catch (Exception ex) { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = finalPlateResult.PlateImage; - })); + Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}"); + } })); } private void OverviewCameraOnVideoFrameReceived(Mat videoFrame) { - pictureBoxOverviewVideo.Invoke(new Action(() => + try { - pictureBoxOverviewVideo.Image?.Dispose(); - pictureBoxOverviewVideo.Image = videoFrame.ToBitmap(); - })); + pictureBoxOverviewVideo.Invoke(new Action(() => + { + pictureBoxOverviewVideo.Image?.Dispose(); + pictureBoxOverviewVideo.Image = videoFrame.ToBitmap(); + })); + } + catch (Exception ex) + { + Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}"); + } } private void PlateCameraOnVideoFrameReceived(Mat videoFrame) { - pictureBoxPlateVideo.Invoke(new Action(() => + try { - pictureBoxPlateVideo.Image?.Dispose(); - pictureBoxPlateVideo.Image = videoFrame.ToBitmap(); - })); + pictureBoxPlateVideo.Invoke(new Action(() => + { + pictureBoxPlateVideo.Image?.Dispose(); + pictureBoxPlateVideo.Image = videoFrame.ToBitmap(); + })); + } + catch (Exception ex) + { + Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}"); + } } private void CaptureAllCamera()