Compare commits

..

No commits in common. "5bcea0ba3fcbb8a288286f9c291b9bf241584c00" and "963bba78a8e31f8347415985e44e3b7074f3ba7f" have entirely different histories.

8 changed files with 86 additions and 106 deletions

View File

@ -80,7 +80,6 @@
<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,6 +12,18 @@ 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
@ -28,6 +40,7 @@ namespace AIParkingApplication
Dispose(); Dispose();
} }
//TODO Old API
public async Task<LoginDataModel> Login(LoginModel loginData) public async Task<LoginDataModel> Login(LoginModel loginData)
{ {
try try
@ -39,7 +52,7 @@ namespace AIParkingApplication
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Login Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}"); Console.WriteLine($"SendEngineRequest : {ex.Message}");
return new LoginDataModel return new LoginDataModel
{ {
IsLoginSuccess = false IsLoginSuccess = false
@ -53,27 +66,43 @@ namespace AIParkingApplication
{ {
HttpResponseMessage response = await httpClient.GetAsync("/api/statistics"); HttpResponseMessage response = await httpClient.GetAsync("/api/statistics");
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
Statistic.ParkInfo parkingInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>(); Statistic.ParkInfo parkInfo = await response.Content.ReadAsAsync<Statistic.ParkInfo>();
if (string.IsNullOrEmpty(parkingInfo.TotalIn)) if (string.IsNullOrEmpty(parkInfo.TotalIn))
{ {
parkingInfo.TotalIn = "0"; parkInfo.TotalIn = "0";
} }
if (string.IsNullOrEmpty(parkInfo.TotalOut))
if (string.IsNullOrEmpty(parkingInfo.TotalOut))
{ {
parkingInfo.TotalOut = "0"; parkInfo.TotalOut = "0";
} }
return parkingInfo; return parkInfo;
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"GetStatisticInfo Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}"); Console.WriteLine($"SendApiStatisticRequest : {ex.Message}");
return new Statistic.ParkInfo(); return new Statistic.ParkInfo();
} }
} }
public async Task<CardInformation> GetCardInformation(string cardNumber) 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<CardValidation> CheckCard(string cardNumber)
{ {
try try
{ {
@ -83,18 +112,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<CardInformation>(); var cardValication = await response.Content.ReadAsAsync<CardValidation>();
return cardValication; return cardValication;
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"CheckCard Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}"); Console.WriteLine($"SendCheckCardRequest : {ex.Message}");
return new CardInformation(); return new CardValidation();
} }
} }
//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, PlateType plateType, string timestamp, string plateString, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "") 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 = "")
{ {
string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes()); string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes());
string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes()); string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
@ -104,13 +133,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 = plateString, TextPlate = textPlate,
CameraID = cameraID, CameraID = cameraID,
ModePlate = plateType == PlateType.Square ? "1":"0", ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0",
Timestamp = timestamp, TimeVehicleInOrOut = timeInOrOut,
PlateImage = plateImageBase64, PlateImage = plateImageBase64,
PlateResultImage = plateImageResultBase64, PlateResultImage = plateImageResultBase64,
PlateFrameImage = PlateFrameImageBase64, PlateFrameImage = PlateFrameImageBase64,
@ -124,7 +153,7 @@ namespace AIParkingApplication
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"SaveLog Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}"); Console.WriteLine($"SendSaveLogRequest : {ex.Message}");
return new SaveLogRespone(); return new SaveLogRespone();
} }
} }
@ -138,15 +167,14 @@ 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 CardInformation public class CardValidation
{ {
[JsonProperty("status")] [JsonProperty("status")]
public bool IsValid { get; set; } public bool IsValid { get; set; }
@ -192,7 +220,8 @@ namespace AIParkingApplication
} }
#endregion #endregion
#region Save Log API Data Model
#region Save Log API
public class SaveLogRespone public class SaveLogRespone
{ {
[JsonProperty("status")] [JsonProperty("status")]
@ -226,7 +255,7 @@ namespace AIParkingApplication
public string CameraID { get; set; } public string CameraID { get; set; }
[JsonProperty("time")] [JsonProperty("time")]
public string Timestamp { get; set; } public string TimeVehicleInOrOut { get; set; }
[JsonProperty("plateImage")] [JsonProperty("plateImage")]
public string PlateImage { get; set; } public string PlateImage { get; set; }
@ -242,7 +271,8 @@ namespace AIParkingApplication
} }
#endregion #endregion
#region Get Config API Data Model
#region Get Config API
public class LoginModel public class LoginModel
{ {
[JsonProperty("username")] [JsonProperty("username")]
@ -310,6 +340,8 @@ namespace AIParkingApplication
[JsonProperty("laneConfig")] [JsonProperty("laneConfig")]
public LaneConfig LaneConfigData { get; set; } public LaneConfig LaneConfigData { get; set; }
} }
#region API Path #region API Path
@ -329,6 +361,7 @@ namespace AIParkingApplication
[JsonProperty("apiUpdateLogs")] [JsonProperty("apiUpdateLogs")]
public APIProperties ApiUpdateLogs { get; set; } public APIProperties ApiUpdateLogs { get; set; }
} }
public class APIProperties public class APIProperties
@ -348,73 +381,54 @@ 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; }
} }
@ -492,7 +506,6 @@ namespace AIParkingApplication
public bool IsLongPlate { get; set; } public bool IsLongPlate { get; set; }
} }
#endregion #endregion
#endregion #endregion
} }

