diff --git a/AIParkingApplication/AIParkingApplication.csproj b/AIParkingApplication/AIParkingApplication.csproj
index b0ba45b..764d710 100644
--- a/AIParkingApplication/AIParkingApplication.csproj
+++ b/AIParkingApplication/AIParkingApplication.csproj
@@ -117,6 +117,7 @@
+
diff --git a/AIParkingApplication/AIParkingApplicationForm.cs b/AIParkingApplication/AIParkingApplicationForm.cs
index 6370191..e8cf826 100644
--- a/AIParkingApplication/AIParkingApplicationForm.cs
+++ b/AIParkingApplication/AIParkingApplicationForm.cs
@@ -25,12 +25,23 @@ namespace AIParkingApplication
Controls.Add(sidebar);
c3Device = new C3DeviceController("192.168.1.200");
- laneIn = new LaneIn(1, this.configOnWeb.CameraData1.StreamUrl, this.configOnWeb.CameraData2.StreamUrl, c3Device, this.apiController, true, false, true);
+ EngineApiController engineApiController = null;
+
+ try
+ {
+ engineApiController = new EngineApiController($"http://{this.configOnWeb.APIPath.ApiPlateRecognize.IP}:{this.configOnWeb.APIPath.ApiPlateRecognize.Port}");
+ }
+ catch (Exception)
+ {
+ MessageBox.Show("Cấu hình API Plate Recognize lỗi!", "Cấu hình API Engine lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ laneIn = new LaneIn(1, this.configOnWeb.CameraData1.StreamUrl, this.configOnWeb.CameraData2.StreamUrl, c3Device, this.apiController, engineApiController, true, false, true);
laneIn.BorderStyle = BorderStyle.FixedSingle;
laneIn.Location = new System.Drawing.Point(sidebar.Location.X + sidebar.Width + 20, 0);
Controls.Add(laneIn);
- laneOut = new LaneOut(2, this.configOnWeb.CameraData3.StreamUrl, this.configOnWeb.CameraData4.StreamUrl, c3Device, this.apiController, true, false, true);
+ laneOut = new LaneOut(2, this.configOnWeb.CameraData3.StreamUrl, this.configOnWeb.CameraData4.StreamUrl, c3Device, this.apiController, engineApiController, true, false, true);
laneOut.BorderStyle = BorderStyle.FixedSingle;
laneOut.Location = new System.Drawing.Point(laneIn.Location.X + laneIn.Width + 20, 0);
Controls.Add(laneOut);
diff --git a/AIParkingApplication/EngineApiController.cs b/AIParkingApplication/EngineApiController.cs
new file mode 100644
index 0000000..3ebb41c
--- /dev/null
+++ b/AIParkingApplication/EngineApiController.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Net.Http;
+using System.Threading.Tasks;
+using OpenCvSharp;
+
+namespace AIParkingApplication
+{
+ public class EngineApiController
+ {
+ private HttpClient httpClientEngine;
+
+ public EngineApiController(string engineBaseAddress)
+ {
+ httpClientEngine = new HttpClient { BaseAddress = new Uri(engineBaseAddress), Timeout = TimeSpan.FromMilliseconds(5000) };
+ }
+
+ public async Task SendEngineRequestAsync(Mat plateImage, PlateType plateType)
+ {
+ string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
+ try
+ {
+ var request = new PlateRequestEngineModel
+ {
+ Img64 = plateImageBase64,
+ Mode = plateType == PlateType.Square ? "square" : "long",
+ Display = "full"
+ };
+ HttpResponseMessage response = await httpClientEngine.PostAsJsonAsync("/get-from-frame", request);
+ response.EnsureSuccessStatusCode();
+ var ocrResult = await response.Content.ReadAsAsync();
+ return ocrResult;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"SendEngineRequest : {ex.Message}");
+ return new OcrResult();
+ }
+ }
+ }
+}
diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs
index c8cddf5..d00e76d 100644
--- a/AIParkingApplication/LaneIn.cs
+++ b/AIParkingApplication/LaneIn.cs
@@ -26,6 +26,7 @@ namespace AIParkingApplication
string overviewStream,
IDoorControlAccess doorControlAccess,
ApiController apiController,
+ EngineApiController engineApiController,
bool isSupportSquarePlate = true,
bool isSupportLongPlate = false,
bool isAutoOpenDoor = true,
@@ -33,7 +34,6 @@ namespace AIParkingApplication
{
InitializeComponent();
this.doorId = doorId;
-
this.isSupportSquarePlate = isSupportSquarePlate;
this.isSupportLongPlate = isSupportLongPlate;
this.isAutoOpenDoor = isAutoOpenDoor;
@@ -50,7 +50,7 @@ namespace AIParkingApplication
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
- plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate);
+ plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
}
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
diff --git a/AIParkingApplication/LaneOut.cs b/AIParkingApplication/LaneOut.cs
index 0d3df7d..c1148d0 100644
--- a/AIParkingApplication/LaneOut.cs
+++ b/AIParkingApplication/LaneOut.cs
@@ -26,6 +26,7 @@ namespace AIParkingApplication
string overviewStream,
IDoorControlAccess doorControlAccess,
ApiController apiController,
+ EngineApiController engineApiController,
bool isSupportSquarePlate = true,
bool isSupportLongPlate = false,
bool isAutoOpenDoor = true,
@@ -33,7 +34,6 @@ namespace AIParkingApplication
{
InitializeComponent();
this.doorId = doorId;
-
this.isSupportSquarePlate = isSupportSquarePlate;
this.isSupportLongPlate = isSupportLongPlate;
this.isAutoOpenDoor = isAutoOpenDoor;
@@ -50,7 +50,7 @@ namespace AIParkingApplication
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
- plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate);
+ plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
}
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
@@ -203,7 +203,7 @@ namespace AIParkingApplication
}
else
{
- lblStatusInfo.UpdateLabel($"MỜI XE {plateStringEngine} QUA", Color.Red);
+ lblStatusInfo.UpdateLabel($"MỜI XE {plateStringEngine} QUA", Color.Green);
}
}
}
diff --git a/AIParkingApplication/PlateProcessor.cs b/AIParkingApplication/PlateProcessor.cs
index 294268d..9a85a88 100644
--- a/AIParkingApplication/PlateProcessor.cs
+++ b/AIParkingApplication/PlateProcessor.cs
@@ -2,7 +2,6 @@
using OpenCvSharp.Extensions;
using System;
using System.Drawing;
-using System.IO;
using System.Threading.Tasks;
namespace AIParkingApplication
@@ -13,11 +12,13 @@ namespace AIParkingApplication
private bool isSupportLongPlate;
private PlateDetector squarePlateDetector;
private PlateDetector longPlateDetector;
+ private EngineApiController engineApiController;
- public PlateProcessor(bool isSupportSquarePlate = true, bool isSupportLongPlate = false)
+ public PlateProcessor(EngineApiController engineApiController, bool isSupportSquarePlate = true, bool isSupportLongPlate = false)
{
this.isSupportSquarePlate = isSupportSquarePlate;
this.isSupportLongPlate = isSupportLongPlate;
+ this.engineApiController = engineApiController;
if (this.isSupportSquarePlate)
{
@@ -35,7 +36,7 @@ namespace AIParkingApplication
Mat plateDetected = plateType == PlateType.Square ? squarePlateDetector.DetectPlate(frame) : longPlateDetector.DetectPlate(frame);
//TODO: Check if plateDetected empty
- OcrResult plateOcrResultFromEngine = await Util.SendEngineRequestAsync(plateDetected, plateType);
+ OcrResult plateOcrResultFromEngine = await engineApiController.SendEngineRequestAsync(plateDetected, plateType);
Mat finalPlateImage;
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.PlateString) && !string.IsNullOrEmpty(plateOcrResultFromEngine.PlateImageBase64))
{
diff --git a/AIParkingApplication/Util.cs b/AIParkingApplication/Util.cs
index 0827ae7..3fa948e 100644
--- a/AIParkingApplication/Util.cs
+++ b/AIParkingApplication/Util.cs
@@ -14,8 +14,6 @@ namespace AIParkingApplication
{
public static class Util
{
- private static HttpClient httpClientEngine = new HttpClient { BaseAddress = new Uri("http://localhost:8080/"), Timeout = TimeSpan.FromMilliseconds(5000) };
-
public static bool IsPingable(string destinationIPAddress, out long pingTime, int timeOut = UtilConstant.PING_TIMEOUT_MS)
{
var pingTask = Task.Factory.StartNew(async () =>
@@ -56,29 +54,6 @@ namespace AIParkingApplication
return sf.GetMethod().Name;
}
- public static async Task SendEngineRequestAsync(Mat plateImage, PlateType plateType)
- {
- string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
- try
- {
- var request = new PlateRequestEngineModel
- {
- Img64 = plateImageBase64,
- Mode = plateType == PlateType.Square ? "square" : "long",
- Display = "full"
- };
- HttpResponseMessage response = await httpClientEngine.PostAsJsonAsync("/get-from-frame", request);
- response.EnsureSuccessStatusCode();
- var ocrResult = await response.Content.ReadAsAsync();
- return ocrResult;
- }
- catch (Exception ex)
- {
- Console.WriteLine($"SendEngineRequest : {ex.Message}");
- return new OcrResult();
- }
- }
-
public static void UpdateImage(this PictureBox pictureBox, Bitmap image)
{
if (pictureBox.IsDisposed)