diff --git a/AIParkingApplication/AIParkingApplicationForm.cs b/AIParkingApplication/AIParkingApplicationForm.cs index 4e0141e..55e39f8 100644 --- a/AIParkingApplication/AIParkingApplicationForm.cs +++ b/AIParkingApplication/AIParkingApplicationForm.cs @@ -8,8 +8,10 @@ namespace AIParkingApplication public AIParkingApplicationForm() { InitializeComponent(); + string serverBaseAddress = "http://localhost:80/"; + ApiController apiController = new ApiController(serverBaseAddress); C3DeviceController c3Device = new C3DeviceController("192.168.1.200"); - LaneIn laneIn = new LaneIn(1, @"C:\HS_test.mp4", @"C:\HS_test.mp4", c3Device, true, false, true); + LaneIn laneIn = new LaneIn(1, @"C:\HS_test.mp4", @"C:\HS_test.mp4", c3Device, apiController, true, false, true); //LaneIn laneOut = new LaneIn(); Controls.Add(laneIn); laneIn.Start(); diff --git a/AIParkingApplication/Camera.cs b/AIParkingApplication/Camera.cs index e523295..52c8dc0 100644 --- a/AIParkingApplication/Camera.cs +++ b/AIParkingApplication/Camera.cs @@ -10,6 +10,7 @@ namespace AIParkingApplication private string streamUrl; private volatile bool isFrameRequested; private Thread readStreamThread; + public volatile Mat CurrentFrame; public event CameraEvent OnVideoFrameReceived; public event CameraEvent OnOneVideoFrameRequested; @@ -63,6 +64,7 @@ namespace AIParkingApplication OnVideoFrameReceived?.Invoke(videoFrame); if (isFrameRequested) { + CurrentFrame = videoFrame; OnOneVideoFrameRequested?.Invoke(videoFrame); isFrameRequested = false; } diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index 98fc01e..75812ca 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -19,11 +19,13 @@ namespace AIParkingApplication private bool isRetryMode; private bool isRetryModeUntilOk; //TODO: Test mode private C3DeviceController c3Device; + private ApiController apiController; public LaneIn(int doorId, string plateStream, string overviewStream, C3DeviceController c3Device, + ApiController apiController, bool isSupportSquarePlate = true, bool isSupportLongPlate = false, bool isAutoOpenDoor = true, @@ -32,6 +34,7 @@ namespace AIParkingApplication { InitializeComponent(); this.doorId = doorId; + this.isSupportSquarePlate = isSupportSquarePlate; this.isSupportLongPlate = isSupportLongPlate; this.isAutoOpenDoor = isAutoOpenDoor; @@ -39,6 +42,7 @@ namespace AIParkingApplication this.isRetryModeUntilOk = isRetryModeUntilOk; overviewCamera = new Camera(overviewStream); plateCamera = new Camera(plateStream); + this.apiController = apiController; this.c3Device = c3Device; this.c3Device.OnNewCardReceived += C3Device_OnNewCardReceived; @@ -60,16 +64,31 @@ namespace AIParkingApplication private void C3Device_OnNewCardReceived(int doorId, string cardNumber) { - //Request To Capture And Process Frame. - CaptureAllCamera(); - //Request Card Info - if (isAutoOpenDoor) + Task.Factory.StartNew(async () => { - if (this.doorId == doorId) + plateCamera.RequestCaptureOneFrame(); + await Task.Delay(500); + var videoFrame = plateCamera.CurrentFrame; + + FinalPlateResult result = await ProcessFrameImage(plateProcessor, videoFrame, isRetryMode, isRetryModeUntilOk); + pictureBoxPlateImage.Invoke(new Action(() => { - c3Device.OpenDoor(doorId); + pictureBoxPlateImage.Image?.Dispose(); + 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); + } } - } + }); } private void PlateCamera_OnOpenVideoStreamFailed(Mat videoFrame) @@ -106,7 +125,7 @@ namespace AIParkingApplication } } - private async Task ProcessFrameImage(Mat frame, bool isRetryMode, bool isRetryModeUntilOk) + private async Task ProcessFrameImage(PlateProcessor plateProcessor, Mat frame, bool isRetryMode, bool isRetryModeUntilOk) { try { @@ -144,13 +163,12 @@ namespace AIParkingApplication private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) { - FinalPlateResult result = await ProcessFrameImage(videoFrame, isRetryMode, isRetryModeUntilOk); - pictureBoxPlateImage.Invoke(new Action(() => - { - pictureBoxPlateImage.Image?.Dispose(); - pictureBoxPlateImage.Image = result.PlateImage; - })); - ShowCardInfoOnUI("224", result.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); + //FinalPlateResult result = await ProcessFrameImage(plateProcessor, videoFrame, isRetryMode, isRetryModeUntilOk); + //pictureBoxPlateImage.Invoke(new Action(() => + //{ + // pictureBoxPlateImage.Image?.Dispose(); + // pictureBoxPlateImage.Image = result.PlateImage; + //})); } public void Stop()