Compare commits

..

9 Commits

8 changed files with 106 additions and 86 deletions

View File

@ -80,6 +80,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="Enums.cs" />
<Compile Include="ILane.cs" /> <Compile Include="ILane.cs" />
<Compile Include="LaneIn.cs"> <Compile Include="LaneIn.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>

View File

@ -12,18 +12,6 @@ namespace AIParkingApplication
private bool isHttpClientDisposabled; private bool isHttpClientDisposabled;
private int numberOfRetry; private int numberOfRetry;
public enum LaneDirection
{
In,
Out
}
public enum ModePlate
{
Sqare,
Long
}
public ApiController(string baseAddress, int numberOfRetry = 5) public ApiController(string baseAddress, int numberOfRetry = 5)
{ {
httpClient = new HttpClient httpClient = new HttpClient
@ -40,7 +28,6 @@ namespace AIParkingApplication
Dispose(); Dispose();
} }
//TODO Old API
public async Task<LoginDataModel> Login(LoginModel loginData) public async Task<LoginDataModel> Login(LoginModel loginData)
{ {
try try
@ -52,7 +39,7 @@ namespace AIParkingApplication
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"SendEngineRequest : {ex.Message}"); Console.WriteLine($"Login Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
return new LoginDataModel return new LoginDataModel
{ {
IsLoginSuccess = false IsLoginSuccess = false
@ -66,43 +53,27 @@ namespace AIParkingApplication
{ {
HttpResponseMessage response = await httpClient.GetAsync("/api/statistics"); HttpResponseMessage response = await httpClient.GetAsync("/api/statistics");
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
Statistic.ParkInfo parkInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>(); Statistic.ParkInfo parkingInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>();
if (string.IsNullOrEmpty(parkInfo.TotalIn)) if (string.IsNullOrEmpty(parkingInfo.TotalIn))
{ {
parkInfo.TotalIn = "0"; parkingInfo.TotalIn = "0";
} }
if (string.IsNullOrEmpty(parkInfo.TotalOut))
if (string.IsNullOrEmpty(parkingInfo.TotalOut))
{ {
parkInfo.TotalOut = "0"; parkingInfo.TotalOut = "0";
} }
return parkInfo; return parkingInfo;
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"SendApiStatisticRequest : {ex.Message}"); Console.WriteLine($"GetStatisticInfo Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
return new Statistic.ParkInfo(); return new Statistic.ParkInfo();
} }
} }
public async void GetApiPathFromServer() public async Task<CardInformation> GetCardInformation(string cardNumber)
{
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<CardValidation> CheckCard(string cardNumber)
{ {
try try
{ {
@ -112,18 +83,18 @@ namespace AIParkingApplication
}; };
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/check-card", request); HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/check-card", request);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var cardValication = await response.Content.ReadAsAsync<CardValidation>(); var cardValication = await response.Content.ReadAsAsync<CardInformation>();
return cardValication; return cardValication;
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"SendCheckCardRequest : {ex.Message}"); Console.WriteLine($"CheckCard Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
return new CardValidation(); return new CardInformation();
} }
} }
//Neu Dicrection la Out thi logID la logID lay ve khi check the //Neu Dicrection la Out thi logID la logID lay ve khi check the
public async Task<SaveLogRespone> SaveLog(LaneDirection direction, string cardID, string cameraID, ModePlate squareOrLong, string timeInOrOut, string textPlate, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "") public async Task<SaveLogRespone> SaveLog(LaneDirection direction, string cardID, string cameraID, PlateType plateType, string timestamp, string plateString, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "")
{ {
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes()); string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes()); string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
@ -133,13 +104,13 @@ namespace AIParkingApplication
{ {
var request = new SaveLogModel var request = new SaveLogModel
{ {
Direction = (direction == LaneDirection.In) ? "in" : "out", Direction = direction == LaneDirection.In ? "in" : "out",
LogID = logID, LogID = logID,
CardID = cardID, CardID = cardID,
TextPlate = textPlate, TextPlate = plateString,
CameraID = cameraID, CameraID = cameraID,
ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0", ModePlate = plateType == PlateType.Square ? "1":"0",
TimeVehicleInOrOut = timeInOrOut, Timestamp = timestamp,
PlateImage = plateImageBase64, PlateImage = plateImageBase64,
PlateResultImage = plateImageResultBase64, PlateResultImage = plateImageResultBase64,
PlateFrameImage = PlateFrameImageBase64, PlateFrameImage = PlateFrameImageBase64,
@ -153,7 +124,7 @@ namespace AIParkingApplication
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"SendSaveLogRequest : {ex.Message}"); Console.WriteLine($"SaveLog Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
return new SaveLogRespone(); return new SaveLogRespone();
} }
} }
@ -167,14 +138,15 @@ namespace AIParkingApplication
} }
} }
} }
#region Check card validation API
#region Check card validation API Data Model
public class CardModel public class CardModel
{ {
[JsonProperty("card")] [JsonProperty("card")]
public string CardNumber { get; set; } public string CardNumber { get; set; }
} }
public class CardValidation public class CardInformation
{ {
[JsonProperty("status")] [JsonProperty("status")]
public bool IsValid { get; set; } public bool IsValid { get; set; }
@ -220,8 +192,7 @@ namespace AIParkingApplication
} }
#endregion #endregion
#region Save Log API Data Model
#region Save Log API
public class SaveLogRespone public class SaveLogRespone
{ {
[JsonProperty("status")] [JsonProperty("status")]
@ -255,7 +226,7 @@ namespace AIParkingApplication
public string CameraID { get; set; } public string CameraID { get; set; }
[JsonProperty("time")] [JsonProperty("time")]
public string TimeVehicleInOrOut { get; set; } public string Timestamp { get; set; }
[JsonProperty("plateImage")] [JsonProperty("plateImage")]
public string PlateImage { get; set; } public string PlateImage { get; set; }
@ -271,8 +242,7 @@ namespace AIParkingApplication
} }
#endregion #endregion
#region Get Config API Data Model
#region Get Config API
public class LoginModel public class LoginModel
{ {
[JsonProperty("username")] [JsonProperty("username")]
@ -340,8 +310,6 @@ namespace AIParkingApplication
[JsonProperty("laneConfig")] [JsonProperty("laneConfig")]
public LaneConfig LaneConfigData { get; set; } public LaneConfig LaneConfigData { get; set; }
} }
#region API Path #region API Path
@ -361,7 +329,6 @@ namespace AIParkingApplication
[JsonProperty("apiUpdateLogs")] [JsonProperty("apiUpdateLogs")]
public APIProperties ApiUpdateLogs { get; set; } public APIProperties ApiUpdateLogs { get; set; }
} }
public class APIProperties public class APIProperties
@ -381,54 +348,73 @@ namespace AIParkingApplication
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int Id { get; set; } public int Id { get; set; }
[JsonProperty("gate")] [JsonProperty("gate")]
public int Gate { get; set; } public int Gate { get; set; }
[JsonProperty("name")] [JsonProperty("name")]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty("type")] [JsonProperty("type")]
public string Type { get; set; } public string Type { get; set; }
[JsonProperty("stream_url")] [JsonProperty("stream_url")]
public string Stream_url { get; set; } public string Stream_url { get; set; }
[JsonProperty("minWidth")] [JsonProperty("minWidth")]
public double MinWidth { get; set; } public double MinWidth { get; set; }
[JsonProperty("maxWidth")] [JsonProperty("maxWidth")]
public double MaxWidth { get; set; } public double MaxWidth { get; set; }
[JsonProperty("minHeight")] [JsonProperty("minHeight")]
public double MinHeight { get; set; } public double MinHeight { get; set; }
[JsonProperty("maxHeight")] [JsonProperty("maxHeight")]
public double MaxHeight { get; set; } public double MaxHeight { get; set; }
[JsonProperty("scaleFactor")] [JsonProperty("scaleFactor")]
public double ScaleFactor { get; set; } public double ScaleFactor { get; set; }
[JsonProperty("minNeighbors")] [JsonProperty("minNeighbors")]
public double MinNeighbors { get; set; } public double MinNeighbors { get; set; }
[JsonProperty("status")] [JsonProperty("status")]
public double Status { get; set; } public double Status { get; set; }
[JsonProperty("isRecognizeCamera")] [JsonProperty("isRecognizeCamera")]
public bool IsRecognizeCamera { get; set; } public bool IsRecognizeCamera { get; set; }
[JsonProperty("isLongPlate")] [JsonProperty("isLongPlate")]
public bool IsLongPlate { get; set; } public bool IsLongPlate { get; set; }
[JsonProperty("stt")] [JsonProperty("stt")]
public int Stt { get; set; } public int Stt { get; set; }
[JsonProperty("roi_config")] [JsonProperty("roi_config")]
public string Roi_config { get; set; } public string Roi_config { get; set; }
[JsonProperty("created_at")] [JsonProperty("created_at")]
public int Created_at { get; set; } public int Created_at { get; set; }
[JsonProperty("modified_at")] [JsonProperty("modified_at")]
public int Modified_at { get; set; } public int Modified_at { get; set; }
} }
public class Statistics public class Statistics
{ {
[JsonProperty("moto")] [JsonProperty("moto")]
public string Moto { get; set; } public string Moto { get; set; }
[JsonProperty("oto")] [JsonProperty("oto")]
public string Oto { get; set; } public string Oto { get; set; }
[JsonProperty("vip")] [JsonProperty("vip")]
public string Vip { get; set; } public string Vip { get; set; }
[JsonProperty("total_in")] [JsonProperty("total_in")]
public string Total_in { get; set; } public string Total_in { get; set; }
[JsonProperty("total_out")] [JsonProperty("total_out")]
public string Total_out { get; set; } public string Total_out { get; set; }
} }
@ -506,6 +492,7 @@ namespace AIParkingApplication
public bool IsLongPlate { get; set; } public bool IsLongPlate { get; set; }
} }
#endregion #endregion
#endregion #endregion
} }

