From 9668f8f3ac78915e9815f108549deede84637f2a Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Tue, 30 Jun 2020 10:15:15 +0700 Subject: [PATCH] Util - Add Extensition Methods: UpdateImage, UpdateLabel --- AIParkingApplication/LaneIn.cs | 49 +++---------------- AIParkingApplication/LaneIn.resx | 42 ++++++++++++++++ AIParkingApplication/LaneOut.cs | 10 +--- .../Properties/AssemblyInfo.cs | 1 - AIParkingApplication/Statistic.cs | 1 - AIParkingApplication/Util.cs | 20 ++++++++ 6 files changed, 71 insertions(+), 52 deletions(-) diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index 64ba662..108938d 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -67,18 +67,10 @@ namespace AIParkingApplication var plateVideoFrame = plateCamera.CurrentFrame; FinalPlateResult result = await ProcessFrameImage(plateProcessor, plateVideoFrame, isRetryMode); - pictureBoxPlateImage.Invoke(new Action(() => - { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = result.PlateImage.ToBitmap(); - })); + pictureBoxPlateImage.UpdateImage(result.PlateImage.ToBitmap()); var overviewVideoFrame = overviewCamera.CurrentFrame; - pictureBoxOverviewImage.Invoke(new Action(() => - { - pictureBoxOverviewImage.Image?.Dispose(); - pictureBoxOverviewImage.Image = overviewVideoFrame.ToBitmap(); - })); + pictureBoxOverviewImage.UpdateImage(overviewVideoFrame.ToBitmap()); var cardInformation = await apiController.GetCardInformation(cardNumber); ShowCardInfoOnUI(cardNumber, result.PlateString, cardInformation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); @@ -121,35 +113,18 @@ namespace AIParkingApplication private void PlateCamera_OnOpenVideoStreamFailed(Mat videoFrame) { - pictureBoxPlateVideo.Invoke(new Action(() => - { - pictureBoxPlateVideo.Image?.Dispose(); - pictureBoxPlateVideo.Image = videoFrame.ToBitmap(); - })); + pictureBoxPlateVideo.UpdateImage(videoFrame.ToBitmap()); } private void OverviewCamera_OnOpenVideoStreamFailed(Mat videoFrame) { - pictureBoxOverviewVideo.Invoke(new Action(() => - { - pictureBoxOverviewImage.Image?.Dispose(); - pictureBoxOverviewVideo.Image = videoFrame.ToBitmap(); - })); + pictureBoxOverviewVideo.UpdateImage(videoFrame.ToBitmap()); } private void ClearPlateAndOverviewImage() { - pictureBoxPlateImage.Invoke(new Action(() => - { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = null; - })); - - pictureBoxOverviewImage.Invoke(new Action(() => - { - pictureBoxOverviewImage.Image?.Dispose(); - pictureBoxOverviewImage.Image = null; - })); + pictureBoxPlateImage.UpdateImage(null); + pictureBoxOverviewImage.UpdateImage(null); } private void OpenDoor(int doorId) @@ -237,11 +212,7 @@ namespace AIParkingApplication { try { - pictureBoxOverviewVideo.Invoke(new Action(() => - { - pictureBoxOverviewVideo.Image?.Dispose(); - pictureBoxOverviewVideo.Image = videoFrame.ToBitmap(); - })); + pictureBoxOverviewVideo.UpdateImage(videoFrame.ToBitmap()); } catch (Exception ex) { @@ -253,11 +224,7 @@ namespace AIParkingApplication { try { - pictureBoxPlateVideo.Invoke(new Action(() => - { - pictureBoxPlateVideo.Image?.Dispose(); - pictureBoxPlateVideo.Image = videoFrame.ToBitmap(); - })); + pictureBoxPlateVideo.UpdateImage(videoFrame.ToBitmap()); } catch (Exception ex) { diff --git a/AIParkingApplication/LaneIn.resx b/AIParkingApplication/LaneIn.resx index 1af7de1..17cd4f2 100644 --- a/AIParkingApplication/LaneIn.resx +++ b/AIParkingApplication/LaneIn.resx @@ -117,4 +117,46 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/AIParkingApplication/LaneOut.cs b/AIParkingApplication/LaneOut.cs index 7f29345..3a1ae95 100644 --- a/AIParkingApplication/LaneOut.cs +++ b/AIParkingApplication/LaneOut.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; namespace AIParkingApplication { diff --git a/AIParkingApplication/Properties/AssemblyInfo.cs b/AIParkingApplication/Properties/AssemblyInfo.cs index d11a5d1..281383a 100644 --- a/AIParkingApplication/Properties/AssemblyInfo.cs +++ b/AIParkingApplication/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/AIParkingApplication/Statistic.cs b/AIParkingApplication/Statistic.cs index e7f596b..1d27a22 100644 --- a/AIParkingApplication/Statistic.cs +++ b/AIParkingApplication/Statistic.cs @@ -3,7 +3,6 @@ using System.Windows.Forms; using System.Threading; using Newtonsoft.Json; using System.Net.Http; -using System.Xml.Serialization; namespace AIParkingApplication { diff --git a/AIParkingApplication/Util.cs b/AIParkingApplication/Util.cs index 20d8ead..684dbd6 100644 --- a/AIParkingApplication/Util.cs +++ b/AIParkingApplication/Util.cs @@ -2,9 +2,11 @@ using OpenCvSharp; using System; using System.Diagnostics; +using System.Drawing; using System.Net.Http; using System.Net.NetworkInformation; using System.Threading.Tasks; +using System.Windows.Forms; namespace AIParkingApplication { @@ -74,6 +76,24 @@ namespace AIParkingApplication return new OcrResult(); } } + + public static void UpdateImage(this PictureBox pictureBox, Bitmap image) + { + pictureBox.Invoke(new Action(() => + { + pictureBox.Image?.Dispose(); + pictureBox.Image = image; + })); + } + + public static void UpdateLabel(this Label label, string text, Color color) + { + label.Invoke(new Action(() => + { + label.BackColor = color; + label.Text = text; + })); + } } public class PlateRequestEngineModel