Compare commits
No commits in common. "b8e88aaafe18752332b2777a1c68122bb98fe5a5" and "b3517e90eaa4d3bb2fa3294b0c35a910c3a50de5" have entirely different histories.
b8e88aaafe
...
b3517e90ea
|
@ -8,10 +8,8 @@ namespace AIParkingApplication
|
||||||
public AIParkingApplicationForm()
|
public AIParkingApplicationForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
string serverBaseAddress = "http://localhost:80/";
|
|
||||||
ApiController apiController = new ApiController(serverBaseAddress);
|
|
||||||
C3DeviceController c3Device = new C3DeviceController("192.168.1.200");
|
C3DeviceController c3Device = new C3DeviceController("192.168.1.200");
|
||||||
LaneIn laneIn = new LaneIn(1, @"C:\HS_test.mp4", @"C:\HS_test.mp4", c3Device, apiController, true, false, true);
|
LaneIn laneIn = new LaneIn(1, @"C:\HS_test.mp4", @"C:\HS_test.mp4", c3Device, true, false, true);
|
||||||
//LaneIn laneOut = new LaneIn();
|
//LaneIn laneOut = new LaneIn();
|
||||||
Controls.Add(laneIn);
|
Controls.Add(laneIn);
|
||||||
laneIn.Start();
|
laneIn.Start();
|
||||||
|
|
|
@ -195,7 +195,7 @@ namespace AIParkingApplication
|
||||||
public class CardValidation
|
public class CardValidation
|
||||||
{
|
{
|
||||||
[JsonProperty("status")]
|
[JsonProperty("status")]
|
||||||
public bool IsValid { get; set; }
|
public string IsValid { get; set; }
|
||||||
|
|
||||||
[JsonProperty("type")]
|
[JsonProperty("type")]
|
||||||
public string Direction { get; set; }
|
public string Direction { get; set; }
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace AIParkingApplication
|
||||||
private string streamUrl;
|
private string streamUrl;
|
||||||
private volatile bool isFrameRequested;
|
private volatile bool isFrameRequested;
|
||||||
private Thread readStreamThread;
|
private Thread readStreamThread;
|
||||||
public volatile Mat CurrentFrame;
|
|
||||||
|
|
||||||
public event CameraEvent OnVideoFrameReceived;
|
public event CameraEvent OnVideoFrameReceived;
|
||||||
public event CameraEvent OnOneVideoFrameRequested;
|
public event CameraEvent OnOneVideoFrameRequested;
|
||||||
|
@ -64,7 +63,6 @@ namespace AIParkingApplication
|
||||||
OnVideoFrameReceived?.Invoke(videoFrame);
|
OnVideoFrameReceived?.Invoke(videoFrame);
|
||||||
if (isFrameRequested)
|
if (isFrameRequested)
|
||||||
{
|
{
|
||||||
CurrentFrame = videoFrame;
|
|
||||||
OnOneVideoFrameRequested?.Invoke(videoFrame);
|
OnOneVideoFrameRequested?.Invoke(videoFrame);
|
||||||
isFrameRequested = false;
|
isFrameRequested = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
@ -20,13 +19,11 @@ namespace AIParkingApplication
|
||||||
private bool isRetryMode;
|
private bool isRetryMode;
|
||||||
private bool isRetryModeUntilOk; //TODO: Test mode
|
private bool isRetryModeUntilOk; //TODO: Test mode
|
||||||
private C3DeviceController c3Device;
|
private C3DeviceController c3Device;
|
||||||
private ApiController apiController;
|
|
||||||
|
|
||||||
public LaneIn(int doorId,
|
public LaneIn(int doorId,
|
||||||
string plateStream,
|
string plateStream,
|
||||||
string overviewStream,
|
string overviewStream,
|
||||||
C3DeviceController c3Device,
|
C3DeviceController c3Device,
|
||||||
ApiController apiController,
|
|
||||||
bool isSupportSquarePlate = true,
|
bool isSupportSquarePlate = true,
|
||||||
bool isSupportLongPlate = false,
|
bool isSupportLongPlate = false,
|
||||||
bool isAutoOpenDoor = true,
|
bool isAutoOpenDoor = true,
|
||||||
|
@ -35,7 +32,6 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.doorId = doorId;
|
this.doorId = doorId;
|
||||||
|
|
||||||
this.isSupportSquarePlate = isSupportSquarePlate;
|
this.isSupportSquarePlate = isSupportSquarePlate;
|
||||||
this.isSupportLongPlate = isSupportLongPlate;
|
this.isSupportLongPlate = isSupportLongPlate;
|
||||||
this.isAutoOpenDoor = isAutoOpenDoor;
|
this.isAutoOpenDoor = isAutoOpenDoor;
|
||||||
|
@ -43,7 +39,6 @@ namespace AIParkingApplication
|
||||||
this.isRetryModeUntilOk = isRetryModeUntilOk;
|
this.isRetryModeUntilOk = isRetryModeUntilOk;
|
||||||
overviewCamera = new Camera(overviewStream);
|
overviewCamera = new Camera(overviewStream);
|
||||||
plateCamera = new Camera(plateStream);
|
plateCamera = new Camera(plateStream);
|
||||||
this.apiController = apiController;
|
|
||||||
this.c3Device = c3Device;
|
this.c3Device = c3Device;
|
||||||
this.c3Device.OnNewCardReceived += C3Device_OnNewCardReceived;
|
this.c3Device.OnNewCardReceived += C3Device_OnNewCardReceived;
|
||||||
|
|
||||||
|
@ -63,42 +58,18 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
|
private void C3Device_OnNewCardReceived(int doorId, string cardNumber)
|
||||||
{
|
{
|
||||||
var cardInfoResult = await apiController.CheckCard(cardNumber);
|
//Request To Capture And Process Frame.
|
||||||
if (cardInfoResult.IsValid)
|
CaptureAllCamera();
|
||||||
|
//Request Card Info
|
||||||
|
if (isAutoOpenDoor)
|
||||||
{
|
{
|
||||||
plateCamera.RequestCaptureOneFrame();
|
if (this.doorId == doorId)
|
||||||
await Task.Delay(500);
|
|
||||||
var videoFrame = plateCamera.CurrentFrame;
|
|
||||||
|
|
||||||
FinalPlateResult result = await ProcessFrameImage(plateProcessor, videoFrame, isRetryMode, isRetryModeUntilOk);
|
|
||||||
pictureBoxPlateImage.Invoke(new Action(() =>
|
|
||||||
{
|
{
|
||||||
pictureBoxPlateImage.Image?.Dispose();
|
c3Device.OpenDoor(doorId);
|
||||||
pictureBoxPlateImage.Image = result.PlateImage;
|
|
||||||
}));
|
|
||||||
|
|
||||||
var cardValidation = await apiController.CheckCard(cardNumber);
|
|
||||||
|
|
||||||
ShowCardInfoOnUI(cardNumber, result.PlateString, cardValidation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
|
|
||||||
|
|
||||||
if (isAutoOpenDoor)
|
|
||||||
{
|
|
||||||
if (this.doorId == doorId)
|
|
||||||
{
|
|
||||||
c3Device.OpenDoor(doorId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
lblRecogizePlateStatus.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
lblRecogizePlateStatus.BackColor = Color.Purple;
|
|
||||||
lblRecogizePlateStatus.Text = "THẺ KHÔNG HỢP LỆ";
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlateCamera_OnOpenVideoStreamFailed(Mat videoFrame)
|
private void PlateCamera_OnOpenVideoStreamFailed(Mat videoFrame)
|
||||||
|
@ -135,13 +106,13 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<FinalPlateResult> ProcessFrameImage(PlateProcessor plateProcessor, Mat frame, bool isRetryMode, bool isRetryModeUntilOk)
|
private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//TODO: check size before resizing
|
//TODO: check size before resizing
|
||||||
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
|
Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720));
|
||||||
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame);
|
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
||||||
|
|
||||||
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
|
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
|
||||||
{
|
{
|
||||||
|
@ -152,35 +123,27 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("ProcessFrameImage Retry Mode");
|
Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode");
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
overviewCamera.RequestCaptureOneFrame();
|
overviewCamera.RequestCaptureOneFrame();
|
||||||
finalPlateResult = await plateProcessor.ProcessPlate(frame);
|
finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return finalPlateResult;
|
|
||||||
|
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
pictureBoxPlateImage.Image?.Dispose();
|
||||||
|
pictureBoxPlateImage.Image = finalPlateResult.PlateImage;
|
||||||
|
}));
|
||||||
|
|
||||||
|
ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}");
|
Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}");
|
||||||
return new FinalPlateResult
|
|
||||||
{
|
|
||||||
PlateImage = frame.ToBitmap(),
|
|
||||||
PlateString = string.Empty
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
|
||||||
{
|
|
||||||
//FinalPlateResult result = await ProcessFrameImage(plateProcessor, videoFrame, isRetryMode, isRetryModeUntilOk);
|
|
||||||
//pictureBoxPlateImage.Invoke(new Action(() =>
|
|
||||||
//{
|
|
||||||
// pictureBoxPlateImage.Image?.Dispose();
|
|
||||||
// pictureBoxPlateImage.Image = result.PlateImage;
|
|
||||||
//}));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
plateCamera.Stop();
|
plateCamera.Stop();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user