View File

@ -13,7 +13,6 @@ namespace AIParkingApplication
public volatile Mat CurrentFrame; public volatile Mat CurrentFrame;
public event CameraEvent OnVideoFrameReceived; public event CameraEvent OnVideoFrameReceived;
public event CameraEvent OnOneVideoFrameRequested;
public event CameraEvent OnOpenVideoStreamFailed; public event CameraEvent OnOpenVideoStreamFailed;
public Camera(string streamUrl) public Camera(string streamUrl)
@ -65,7 +64,6 @@ namespace AIParkingApplication
if (isFrameRequested) if (isFrameRequested)
{ {
CurrentFrame = videoFrame; CurrentFrame = videoFrame;
OnOneVideoFrameRequested?.Invoke(videoFrame);
isFrameRequested = false; isFrameRequested = false;
} }
} }

View File

@ -0,0 +1,14 @@
namespace AIParkingApplication
{
public enum PlateType
{
Square,
Long
}
public enum LaneDirection
{
In,
Out
}
}

View File

@ -60,7 +60,7 @@ namespace AIParkingApplication
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber) private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
{ {
var cardInfoResult = await apiController.CheckCard(cardNumber); var cardInfoResult = await apiController.GetCardInformation(cardNumber);
if (cardInfoResult.IsValid) if (cardInfoResult.IsValid)
{ {
plateCamera.RequestCaptureOneFrame(); plateCamera.RequestCaptureOneFrame();
@ -80,20 +80,41 @@ namespace AIParkingApplication
pictureBoxPlateImage.Invoke(new Action(() => pictureBoxPlateImage.Invoke(new Action(() =>
{ {
pictureBoxPlateImage.Image?.Dispose(); pictureBoxPlateImage.Image?.Dispose();
pictureBoxPlateImage.Image = result.PlateImage; pictureBoxPlateImage.Image = result.PlateImage.ToBitmap();
})); }));
var cardValidation = await apiController.CheckCard(cardNumber); var cardInformation = await apiController.GetCardInformation(cardNumber);
ShowCardInfoOnUI(cardNumber, result.PlateString, cardValidation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); ShowCardInfoOnUI(cardNumber, result.PlateString, cardInformation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
if (isAutoOpenDoor) //TODO check saveLogResult
var saveLogResult = await apiController.SaveLog(LaneDirection.In, cardInformation.CardRealID.ToString(), "1", result.PlateType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT), result.PlateString, result.PlateImage, result.PlateImage, result.PlateImage, overviewVideoFrame);
if (saveLogResult.Status)
{ {
if (this.doorId == doorId) if (isAutoOpenDoor)
{ {
c3Device.OpenDoor(doorId); if (this.doorId == doorId)
{
var openDoorResult = c3Device.OpenDoor(doorId);
if (openDoorResult.HasError)
{
lblRecogizePlateStatus.Invoke(new Action(() =>
{
lblRecogizePlateStatus.BackColor = Color.Red;
lblRecogizePlateStatus.Text = "KHÔNG THỂ MỞ CỬA";
}));
}
}
} }
} }
else
{
lblRecogizePlateStatus.Invoke(new Action(() =>
{
lblRecogizePlateStatus.BackColor = Color.Red;
lblRecogizePlateStatus.Text = "KHÔNG THỂ KẾT NỐI ĐẾN MÁY CHỦ";
}));
}
} }
else else
{ {
@ -145,8 +166,9 @@ namespace AIParkingApplication
Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}"); Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}");
return new FinalPlateResult return new FinalPlateResult
{ {
PlateImage = frame.ToBitmap(), PlateImage = frame,
PlateString = string.Empty PlateString = string.Empty,
PlateType = PlateType.Square
}; };
} }
} }

