Compare commits

..

No commits in common. "059e79924c9520b6e43f17e1fdc6c6f01fc39f67" and "04e74cea455ddaec31261db67ef084459db308f3" have entirely different histories.

3 changed files with 31 additions and 209 deletions

View File

@ -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" />

View File

@ -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; }
}
}

View File

@ -106,7 +106,9 @@ namespace AIParkingApplication
} }
} }
private async void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
{
Task.Factory.StartNew(new Action(async () =>
{ {
try try
{ {
@ -142,6 +144,7 @@ namespace AIParkingApplication
{ {
Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}"); Console.WriteLine($"PlateCamera_OnOneVideoFrameRequested\texMessage: {ex.Message}");
} }
}));
} }
public void Stop() public void Stop()