View File

@ -13,6 +13,7 @@ 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)
@ -64,6 +65,7 @@ namespace AIParkingApplication
if (isFrameRequested) if (isFrameRequested)
{ {
CurrentFrame = videoFrame; CurrentFrame = videoFrame;
OnOneVideoFrameRequested?.Invoke(videoFrame);
isFrameRequested = false; isFrameRequested = false;
} }
} }

View File

@ -1,14 +0,0 @@
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.GetCardInformation(cardNumber); var cardInfoResult = await apiController.CheckCard(cardNumber);
if (cardInfoResult.IsValid) if (cardInfoResult.IsValid)
{ {
plateCamera.RequestCaptureOneFrame(); plateCamera.RequestCaptureOneFrame();
@ -80,42 +80,21 @@ namespace AIParkingApplication
pictureBoxPlateImage.Invoke(new Action(() => pictureBoxPlateImage.Invoke(new Action(() =>
{ {
pictureBoxPlateImage.Image?.Dispose(); pictureBoxPlateImage.Image?.Dispose();
pictureBoxPlateImage.Image = result.PlateImage.ToBitmap(); pictureBoxPlateImage.Image = result.PlateImage;
})); }));
var cardInformation = await apiController.GetCardInformation(cardNumber); var cardValidation = await apiController.CheckCard(cardNumber);
ShowCardInfoOnUI(cardNumber, result.PlateString, cardInformation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)); ShowCardInfoOnUI(cardNumber, result.PlateString, cardValidation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
//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 (isAutoOpenDoor) if (isAutoOpenDoor)
{ {
if (this.doorId == doorId) if (this.doorId == doorId)
{ {
var openDoorResult = c3Device.OpenDoor(doorId); 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
{ {
lblRecogizePlateStatus.Invoke(new Action(() => lblRecogizePlateStatus.Invoke(new Action(() =>
@ -166,9 +145,8 @@ namespace AIParkingApplication
Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}"); Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}");
return new FinalPlateResult return new FinalPlateResult
{ {
PlateImage = frame, PlateImage = frame.ToBitmap(),
PlateString = string.Empty, PlateString = string.Empty
PlateType = PlateType.Square
}; };
} }
} }

View File

@ -81,6 +81,12 @@ 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,26 +36,24 @@ 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);
Mat finalPlateImage; Bitmap finalPlateImage;
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.Ocr) && !string.IsNullOrEmpty(plateOcrResultFromEngine.PlateImageBase64)) if (!string.IsNullOrEmpty(plateOcrResultFromEngine.Ocr) && !string.IsNullOrEmpty(plateOcrResultFromEngine.Plate))
{ {
byte[] imageData = Convert.FromBase64String(plateOcrResultFromEngine.PlateImageBase64); byte[] imageData = Convert.FromBase64String(plateOcrResultFromEngine.Plate);
using (var ms = new MemoryStream(imageData)) using (var ms = new MemoryStream(imageData))
{ {
Bitmap image = new Bitmap(ms); finalPlateImage = new Bitmap(ms);
finalPlateImage = BitmapConverter.ToMat(image);
} }
} }
else else
{ {
finalPlateImage = plateDetected; finalPlateImage = plateDetected.ToBitmap();
} }
return new FinalPlateResult return new FinalPlateResult
{ {
PlateString = plateOcrResultFromEngine.Ocr, PlateString = plateOcrResultFromEngine.Ocr,
PlateImage = finalPlateImage, PlateImage = finalPlateImage
PlateType = plateType
}; };
} }
@ -86,8 +84,7 @@ namespace AIParkingApplication
return new FinalPlateResult return new FinalPlateResult
{ {
PlateString = string.Empty, PlateString = string.Empty,
PlateImage = frame, PlateImage = frame.ToBitmap()
PlateType = PlateType.Square
}; };
} }
} }
@ -108,7 +105,6 @@ namespace AIParkingApplication
public class FinalPlateResult public class FinalPlateResult
{ {
public string PlateString { get; set; } public string PlateString { get; set; }
public Mat PlateImage { get; set; } public Bitmap 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 PlateImageBase64 { get; set; } public string Plate { get; set; }
} }
public static class UtilConstant public static class UtilConstant