Compare commits
7 Commits
34fc28a0d8
...
148896423f
Author | SHA1 | Date | |
---|---|---|---|
148896423f | |||
e30cc8470d | |||
0f39bd31f3 | |||
f63da8a968 | |||
5259eba6b5 | |||
ab14853d29 | |||
f280376752 |
|
@ -10,6 +10,7 @@ namespace AIParkingApplication
|
|||
private string streamUrl;
|
||||
private volatile bool isFrameRequested;
|
||||
private Thread readStreamThread;
|
||||
private VideoCapture videoCapture;
|
||||
public volatile Mat CurrentFrame;
|
||||
|
||||
public event CameraEvent OnVideoFrameReceived;
|
||||
|
@ -21,11 +22,13 @@ namespace AIParkingApplication
|
|||
isFrameRequested = false;
|
||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readStreamThread.IsBackground = true;
|
||||
videoCapture = new VideoCapture();
|
||||
}
|
||||
|
||||
~Camera()
|
||||
{
|
||||
Stop();
|
||||
videoCapture?.Dispose();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
|
@ -45,7 +48,6 @@ namespace AIParkingApplication
|
|||
|
||||
public void ReadVideoStream()
|
||||
{
|
||||
VideoCapture videoCapture = new VideoCapture(); //TODO: Need to dispose this videoCapture?
|
||||
Mat videoFrame = new Mat();
|
||||
if (!videoCapture.Open(streamUrl))
|
||||
{
|
||||
|
|
|
@ -63,56 +63,53 @@ namespace AIParkingApplication
|
|||
var cardInfoResult = await apiController.GetCardInformation(cardNumber);
|
||||
if (cardInfoResult.IsValid)
|
||||
{
|
||||
plateCamera.RequestCaptureOneFrame();
|
||||
overviewCamera.RequestCaptureOneFrame();
|
||||
await Task.Delay(200);
|
||||
var plateVideoFrame = plateCamera.CurrentFrame;
|
||||
var overviewVideoFrame = overviewCamera.CurrentFrame;
|
||||
|
||||
pictureBoxOverviewImage.Invoke(new Action(() =>
|
||||
if (cardInfoResult.Direction == "in")
|
||||
{
|
||||
pictureBoxOverviewImage.Image?.Dispose();
|
||||
pictureBoxOverviewImage.Image = overviewVideoFrame.ToBitmap();
|
||||
}));
|
||||
plateCamera.RequestCaptureOneFrame();
|
||||
overviewCamera.RequestCaptureOneFrame();
|
||||
await Task.Delay(200);
|
||||
|
||||
FinalPlateResult result = await ProcessFrameImage(plateProcessor, plateVideoFrame, isRetryMode);
|
||||
|
||||
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||
{
|
||||
pictureBoxPlateImage.Image?.Dispose();
|
||||
pictureBoxPlateImage.Image = result.PlateImage.ToBitmap();
|
||||
}));
|
||||
|
||||
var cardInformation = await apiController.GetCardInformation(cardNumber);
|
||||
|
||||
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)
|
||||
var plateVideoFrame = plateCamera.CurrentFrame;
|
||||
FinalPlateResult result = await ProcessFrameImage(plateProcessor, plateVideoFrame, isRetryMode);
|
||||
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||
{
|
||||
if (this.doorId == doorId)
|
||||
pictureBoxPlateImage.Image?.Dispose();
|
||||
pictureBoxPlateImage.Image = result.PlateImage.ToBitmap();
|
||||
}));
|
||||
|
||||
var overviewVideoFrame = overviewCamera.CurrentFrame;
|
||||
pictureBoxOverviewImage.Invoke(new Action(() =>
|
||||
{
|
||||
pictureBoxOverviewImage.Image?.Dispose();
|
||||
pictureBoxOverviewImage.Image = overviewVideoFrame.ToBitmap();
|
||||
}));
|
||||
|
||||
var cardInformation = await apiController.GetCardInformation(cardNumber);
|
||||
ShowCardInfoOnUI(cardNumber, result.PlateString, cardInformation.CardType, DateTime.Now.ToString(AppConstant.DATETIME_FORMAT));
|
||||
|
||||
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 && 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";
|
||||
}));
|
||||
}
|
||||
OpenDoor(doorId);
|
||||
}
|
||||
}
|
||||
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(() =>
|
||||
{
|
||||
lblRecogizePlateStatus.BackColor = Color.Red;
|
||||
lblRecogizePlateStatus.Text = "KHÔNG THỂ KẾT NỐI ĐẾN MÁY CHỦ";
|
||||
lblRecogizePlateStatus.Text = "THẺ ĐÃ ĐƯỢC SỬ DỤNG";
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +141,18 @@ namespace AIParkingApplication
|
|||
}));
|
||||
}
|
||||
|
||||
private void OpenDoor(int doorId)
|
||||
{
|
||||
if (c3Device.OpenDoor(doorId).HasError)
|
||||
{
|
||||
lblRecogizePlateStatus.Invoke(new Action(() =>
|
||||
{
|
||||
lblRecogizePlateStatus.BackColor = Color.Red;
|
||||
lblRecogizePlateStatus.Text = "KHÔNG THỂ KẾT NỐI TỚI THIẾT BỊ MỞ CỬA";
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<FinalPlateResult> ProcessFrameImage(PlateProcessor plateProcessor, Mat frame, bool isRetryMode)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace AIParkingApplication
|
|||
plateCascadeClassifier = new CascadeClassifier(this.plateType == PlateType.Square ? PlateDetectorConstant.SQUARE_PLATE_WEIGHT_FILENAME : PlateDetectorConstant.LONG_PLATE_WEIGHT_FILENAME);
|
||||
}
|
||||
|
||||
~PlateDetector()
|
||||
{
|
||||
plateCascadeClassifier?.Dispose();
|
||||
}
|
||||
|
||||
public Mat DetectPlate(Mat frame)
|
||||
{
|
||||
Rect[] plateRectsDetected = plateCascadeClassifier.DetectMultiScale(frame, scaleFactor, minNeighbors, HaarDetectionType.ScaleImage, minSizePlate, maxSizePlate);
|
||||
|
|
Loading…
Reference in New Issue
Block a user