Project - Add CantConnectCamera.jpg. AppConstant: Add CAMERA_FAILED_IMAGE_PATH. Camera: Add Event OnOpenVideoStreamFailed. LaneIn: Add Event handler for OnOpenVideoStreamFailed

This commit is contained in:
DucDangAnh 2020-06-22 10:17:06 +07:00
parent 8a8e8c8481
commit 7880d5bced
7 changed files with 73 additions and 5 deletions

View File

@ -139,6 +139,9 @@
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Images\CantConnectCamera.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="plate.xml"> <Content Include="plate.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -146,6 +149,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>

View File

@ -28,13 +28,37 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout(); 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 // AIParkingApplicationForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1350, 729); 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.MinimumSize = new System.Drawing.Size(1366, 768);
this.Name = "AIParkingApplicationForm"; this.Name = "AIParkingApplicationForm";
this.Text = "AIParking Application"; this.Text = "AIParking Application";
@ -43,6 +67,9 @@
} }
#endregion #endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
} }
} }

View File

@ -4,14 +4,26 @@ namespace AIParkingApplication
{ {
public partial class AIParkingApplicationForm : Form 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() public AIParkingApplicationForm()
{ {
InitializeComponent(); 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(); //LaneIn laneOut = new LaneIn();
Controls.Add(laneIn); Controls.Add(laneIn);
//laneOut.Location = new System.Drawing.Point(550, 0); //laneOut.Location = new System.Drawing.Point(550, 0);
//Controls.Add(laneOut); //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();
}
} }
} }

View File

@ -7,5 +7,7 @@
public const string ERROR_TITLE = "Lỗi"; public const string ERROR_TITLE = "Lỗi";
public const string DATETIME_FORMAT = "HH:mm:ss dd/MM/yyyy"; public const string DATETIME_FORMAT = "HH:mm:ss dd/MM/yyyy";
#endregion #endregion
public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg";
} }
} }

View File

@ -4,6 +4,7 @@ using System.Threading;
namespace AIParkingApplication namespace AIParkingApplication
{ {
public delegate void CameraEvent(Mat videoFrame); public delegate void CameraEvent(Mat videoFrame);
public class Camera public class Camera
{ {
private string streamUrl; private string streamUrl;
@ -12,6 +13,7 @@ namespace AIParkingApplication
public event CameraEvent OnVideoFrameReceived; public event CameraEvent OnVideoFrameReceived;
public event CameraEvent OnOneVideoFrameRequested; public event CameraEvent OnOneVideoFrameRequested;
public event CameraEvent OnOpenVideoStreamFailed;
public Camera(string streamUrl) public Camera(string streamUrl)
{ {
@ -43,10 +45,11 @@ namespace AIParkingApplication
public void ReadVideoStream() public void ReadVideoStream()
{ {
VideoCapture videoCapture = new VideoCapture(); VideoCapture videoCapture = new VideoCapture(); //TODO: Need to dispose this videoCapture?
Mat videoFrame = new Mat(); Mat videoFrame = new Mat();
if (!videoCapture.Open(streamUrl)) if (!videoCapture.Open(streamUrl))
{ {
OnOpenVideoStreamFailed?.Invoke(Cv2.ImRead(AppConstant.CAMERA_FAILED_IMAGE_PATH));
return; return;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -1,9 +1,9 @@
using OpenCvSharp; using System;
using OpenCvSharp.Extensions;
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using OpenCvSharp;
using OpenCvSharp.Extensions;
namespace AIParkingApplication namespace AIParkingApplication
{ {
@ -29,13 +29,33 @@ namespace AIParkingApplication
plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived; plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived;
plateCamera.OnOneVideoFrameRequested += PlateCamera_OnOneVideoFrameRequested; plateCamera.OnOneVideoFrameRequested += PlateCamera_OnOneVideoFrameRequested;
plateCamera.OnOpenVideoStreamFailed += PlateCamera_OnOpenVideoStreamFailed;
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived; overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested; overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate); 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) private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame)
{ {
try try