Compare commits
No commits in common. "059e79924c9520b6e43f17e1fdc6c6f01fc39f67" and "04e74cea455ddaec31261db67ef084459db308f3" have entirely different histories.
059e79924c
...
04e74cea45
|
@ -76,7 +76,6 @@
|
||||||
<Compile Include="AIParkingApplicationForm.Designer.cs">
|
<Compile Include="AIParkingApplicationForm.Designer.cs">
|
||||||
<DependentUpon>AIParkingApplicationForm.cs</DependentUpon>
|
<DependentUpon>AIParkingApplicationForm.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="ApiController.cs" />
|
|
||||||
<Compile Include="AppConstant.cs" />
|
<Compile Include="AppConstant.cs" />
|
||||||
<Compile Include="C3DeviceController.cs" />
|
<Compile Include="C3DeviceController.cs" />
|
||||||
<Compile Include="Camera.cs" />
|
<Compile Include="Camera.cs" />
|
||||||
|
|
|
@ -1,180 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using OpenCvSharp;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace AIParkingApplication
|
|
||||||
{
|
|
||||||
public class ApiController : IDisposable
|
|
||||||
{
|
|
||||||
private HttpClient httpClient;
|
|
||||||
private bool isHttpClientDisposabled;
|
|
||||||
private int numberOfRetry;
|
|
||||||
private ApiPath apiPath;
|
|
||||||
|
|
||||||
public ApiController(string baseAddress, int numberOfRetry = 5)
|
|
||||||
{
|
|
||||||
httpClient = new HttpClient
|
|
||||||
{
|
|
||||||
BaseAddress = new Uri(baseAddress),
|
|
||||||
Timeout = TimeSpan.FromSeconds(5)
|
|
||||||
};
|
|
||||||
isHttpClientDisposabled = false;
|
|
||||||
this.numberOfRetry = numberOfRetry;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ApiController()
|
|
||||||
{
|
|
||||||
Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO Old API
|
|
||||||
public async Task<LoginResponseModel> Login(LoginModel loginData)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var loginResult = await response.Content.ReadAsAsync<LoginResponseModel>();
|
|
||||||
return loginResult;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
|
||||||
return new LoginResponseModel
|
|
||||||
{
|
|
||||||
IsLoggedIn = false
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO For New API
|
|
||||||
//public async Task<LoginResponseModel> Login(LoginModel loginData)
|
|
||||||
//{
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData);
|
|
||||||
// response.EnsureSuccessStatusCode();
|
|
||||||
// var loginResult = await response.Content.ReadAsAsync<LoginResponseModel>();
|
|
||||||
// return loginResult;
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
|
||||||
// return new LoginResponseModel
|
|
||||||
// {
|
|
||||||
// IsLoggedIn = false
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public async void GetApiPathFromServer()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var request = new PlateRequestEngineModel
|
|
||||||
{
|
|
||||||
};
|
|
||||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/get-from-frame", request);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var ocrResult = await response.Content.ReadAsAsync<OcrResult>();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<OcrResult> SaveLogIn(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 httpClient.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 void Dispose()
|
|
||||||
{
|
|
||||||
if (httpClient != null && !isHttpClientDisposabled)
|
|
||||||
{
|
|
||||||
isHttpClientDisposabled = true;
|
|
||||||
httpClient.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ApiPath
|
|
||||||
{
|
|
||||||
[JsonProperty("savelogsin")] //wtf is this from server.
|
|
||||||
public string SaveVehicleIn { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LoginModel
|
|
||||||
{
|
|
||||||
[JsonProperty("username")]
|
|
||||||
public string Username { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("password")]
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LoginResponseOldModel
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LoginResponseModel
|
|
||||||
{
|
|
||||||
[JsonProperty("")]
|
|
||||||
public bool IsLoggedIn { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PlateLogModel
|
|
||||||
{
|
|
||||||
[JsonProperty("card")]
|
|
||||||
public string CardID { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("plate")]
|
|
||||||
public string PlateString { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("type")]
|
|
||||||
public string LaneType { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("mod")]
|
|
||||||
public string PlateMode { get; set; } //0 or 1
|
|
||||||
|
|
||||||
[JsonProperty("camera")]
|
|
||||||
public string CameraID { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("time")]
|
|
||||||
public string Time { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("plateImage")]
|
|
||||||
public string PlateImageBase64 { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("plateResultImage")]
|
|
||||||
public string PlateResultImageBase64 { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("plateFrameImage")]
|
|
||||||
public string PlateFrameImageBase64 { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty("frameImage")]
|
|
||||||
public string FrameImageBase64 { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -106,42 +106,45 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
||||||
{
|
{
|
||||||
try
|
Task.Factory.StartNew(new Action(async () =>
|
||||||
{
|
{
|
||||||
//TODO: check size before resizing
|
try
|
||||||
Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720));
|
|
||||||
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
|
||||||
|
|
||||||
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
|
|
||||||
{
|
{
|
||||||
if (isRetryModeUntilOk) //TODO: TestMode
|
//TODO: check size before resizing
|
||||||
|
Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720));
|
||||||
|
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
||||||
|
|
||||||
|
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
|
||||||
{
|
{
|
||||||
Thread.Sleep(500);
|
if (isRetryModeUntilOk) //TODO: TestMode
|
||||||
CaptureAllCamera();
|
{
|
||||||
|
Thread.Sleep(500);
|
||||||
|
CaptureAllCamera();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode");
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
overviewCamera.RequestCaptureOneFrame();
|
||||||
|
finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("PlateCamera_OnOneVideoFrameRequested Retry Mode");
|
pictureBoxPlateImage.Image?.Dispose();
|
||||||
Thread.Sleep(1000);
|
pictureBoxPlateImage.Image = finalPlateResult.PlateImage;
|
||||||
overviewCamera.RequestCaptureOneFrame();
|
}));
|
||||||
finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
|
||||||
}
|
ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
pictureBoxPlateImage.Invoke(new Action(() =>
|
|
||||||
{
|
{
|
||||||
pictureBoxPlateImage.Image?.Dispose();
|
Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}");
|
||||||
pictureBoxPlateImage.Image = finalPlateResult.PlateImage;
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
ShowCardInfoOnUI("224", finalPlateResult.PlateString, "Thẻ tháng", DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user