Add EngineApiController
This commit is contained in:
parent
2c5c923fc9
commit
bbe0f7ed64
|
@ -117,6 +117,7 @@
|
||||||
<Compile Include="AppConstant.cs" />
|
<Compile Include="AppConstant.cs" />
|
||||||
<Compile Include="C3DeviceController.cs" />
|
<Compile Include="C3DeviceController.cs" />
|
||||||
<Compile Include="Camera.cs" />
|
<Compile Include="Camera.cs" />
|
||||||
|
<Compile Include="EngineApiController.cs" />
|
||||||
<Compile Include="Enums.cs" />
|
<Compile Include="Enums.cs" />
|
||||||
<Compile Include="IDoorControlAccess.cs" />
|
<Compile Include="IDoorControlAccess.cs" />
|
||||||
<Compile Include="ILane.cs" />
|
<Compile Include="ILane.cs" />
|
||||||
|
|
|
@ -25,12 +25,23 @@ namespace AIParkingApplication
|
||||||
Controls.Add(sidebar);
|
Controls.Add(sidebar);
|
||||||
|
|
||||||
c3Device = new C3DeviceController("192.168.1.200");
|
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.BorderStyle = BorderStyle.FixedSingle;
|
||||||
laneIn.Location = new System.Drawing.Point(sidebar.Location.X + sidebar.Width + 20, 0);
|
laneIn.Location = new System.Drawing.Point(sidebar.Location.X + sidebar.Width + 20, 0);
|
||||||
Controls.Add(laneIn);
|
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.BorderStyle = BorderStyle.FixedSingle;
|
||||||
laneOut.Location = new System.Drawing.Point(laneIn.Location.X + laneIn.Width + 20, 0);
|
laneOut.Location = new System.Drawing.Point(laneIn.Location.X + laneIn.Width + 20, 0);
|
||||||
Controls.Add(laneOut);
|
Controls.Add(laneOut);
|
||||||
|
|
40
AIParkingApplication/EngineApiController.cs
Normal file
40
AIParkingApplication/EngineApiController.cs
Normal file
|
@ -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<OcrResult> 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<OcrResult>();
|
||||||
|
return ocrResult;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
||||||
|
return new OcrResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ namespace AIParkingApplication
|
||||||
string overviewStream,
|
string overviewStream,
|
||||||
IDoorControlAccess doorControlAccess,
|
IDoorControlAccess doorControlAccess,
|
||||||
ApiController apiController,
|
ApiController apiController,
|
||||||
|
EngineApiController engineApiController,
|
||||||
bool isSupportSquarePlate = true,
|
bool isSupportSquarePlate = true,
|
||||||
bool isSupportLongPlate = false,
|
bool isSupportLongPlate = false,
|
||||||
bool isAutoOpenDoor = true,
|
bool isAutoOpenDoor = true,
|
||||||
|
@ -33,7 +34,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;
|
||||||
|
@ -50,7 +50,7 @@ namespace AIParkingApplication
|
||||||
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
|
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
|
||||||
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
|
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)
|
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace AIParkingApplication
|
||||||
string overviewStream,
|
string overviewStream,
|
||||||
IDoorControlAccess doorControlAccess,
|
IDoorControlAccess doorControlAccess,
|
||||||
ApiController apiController,
|
ApiController apiController,
|
||||||
|
EngineApiController engineApiController,
|
||||||
bool isSupportSquarePlate = true,
|
bool isSupportSquarePlate = true,
|
||||||
bool isSupportLongPlate = false,
|
bool isSupportLongPlate = false,
|
||||||
bool isAutoOpenDoor = true,
|
bool isAutoOpenDoor = true,
|
||||||
|
@ -33,7 +34,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;
|
||||||
|
@ -50,7 +50,7 @@ namespace AIParkingApplication
|
||||||
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
|
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
|
||||||
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
|
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)
|
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
|
||||||
|
@ -203,7 +203,7 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lblStatusInfo.UpdateLabel($"MỜI XE {plateStringEngine} QUA", Color.Red);
|
lblStatusInfo.UpdateLabel($"MỜI XE {plateStringEngine} QUA", Color.Green);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
using OpenCvSharp.Extensions;
|
using OpenCvSharp.Extensions;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AIParkingApplication
|
namespace AIParkingApplication
|
||||||
|
@ -13,11 +12,13 @@ namespace AIParkingApplication
|
||||||
private bool isSupportLongPlate;
|
private bool isSupportLongPlate;
|
||||||
private PlateDetector squarePlateDetector;
|
private PlateDetector squarePlateDetector;
|
||||||
private PlateDetector longPlateDetector;
|
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.isSupportSquarePlate = isSupportSquarePlate;
|
||||||
this.isSupportLongPlate = isSupportLongPlate;
|
this.isSupportLongPlate = isSupportLongPlate;
|
||||||
|
this.engineApiController = engineApiController;
|
||||||
|
|
||||||
if (this.isSupportSquarePlate)
|
if (this.isSupportSquarePlate)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +36,7 @@ namespace AIParkingApplication
|
||||||
Mat plateDetected = plateType == PlateType.Square ? squarePlateDetector.DetectPlate(frame) : longPlateDetector.DetectPlate(frame);
|
Mat plateDetected = plateType == PlateType.Square ? squarePlateDetector.DetectPlate(frame) : longPlateDetector.DetectPlate(frame);
|
||||||
|
|
||||||
//TODO: Check if plateDetected empty
|
//TODO: Check if plateDetected empty
|
||||||
OcrResult plateOcrResultFromEngine = await Util.SendEngineRequestAsync(plateDetected, plateType);
|
OcrResult plateOcrResultFromEngine = await engineApiController.SendEngineRequestAsync(plateDetected, plateType);
|
||||||
Mat finalPlateImage;
|
Mat finalPlateImage;
|
||||||
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.PlateString) && !string.IsNullOrEmpty(plateOcrResultFromEngine.PlateImageBase64))
|
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.PlateString) && !string.IsNullOrEmpty(plateOcrResultFromEngine.PlateImageBase64))
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,8 +14,6 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
public static class Util
|
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)
|
public static bool IsPingable(string destinationIPAddress, out long pingTime, int timeOut = UtilConstant.PING_TIMEOUT_MS)
|
||||||
{
|
{
|
||||||
var pingTask = Task.Factory.StartNew(async () =>
|
var pingTask = Task.Factory.StartNew(async () =>
|
||||||
|
@ -56,29 +54,6 @@ namespace AIParkingApplication
|
||||||
return sf.GetMethod().Name;
|
return sf.GetMethod().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<OcrResult> 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<OcrResult>();
|
|
||||||
return ocrResult;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
|
||||||
return new OcrResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UpdateImage(this PictureBox pictureBox, Bitmap image)
|
public static void UpdateImage(this PictureBox pictureBox, Bitmap image)
|
||||||
{
|
{
|
||||||
if (pictureBox.IsDisposed)
|
if (pictureBox.IsDisposed)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user