PlateProcessor - FinalPlateResult add Prop: PlateType. ApiController - Rename CardValidation -> CardInformation

This commit is contained in:
DucDangAnh 2020-06-29 11:39:36 +07:00
parent 6c93c0dcb7
commit 5bcea0ba3f
3 changed files with 46 additions and 20 deletions

View File

@ -73,7 +73,7 @@ namespace AIParkingApplication
} }
} }
public async Task<CardValidation> GetCardInformation(string cardNumber) public async Task<CardInformation> GetCardInformation(string cardNumber)
{ {
try try
{ {
@ -83,13 +83,13 @@ 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($"CheckCard Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}"); Console.WriteLine($"CheckCard Exception:\t{DateTime.Now.ToString(AppConstant.DATETIME_FORMAT)} \t {ex.Message}");
return new CardValidation(); return new CardInformation();
} }
} }
@ -146,7 +146,7 @@ namespace AIParkingApplication
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; }

View File

@ -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.GetCardInformation(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

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