Compare commits

..

5 Commits

8 changed files with 126 additions and 31 deletions

View File

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

View File

@ -28,13 +28,37 @@
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -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";
}
}

View File

@ -1,11 +1,11 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace AIParkingApplication
{
public delegate void C3EventHandler(ActionResult actionResult);
public delegate void C3RTLogEventHandler(ActionResult actionResult, int doorId, string cardNumber);
public delegate void C3DeviceEvent(int doorId, string cardNumber);
public class C3DeviceController
{
@ -14,17 +14,10 @@ namespace AIParkingApplication
private IntPtr oneTimeConnectedParamHandler;
private string connectionString;
private bool isReconnected;
public event C3EventHandler OnConnected;
public event C3EventHandler OnConnectFailed;
public event C3EventHandler OnReconnect;
public event C3EventHandler OnDoorOpenned;
public event C3EventHandler OnDoorOpenFailed;
public event C3EventHandler OnPingFailed;
public event C3EventHandler OnDisconnected;
public event C3RTLogEventHandler OnGetRTLog;
public event C3EventHandler OnGetRTLogFailed;
private int reconnectCounter;
public event C3DeviceEvent OnNewCardReceived;
public C3DeviceController(string ipAddress, int port = C3Constant.DEFAULT_C3_PORT)
{
IPAddress = ipAddress;
@ -67,7 +60,6 @@ namespace AIParkingApplication
HasError = false,
Message = string.Format(C3Constant.CONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnConnected?.Invoke(result);
return result;
}
else
@ -77,7 +69,6 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_CONNECT, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress, PullLastError())
};
OnConnectFailed?.Invoke(result);
return result;
}
}
@ -88,8 +79,6 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnPingFailed?.Invoke(result);
OnConnectFailed?.Invoke(result);
return result;
}
}
@ -106,7 +95,6 @@ namespace AIParkingApplication
HasError = false,
Message = string.Format(C3Constant.OPENNED_DOOR_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnDoorOpenned?.Invoke(result);
return result;
}
else
@ -116,7 +104,6 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_OPEN_DOOR, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnDoorOpenFailed?.Invoke(result);
return result;
}
}
@ -127,11 +114,23 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.NOT_CONNECTTED, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnDoorOpenFailed?.Invoke(result);
return result;
}
}
public async Task GetLogToReceiveNewCard()
{
while (true)
{
await Task.Delay(1000);
ActionResult getRTLogResult = GetRTLog(out int doorId, out string cardNumber);
if (doorId != C3Constant.DEFAULT_DOOR_ID && cardNumber != C3Constant.DEFAULT_CARD_NUMBER)
{
OnNewCardReceived?.Invoke(doorId, cardNumber);
}
}
}
public ActionResult GetRTLog(out int doorId, out string cardNumber)
{
doorId = C3Constant.DEFAULT_DOOR_ID;
@ -145,7 +144,6 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_PING, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnPingFailed?.Invoke(result);
return result;
}
@ -167,7 +165,6 @@ namespace AIParkingApplication
{
HasError = false
};
OnGetRTLog?.Invoke(result, doorId, cardNumber);
return result;
}
else
@ -182,7 +179,6 @@ namespace AIParkingApplication
reconnectCounter = 0;
reconnectResult.Message = string.Format(C3Constant.RECONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress);
}
OnReconnect?.Invoke(reconnectResult);
return reconnectResult;
}
@ -191,7 +187,6 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.FAILED_TO_READ_LOG, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnGetRTLogFailed?.Invoke(result);
return result;
}
}
@ -204,7 +199,6 @@ namespace AIParkingApplication
HasError = true,
Message = string.Format(C3Constant.WRONG_FORMAT_DATA, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress, ex.Message)
};
OnGetRTLogFailed?.Invoke(result);
return result;
}
}
@ -218,7 +212,6 @@ namespace AIParkingApplication
HasError = false,
Message = string.Format(C3Constant.DISCONNECTED_SUCCESSFULLY, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), IPAddress)
};
OnDisconnected?.Invoke(result);
return result;
}
}

View File

@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -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
{
@ -12,28 +12,82 @@ namespace AIParkingApplication
private Camera overviewCamera;
private Camera plateCamera;
private PlateProcessor plateProcessor;
private int doorId;
private bool isSupportSquarePlate;
private bool isSupportLongPlate;
private bool isAutoOpenDoor;
private bool isRetryMode;
private bool isRetryModeUntilOk; //TODO: Test mode
private C3DeviceController c3Device;
public LaneIn(string plateStream, string overviewStream, bool isSupportSquarePlate = true, bool isSupportLongPlate = false, bool isRetryMode = false, bool isRetryModeUntilOk = false)
public LaneIn(int doorId,
string plateStream,
string overviewStream,
C3DeviceController c3Device,
bool isSupportSquarePlate = true,
bool isSupportLongPlate = false,
bool isAutoOpenDoor = true,
bool isRetryMode = false,
bool isRetryModeUntilOk = false)
{
InitializeComponent();
this.doorId = doorId;
this.isSupportSquarePlate = isSupportSquarePlate;
this.isSupportLongPlate = isSupportLongPlate;
this.isAutoOpenDoor = isAutoOpenDoor;
this.isRetryMode = isRetryMode;
this.isRetryModeUntilOk = isRetryModeUntilOk;
overviewCamera = new Camera(overviewStream);
plateCamera = new Camera(plateStream);
this.c3Device = c3Device;
this.c3Device.OnNewCardReceived += C3Device_OnNewCardReceived;
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);
if (!this.c3Device.Connect().HasError)
{
_ = this.c3Device.GetLogToReceiveNewCard();
}
}
private void C3Device_OnNewCardReceived(int doorId, string cardNumber)
{
//Request To Capture And Process Frame.
CaptureAllCamera();
//Request Card Info
if (isAutoOpenDoor)
{
if (this.doorId == doorId)
{
c3Device.OpenDoor(doorId);
}
}
}
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)
@ -126,7 +180,7 @@ namespace AIParkingApplication
{
lblCardTime.Text = $"Thời gian: {cardTime}";
}));
lblRecogizePlateStatus.Invoke(new Action(() =>
{
lblRecogizePlateStatus.Text = string.IsNullOrEmpty(plateString) ? "KHÔNG NHẬN DIỆN ĐƯỢC BIỂN SỐ" : $"MỜI XE {plateString} VÀO";