From 968e852f1895d1c71434dce404509661fdee8cb2 Mon Sep 17 00:00:00 2001 From: Le Chau Date: Fri, 26 Jun 2020 10:19:33 +0700 Subject: [PATCH 1/2] =?UTF-8?q?Th=C3=AAm=20API=20Login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIParkingApplication/ApiController.cs | 238 +++++++++++++++++++++++++- 1 file changed, 229 insertions(+), 9 deletions(-) diff --git a/AIParkingApplication/ApiController.cs b/AIParkingApplication/ApiController.cs index b3eb64a..032845d 100644 --- a/AIParkingApplication/ApiController.cs +++ b/AIParkingApplication/ApiController.cs @@ -30,21 +30,22 @@ namespace AIParkingApplication } //TODO Old API - public async Task Login(LoginModel loginData) + public async Task Login(LoginModel loginData) { try { HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData); response.EnsureSuccessStatusCode(); - var loginResult = await response.Content.ReadAsAsync(); + var loginResult = await response.Content.ReadAsAsync(); + Console.WriteLine(loginResult.LoginData.StatisticsData.Moto); return loginResult; } catch (Exception ex) { Console.WriteLine($"SendEngineRequest : {ex.Message}"); - return new LoginResponseModel + return new LoginDataModel { - IsLoggedIn = false + IsLoginSuccess = false }; } } @@ -119,6 +120,8 @@ namespace AIParkingApplication } } + + public class ApiPath { [JsonProperty("savelogsin")] //wtf is this from server. @@ -139,11 +142,6 @@ namespace AIParkingApplication } - public class LoginResponseModel - { - [JsonProperty("")] - public bool IsLoggedIn { get; set; } - } public class PlateLogModel { @@ -177,4 +175,226 @@ namespace AIParkingApplication [JsonProperty("frameImage")] public string FrameImageBase64 { get; set; } } + + public class LoginDataModel + { + [JsonProperty("status")] + public bool IsLoginSuccess { get; set; } + + [JsonProperty("data")] + public Data LoginData { get; set; } + } + + public class Data + { + [JsonProperty("userID")] + public int UserID { get; set; } + + [JsonProperty("name")] + public string UserName { get; set; } + + [JsonProperty("configROI")] + public bool IsConfigROI { get; set; } + + [JsonProperty("configSystemLogs")] + public bool IsSaveSystemLogs { get; set; } + + [JsonProperty("api")] + public APIPath APIPath { get; set; } + + [JsonProperty("camera1")] + public CameraData CameraData1 { get; set; } + + [JsonProperty("camera2")] + public CameraData CameraData2 { get; set; } + + [JsonProperty("camera3")] + public CameraData CameraData3 { get; set; } + + [JsonProperty("camera4")] + public CameraData CameraData4 { get; set; } + + [JsonProperty("camera5")] + public CameraData CameraData5 { get; set; } + + [JsonProperty("camera6")] + public CameraData CameraData6 { get; set; } + + [JsonProperty("camera7")] + public CameraData CameraData7 { get; set; } + + [JsonProperty("camera8")] + public CameraData CameraData8 { get; set; } + + [JsonProperty("statistic")] + public Statistics StatisticsData { get; set; } + + [JsonProperty("cascadeConfig")] + public CascadeConfig CascadeConfigData { get; set; } + + [JsonProperty("laneConfig")] + public LaneConfig LaneConfigData { get; set; } + + + } + + public class APIPath + { + [JsonProperty("apiStatistics")] + public APIProperties ApiStatistics { get; set; } + + [JsonProperty("apiPlateRecognize")] + public APIProperties ApiPlateRecognize { get; set; } + + [JsonProperty("apiCheckCard")] + public APIProperties ApiCheckCard { get; set; } + + [JsonProperty("apiSaveLogs")] + public APIProperties ApiSaveLogs { get; set; } + + [JsonProperty("apiUpdateLogs")] + public APIProperties ApiUpdateLogs { get; set; } + + } + + public class APIProperties + { + [JsonProperty("ip")] + public string IP { get; set; } + + [JsonProperty("port")] + public string Port { get; set; } + + [JsonProperty("path")] + public string Path { get; set; } + } + + public class CameraData + { + [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; } + } + + public class CascadeConfig + { + [JsonProperty("minWidthPlate")] + public int MinWidthPlate { get; set; } + + [JsonProperty("maxWidthPlate")] + public int MaxWidthPlate { get; set; } + + [JsonProperty("minHeightPlate")] + public int MinHeightPlate { get; set; } + + [JsonProperty("maxHeightPlate")] + public int MaxHeightPlate { get; set; } + + [JsonProperty("minWidthLongPlate")] + public int MinWidthLongPlate { get; set; } + + [JsonProperty("maxWidthLongPlate")] + public int MaxWidthLongPlate { get; set; } + + [JsonProperty("minHeightLongPlate")] + public int MinHeightLongPlate { get; set; } + + [JsonProperty("maxHeightLongPlate")] + public int MaxHeightLongPlate { get; set; } + + [JsonProperty("scaleFactor")] + public double ScaleFactor { get; set; } + + [JsonProperty("scaleFactorLong")] + public double ScaleFactorLong { get; set; } + + [JsonProperty("minNeighbors")] + public double MinNeighbors { get; set; } + + [JsonProperty("minNeighborsLong")] + public double MinNeighborsLong { get; set; } + + [JsonProperty("timeOut")] + public int TimeOut { get; set; } + + [JsonProperty("logs")] + public int Logs { get; set; } + } + + public class LaneConfig + { + [JsonProperty("laneConfig")] + public LanePosision Posision { get; set; } + } + + public class LanePosision + { + [JsonProperty("left")] + public LaneConfigParam LeftLane { get; set; } + + [JsonProperty("right")] + public LaneConfigParam RightLane { get; set; } + } + + public class LaneConfigParam + { + [JsonProperty("name")] + public string LaneName { get; set; } + + [JsonProperty("default")] + public string DefaultLane { get; set; } + + [JsonProperty("longPlate")] + public bool IsLongPlate { get; set; } + } } + From eb9f0e86d32ec2af862c43091cc56ae76d566454 Mon Sep 17 00:00:00 2001 From: Le Chau Date: Fri, 26 Jun 2020 13:48:56 +0700 Subject: [PATCH 2/2] =?UTF-8?q?Th=C3=AAm=20API=20L=C6=B0u=20Log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIParkingApplication/ApiController.cs | 96 ++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/AIParkingApplication/ApiController.cs b/AIParkingApplication/ApiController.cs index 032845d..d22c665 100644 --- a/AIParkingApplication/ApiController.cs +++ b/AIParkingApplication/ApiController.cs @@ -12,6 +12,17 @@ namespace AIParkingApplication private bool isHttpClientDisposabled; private int numberOfRetry; private ApiPath apiPath; + public enum VehicleDirection + { + In, + Out + } + + public enum ModePlate + { + Sqare, + Long + } public ApiController(string baseAddress, int numberOfRetry = 5) { @@ -37,7 +48,6 @@ namespace AIParkingApplication HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/login", loginData); response.EnsureSuccessStatusCode(); var loginResult = await response.Content.ReadAsAsync(); - Console.WriteLine(loginResult.LoginData.StatisticsData.Moto); return loginResult; } catch (Exception ex) @@ -110,6 +120,42 @@ namespace AIParkingApplication } } + //Neu Dicrection la Out thi logID la logID lay ve khi check the + public async Task SaveLog(int direction, string cardID, string cameraID, int squareOrLong, string timeInOrOut, string textPlate, Mat plateImage, Mat plateImageResult, Mat PlateFrameImage, Mat FrameImage, string logID = "") + { + string plateImageBase64 = Convert.ToBase64String(plateImage.ToBytes()); + string plateImageResultBase64 = Convert.ToBase64String(plateImageResult.ToBytes()); + string PlateFrameImageBase64 = Convert.ToBase64String(PlateFrameImage.ToBytes()); + string FrameImageBase64 = Convert.ToBase64String(FrameImage.ToBytes()); + try + { + var request = new SaveLogParams + { + Direction = (direction == (int)VehicleDirection.In) ? "in" : "out", + LogID = logID, + CardID = cardID, + TextPlate = textPlate, + CameraID = cameraID, + ModePlate = (squareOrLong == (int)ModePlate.Sqare) ? "1":"0", + TimeVehicleInOrOut = timeInOrOut, + PlateImage = plateImageBase64, + PlateResultImage = plateImageResultBase64, + PlateFrameImage = PlateFrameImageBase64, + FrameImage = FrameImageBase64 + }; + + HttpResponseMessage response = await httpClient.PostAsJsonAsync("/api/save-logs", request); + response.EnsureSuccessStatusCode(); + SaveLogRespone saveLogRespone = await response.Content.ReadAsAsync(); + return saveLogRespone; + } + catch (Exception ex) + { + Console.WriteLine($"SendSaveLogRequest : {ex.Message}"); + return new SaveLogRespone(); + } + } + public void Dispose() { if (httpClient != null && !isHttpClientDisposabled) @@ -120,7 +166,53 @@ namespace AIParkingApplication } } - + public class SaveLogRespone + { + [JsonProperty("status")] + public bool Status { get; set; } + + [JsonProperty("logID")] + public int LogID { get; set; } + + [JsonProperty("cost")] + public string Cost { get; set; } + } + + public class SaveLogParams + { + [JsonProperty("card")] + public string CardID { get; set; } + + [JsonProperty("plate")] + public string TextPlate { get; set; } + + [JsonProperty("type")] + public string Direction { get; set; } + + [JsonProperty("mod")] + public string ModePlate { get; set; } + + [JsonProperty("log_id")] + public string LogID { get; set; } + + [JsonProperty("camera")] + public string CameraID { get; set; } + + [JsonProperty("time")] + public string TimeVehicleInOrOut { get; set; } + + [JsonProperty("plateImage")] + public string PlateImage { get; set; } + + [JsonProperty("plateResultImage")] + public string PlateResultImage { get; set; } + + [JsonProperty("plateFrameImage")] + public string PlateFrameImage { get; set; } + + [JsonProperty("frameImage")] + public string FrameImage { get; set; } + } public class ApiPath {