LaneIn - Add TryCatch For Methods: OverviewCamera_OnOneVideoFrameRequested, PlateCamera_OnOneVideoFrameRequested, OverviewCameraOnVideoFrameReceived, PlateCameraOnVideoFrameReceived

This commit is contained in:
DucDangAnh 2020-06-19 10:13:22 +07:00
parent 2caffc6adf
commit 2bd45cf43f

View File

@ -15,7 +15,8 @@ namespace AIParkingApplication
public LaneIn() public LaneIn()
{ {
InitializeComponent(); 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:\HS_test.mp4";
//string plateCameraVideo = @"C:\CongRa_1.mp4"; //string plateCameraVideo = @"C:\CongRa_1.mp4";
@ -36,48 +37,76 @@ namespace AIParkingApplication
private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame) private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame)
{ {
pictureBoxOverviewImage.Invoke(new Action(() => try
{ {
pictureBoxOverviewImage.Image?.Dispose(); pictureBoxOverviewImage.Invoke(new Action(() =>
pictureBoxOverviewImage.Image = videoFrame.ToBitmap(); {
})); pictureBoxOverviewImage.Image?.Dispose();
pictureBoxOverviewImage.Image = videoFrame.ToBitmap();
}));
}
catch (Exception ex)
{
Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
}
} }
private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
{ {
Task.Factory.StartNew(new Action(async () => Task.Factory.StartNew(new Action(async () =>
{ {
var finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); try
lblPlateString.Invoke(new Action(() =>
{ {
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(); Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
pictureBoxPlateImage.Image = finalPlateResult.PlateImage; }
}));
})); }));
} }
private void OverviewCameraOnVideoFrameReceived(Mat videoFrame) private void OverviewCameraOnVideoFrameReceived(Mat videoFrame)
{ {
pictureBoxOverviewVideo.Invoke(new Action(() => try
{ {
pictureBoxOverviewVideo.Image?.Dispose(); pictureBoxOverviewVideo.Invoke(new Action(() =>
pictureBoxOverviewVideo.Image = videoFrame.ToBitmap(); {
})); pictureBoxOverviewVideo.Image?.Dispose();
pictureBoxOverviewVideo.Image = videoFrame.ToBitmap();
}));
}
catch (Exception ex)
{
Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
}
} }
private void PlateCameraOnVideoFrameReceived(Mat videoFrame) private void PlateCameraOnVideoFrameReceived(Mat videoFrame)
{ {
pictureBoxPlateVideo.Invoke(new Action(() => try
{ {
pictureBoxPlateVideo.Image?.Dispose(); pictureBoxPlateVideo.Invoke(new Action(() =>
pictureBoxPlateVideo.Image = videoFrame.ToBitmap(); {
})); pictureBoxPlateVideo.Image?.Dispose();
pictureBoxPlateVideo.Image = videoFrame.ToBitmap();
}));
}
catch (Exception ex)
{
Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
}
} }
private void CaptureAllCamera() private void CaptureAllCamera()