View File

@ -81,12 +81,6 @@ namespace AIParkingApplication
} }
} }
public enum PlateType
{
Square,
Long
}
public static class PlateDetectorConstant public static class PlateDetectorConstant
{ {
public const string SQUARE_PLATE_WEIGHT_FILENAME = "plate.xml"; public const string SQUARE_PLATE_WEIGHT_FILENAME = "plate.xml";

View File

@ -36,24 +36,26 @@ namespace AIParkingApplication
//TODO: Check if plateDetected empty //TODO: Check if plateDetected empty
OcrResult plateOcrResultFromEngine = await Util.SendEngineRequestAsync(plateDetected, plateType); OcrResult plateOcrResultFromEngine = await Util.SendEngineRequestAsync(plateDetected, plateType);
Bitmap finalPlateImage; Mat finalPlateImage;
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.Ocr) && !string.IsNullOrEmpty(plateOcrResultFromEngine.Plate)) if (!string.IsNullOrEmpty(plateOcrResultFromEngine.Ocr) && !string.IsNullOrEmpty(plateOcrResultFromEngine.PlateImageBase64))
{ {
byte[] imageData = Convert.FromBase64String(plateOcrResultFromEngine.Plate); byte[] imageData = Convert.FromBase64String(plateOcrResultFromEngine.PlateImageBase64);
using (var ms = new MemoryStream(imageData)) using (var ms = new MemoryStream(imageData))
{ {
finalPlateImage = new Bitmap(ms); Bitmap image = new Bitmap(ms);
finalPlateImage = BitmapConverter.ToMat(image);
} }
} }
else else
{ {
finalPlateImage = plateDetected.ToBitmap(); finalPlateImage = plateDetected;
} }
return new FinalPlateResult return new FinalPlateResult
{ {
PlateString = plateOcrResultFromEngine.Ocr, PlateString = plateOcrResultFromEngine.Ocr,
PlateImage = finalPlateImage PlateImage = finalPlateImage,
PlateType = plateType
}; };
} }
@ -84,7 +86,8 @@ namespace AIParkingApplication
return new FinalPlateResult return new FinalPlateResult
{ {
PlateString = string.Empty, PlateString = string.Empty,
PlateImage = frame.ToBitmap() PlateImage = frame,
PlateType = PlateType.Square
}; };
} }
} }
@ -105,6 +108,7 @@ namespace AIParkingApplication
public class FinalPlateResult public class FinalPlateResult
{ {
public string PlateString { get; set; } public string PlateString { get; set; }
public Bitmap PlateImage { get; set; } public Mat PlateImage { get; set; }
public PlateType PlateType { get; set; }
} }
} }

View File

@ -95,7 +95,7 @@ namespace AIParkingApplication
public string Ocr { get; set; } public string Ocr { get; set; }
[JsonProperty("plate")] [JsonProperty("plate")]
public string Plate { get; set; } public string PlateImageBase64 { get; set; }
} }
public static class UtilConstant public static class UtilConstant