Compare commits
9 Commits
963bba78a8
...
5bcea0ba3f
Author | SHA1 | Date | |
---|---|---|---|
5bcea0ba3f | |||
6c93c0dcb7 | |||
a7a060f89c | |||
8060a595c8 | |||
96cc32dbee | |||
57101b4d8f | |||
7b05cbafa2 | |||
f4527e3eac | |||
454251898d |
|
@ -80,6 +80,7 @@
|
|||
<Compile Include="AppConstant.cs" />
|
||||
<Compile Include="C3DeviceController.cs" />
|
||||
<Compile Include="Camera.cs" />
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="ILane.cs" />
|
||||
<Compile Include="LaneIn.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
|
|
|
@ -12,18 +12,6 @@ namespace AIParkingApplication
|
|||
private bool isHttpClientDisposabled;
|
||||
private int numberOfRetry;
|
||||
|
||||
public enum LaneDirection
|
||||
{
|
||||
In,
|
||||
Out
|
||||
}
|
||||
|
||||
public enum ModePlate
|
||||
{
|
||||
Sqare,
|
||||
Long
|
||||
}
|
||||
|
||||
public ApiController(string baseAddress, int numberOfRetry = 5)
|
||||
{
|
||||
httpClient = new HttpClient
|
||||
|
@ -40,7 +28,6 @@ namespace AIParkingApplication
|
|||
Dispose();
|
||||
}
|
||||
|
||||
//TODO Old API
|
||||
public async Task<LoginDataModel> Login(LoginModel loginData)
|
||||
{
|
||||
try
|
||||
|
@ -52,7 +39,7 @@ namespace AIParkingApplication
|
|||
}
|
||||
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
|
||||
{
|
||||
IsLoginSuccess = false
|
||||
|
@ -66,43 +53,27 @@ namespace AIParkingApplication
|
|||
{
|
||||
HttpResponseMessage response = await httpClient.GetAsync("/api/statistics");
|
||||
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)
|
||||
{
|
||||
Console.WriteLine($"SendApiStatisticRequest : {ex.Message}");
|
||||
Console.WriteLine($"GetStatisticInfo Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
|
||||
return new Statistic.ParkInfo();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
public async Task<CardInformation> GetCardInformation(string cardNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -112,18 +83,18 @@ namespace AIParkingApplication
|
|||
};
|
||||
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/check-card", request);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var cardValication = await response.Content.ReadAsAsync<CardValidation>();
|
||||
var cardValication = await response.Content.ReadAsAsync<CardInformation>();
|
||||
return cardValication;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"SendCheckCardRequest : {ex.Message}");
|
||||
return new CardValidation();
|
||||
Console.WriteLine($"CheckCard Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
|
||||
return new CardInformation();
|
||||
}
|
||||
}
|
||||
|
||||
//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 plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes());
|
||||
|
@ -133,13 +104,13 @@ namespace AIParkingApplication
|
|||
{
|
||||
var request = new SaveLogModel
|
||||
{
|
||||
Direction = (direction == LaneDirection.In) ? "in" : "out",
|
||||
Direction = direction == LaneDirection.In ? "in" : "out",
|
||||
LogID = logID,
|
||||
CardID = cardID,
|
||||
TextPlate = textPlate,
|
||||
TextPlate = plateString,
|
||||
CameraID = cameraID,
|
||||
ModePlate = (squareOrLong == ModePlate.Sqare) ? "1":"0",
|
||||
TimeVehicleInOrOut = timeInOrOut,
|
||||
ModePlate = plateType == PlateType.Square ? "1":"0",
|
||||
Timestamp = timestamp,
|
||||
PlateImage = plateImageBase64,
|
||||
PlateResultImage = plateImageResultBase64,
|
||||
PlateFrameImage = PlateFrameImageBase64,
|
||||
|
@ -153,7 +124,7 @@ namespace AIParkingApplication
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -167,14 +138,15 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
}
|
||||
#region Check card validation API
|
||||
|
||||
#region Check card validation API Data Model
|
||||
public class CardModel
|
||||
{
|
||||
[JsonProperty("card")]
|
||||
public string CardNumber { get; set; }
|
||||
}
|
||||
|
||||
public class CardValidation
|
||||
public class CardInformation
|
||||
{
|
||||
[JsonProperty("status")]
|
||||
public bool IsValid { get; set; }
|
||||
|
@ -220,8 +192,7 @@ namespace AIParkingApplication
|
|||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Save Log API
|
||||
#region Save Log API Data Model
|
||||
public class SaveLogRespone
|
||||
{
|
||||
[JsonProperty("status")]
|
||||
|
@ -255,7 +226,7 @@ namespace AIParkingApplication
|
|||
public string CameraID { get; set; }
|
||||
|
||||
[JsonProperty("time")]
|
||||
public string TimeVehicleInOrOut { get; set; }
|
||||
public string Timestamp { get; set; }
|
||||
|
||||
[JsonProperty("plateImage")]
|
||||
public string PlateImage { get; set; }
|
||||
|
@ -271,8 +242,7 @@ namespace AIParkingApplication
|
|||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Get Config API
|
||||
#region Get Config API Data Model
|
||||
public class LoginModel
|
||||
{
|
||||
[JsonProperty("username")]
|
||||
|
@ -340,8 +310,6 @@ namespace AIParkingApplication
|
|||
|
||||
[JsonProperty("laneConfig")]
|
||||
public LaneConfig LaneConfigData { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
#region API Path
|
||||
|
@ -361,7 +329,6 @@ namespace AIParkingApplication
|
|||
|
||||
[JsonProperty("apiUpdateLogs")]
|
||||
public APIProperties ApiUpdateLogs { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class APIProperties
|
||||
|
@ -381,54 +348,73 @@ namespace AIParkingApplication
|
|||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("gate")]
|
||||
public int Gate { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonProperty("stream_url")]
|
||||
public string Stream_url { get; set; }
|
||||
|
||||
[JsonProperty("minWidth")]
|
||||
public double MinWidth { get; set; }
|
||||
|
||||
[JsonProperty("maxWidth")]
|
||||
public double MaxWidth { get; set; }
|
||||
|
||||
[JsonProperty("minHeight")]
|
||||
public double MinHeight { get; set; }
|
||||
|
||||
[JsonProperty("maxHeight")]
|
||||
public double MaxHeight { get; set; }
|
||||
|
||||
[JsonProperty("scaleFactor")]
|
||||
public double ScaleFactor { get; set; }
|
||||
|
||||
[JsonProperty("minNeighbors")]
|
||||
public double MinNeighbors { get; set; }
|
||||
|
||||
[JsonProperty("status")]
|
||||
public double Status { get; set; }
|
||||
|
||||
[JsonProperty("isRecognizeCamera")]
|
||||
public bool IsRecognizeCamera { get; set; }
|
||||
|
||||
[JsonProperty("isLongPlate")]
|
||||
public bool IsLongPlate { get; set; }
|
||||
|
||||
[JsonProperty("stt")]
|
||||
public int Stt { get; set; }
|
||||
|
||||
[JsonProperty("roi_config")]
|
||||
public string Roi_config { get; set; }
|
||||
|
||||
[JsonProperty("created_at")]
|
||||
public int Created_at { get; set; }
|
||||
|
||||
[JsonProperty("modified_at")]
|
||||
public int Modified_at { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class Statistics
|
||||
{
|
||||
[JsonProperty("moto")]
|
||||
public string Moto { get; set; }
|
||||
|
||||
[JsonProperty("oto")]
|
||||
public string Oto { get; set; }
|
||||
|
||||
[JsonProperty("vip")]
|
||||
public string Vip { get; set; }
|
||||
|
||||
[JsonProperty("total_in")]
|
||||
public string Total_in { get; set; }
|
||||
|
||||
[JsonProperty("total_out")]
|
||||
public string Total_out { get; set; }
|
||||
}
|
||||
|
@ -506,6 +492,7 @@ namespace AIParkingApplication
|
|||
public bool IsLongPlate { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace AIParkingApplication
|
|||
public volatile Mat CurrentFrame;
|
||||
|
||||
public event CameraEvent OnVideoFrameReceived;
|
||||
public event CameraEvent OnOneVideoFrameRequested;
|
||||
public event CameraEvent OnOpenVideoStreamFailed;
|
||||
|
||||
public Camera(string streamUrl)
|
||||
|
@ -65,7 +64,6 @@ namespace AIParkingApplication
|
|||
if (isFrameRequested)
|
||||
{
|
||||
CurrentFrame = videoFrame;
|
||||
OnOneVideoFrameRequested?.Invoke(videoFrame);
|
||||
isFrameRequested = false;
|
||||
}
|
||||
}
|
||||
|
|
14
AIParkingApplication/Enums.cs
Normal file
14
AIParkingApplication/Enums.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace AIParkingApplication
|
||||
{
|
||||
public enum PlateType
|
||||
{
|
||||
Square,
|
||||
Long
|
||||
}
|
||||
|
||||
public enum LaneDirection
|
||||
{
|
||||
In,
|
||||
Out
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ namespace AIParkingApplication
|
|||
|
||||
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
|
||||
{
|
||||
var cardInfoResult = await apiController.CheckCard(cardNumber);
|
||||
var cardInfoResult = await apiController.GetCardInformation(cardNumber);
|
||||
if (cardInfoResult.IsValid)
|
||||
{
|
||||
plateCamera.RequestCaptureOneFrame();
|
||||
|
@ -80,21 +80,42 @@ namespace AIParkingApplication
|
|||
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||
{
|
||||
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));
|
||||
|
||||
//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 (this.doorId == doorId)
|
||||
{
|
||||
c3Device.OpenDoor(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
|
||||
{
|
||||
lblRecogizePlateStatus.Invoke(new Action(() =>
|
||||
|
@ -145,8 +166,9 @@ namespace AIParkingApplication
|
|||
Console.WriteLine($"ProcessFrameImage\texMessage: {ex.Message}");
|
||||
return new FinalPlateResult
|
||||
{
|
||||
PlateImage = frame.ToBitmap(),
|
||||
PlateString = string.Empty
|
||||
PlateImage = frame,
|
||||
PlateString = string.Empty,
|
||||
PlateType = PlateType.Square
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,12 +81,6 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
public enum PlateType
|
||||
{
|
||||
Square,
|
||||
Long
|
||||
}
|
||||
|
||||
public static class PlateDetectorConstant
|
||||
{
|
||||
public const string SQUARE_PLATE_WEIGHT_FILENAME = "plate.xml";
|
||||
|
|
|
@ -36,24 +36,26 @@ namespace AIParkingApplication
|
|||
|
||||
//TODO: Check if plateDetected empty
|
||||
OcrResult plateOcrResultFromEngine = await Util.SendEngineRequestAsync(plateDetected, plateType);
|
||||
Bitmap finalPlateImage;
|
||||
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.Ocr) && !string.IsNullOrEmpty(plateOcrResultFromEngine.Plate))
|
||||
Mat finalPlateImage;
|
||||
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))
|
||||
{
|
||||
finalPlateImage = new Bitmap(ms);
|
||||
Bitmap image = new Bitmap(ms);
|
||||
finalPlateImage = BitmapConverter.ToMat(image);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
finalPlateImage = plateDetected.ToBitmap();
|
||||
finalPlateImage = plateDetected;
|
||||
}
|
||||
|
||||
return new FinalPlateResult
|
||||
{
|
||||
PlateString = plateOcrResultFromEngine.Ocr,
|
||||
PlateImage = finalPlateImage
|
||||
PlateImage = finalPlateImage,
|
||||
PlateType = plateType
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -84,7 +86,8 @@ namespace AIParkingApplication
|
|||
return new FinalPlateResult
|
||||
{
|
||||
PlateString = string.Empty,
|
||||
PlateImage = frame.ToBitmap()
|
||||
PlateImage = frame,
|
||||
PlateType = PlateType.Square
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +108,7 @@ namespace AIParkingApplication
|
|||
public class FinalPlateResult
|
||||
{
|
||||
public string PlateString { get; set; }
|
||||
public Bitmap PlateImage { get; set; }
|
||||
public Mat PlateImage { get; set; }
|
||||
public PlateType PlateType { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace AIParkingApplication
|
|||
public string Ocr { get; set; }
|
||||
|
||||
[JsonProperty("plate")]
|
||||
public string Plate { get; set; }
|
||||
public string PlateImageBase64 { get; set; }
|
||||
}
|
||||
|
||||
public static class UtilConstant
|
||||
|
|
Loading…
Reference in New Issue
Block a user