diff --git a/AIParkingApplication/AIParkingApplication.csproj b/AIParkingApplication/AIParkingApplication.csproj index de9bf7d..29788a1 100644 --- a/AIParkingApplication/AIParkingApplication.csproj +++ b/AIParkingApplication/AIParkingApplication.csproj @@ -139,6 +139,9 @@ + + PreserveNewest + PreserveNewest @@ -146,6 +149,7 @@ PreserveNewest + diff --git a/AIParkingApplication/AIParkingApplicationForm.Designer.cs b/AIParkingApplication/AIParkingApplicationForm.Designer.cs index 7344900..6c3bde7 100644 --- a/AIParkingApplication/AIParkingApplicationForm.Designer.cs +++ b/AIParkingApplication/AIParkingApplicationForm.Designer.cs @@ -28,13 +28,37 @@ /// private void InitializeComponent() { + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // + // button1 + // + this.button1.Location = new System.Drawing.Point(840, 223); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 0; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(840, 267); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 0; + this.button2.Text = "button1"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // // AIParkingApplicationForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1350, 729); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); this.MinimumSize = new System.Drawing.Size(1366, 768); this.Name = "AIParkingApplicationForm"; this.Text = "AIParking Application"; @@ -43,6 +67,9 @@ } #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; } } diff --git a/AIParkingApplication/AIParkingApplicationForm.cs b/AIParkingApplication/AIParkingApplicationForm.cs index f0f794c..5440bba 100644 --- a/AIParkingApplication/AIParkingApplicationForm.cs +++ b/AIParkingApplication/AIParkingApplicationForm.cs @@ -4,14 +4,26 @@ namespace AIParkingApplication { public partial class AIParkingApplicationForm : Form { + //@"C:\CongRa_1.mp4"; @"C:\HS_test.mp4"; @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" + LaneIn laneIn = new LaneIn(@"C:\HS_test.mp4", @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov", true, false, false); public AIParkingApplicationForm() { InitializeComponent(); - LaneIn laneIn = new LaneIn(@"C:\HS_test.mp4", @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov", true, true); //@"C:\CongRa_1.mp4"; + //LaneIn laneOut = new LaneIn(); Controls.Add(laneIn); //laneOut.Location = new System.Drawing.Point(550, 0); //Controls.Add(laneOut); } + + private void button1_Click(object sender, System.EventArgs e) + { + laneIn.Stop(); + } + + private void button2_Click(object sender, System.EventArgs e) + { + laneIn.Start(); + } } } diff --git a/AIParkingApplication/AppConstant.cs b/AIParkingApplication/AppConstant.cs index d189532..e447052 100644 --- a/AIParkingApplication/AppConstant.cs +++ b/AIParkingApplication/AppConstant.cs @@ -7,5 +7,7 @@ public const string ERROR_TITLE = "Lỗi"; public const string DATETIME_FORMAT = "HH:mm:ss dd/MM/yyyy"; #endregion + + public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg"; } } diff --git a/AIParkingApplication/Camera.cs b/AIParkingApplication/Camera.cs index c162a69..e523295 100644 --- a/AIParkingApplication/Camera.cs +++ b/AIParkingApplication/Camera.cs @@ -4,6 +4,7 @@ using System.Threading; namespace AIParkingApplication { public delegate void CameraEvent(Mat videoFrame); + public class Camera { private string streamUrl; @@ -12,6 +13,7 @@ namespace AIParkingApplication public event CameraEvent OnVideoFrameReceived; public event CameraEvent OnOneVideoFrameRequested; + public event CameraEvent OnOpenVideoStreamFailed; public Camera(string streamUrl) { @@ -43,10 +45,11 @@ namespace AIParkingApplication public void ReadVideoStream() { - VideoCapture videoCapture = new VideoCapture(); + VideoCapture videoCapture = new VideoCapture(); //TODO: Need to dispose this videoCapture? Mat videoFrame = new Mat(); if (!videoCapture.Open(streamUrl)) { + OnOpenVideoStreamFailed?.Invoke(Cv2.ImRead(AppConstant.CAMERA_FAILED_IMAGE_PATH)); return; } diff --git a/AIParkingApplication/Images/CantConnectCamera.jpg b/AIParkingApplication/Images/CantConnectCamera.jpg new file mode 100644 index 0000000..769218f Binary files /dev/null and b/AIParkingApplication/Images/CantConnectCamera.jpg differ diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index b4d244a..f9fbaab 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -1,9 +1,9 @@ -using OpenCvSharp; -using OpenCvSharp.Extensions; -using System; +using System; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using OpenCvSharp; +using OpenCvSharp.Extensions; namespace AIParkingApplication { @@ -29,13 +29,33 @@ namespace AIParkingApplication plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived; plateCamera.OnOneVideoFrameRequested += PlateCamera_OnOneVideoFrameRequested; + plateCamera.OnOpenVideoStreamFailed += PlateCamera_OnOpenVideoStreamFailed; overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived; overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested; + overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed; plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate); } + private void PlateCamera_OnOpenVideoStreamFailed(Mat videoFrame) + { + pictureBoxPlateVideo.Invoke(new Action(() => + { + pictureBoxPlateVideo.Image?.Dispose(); + pictureBoxPlateVideo.Image = videoFrame.ToBitmap(); + })); + } + + private void OverviewCamera_OnOpenVideoStreamFailed(Mat videoFrame) + { + pictureBoxOverviewVideo.Invoke(new Action(() => + { + pictureBoxOverviewImage.Image?.Dispose(); + pictureBoxOverviewVideo.Image = videoFrame.ToBitmap(); + })); + } + private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame) { try