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 string streamUrl;
|
||||||
private volatile bool isFrameRequested;
|
private volatile bool isFrameRequested;
|
||||||
private Thread readStreamThread;
|
private Thread readStreamThread;
|
||||||
|
private VideoCapture videoCapture;
|
||||||
public volatile Mat CurrentFrame;
|
public volatile Mat CurrentFrame;
|
||||||
|
|
||||||
public event CameraEvent OnVideoFrameReceived;
|
public event CameraEvent OnVideoFrameReceived;
|
||||||
|
@ -21,11 +22,13 @@ namespace AIParkingApplication
|
||||||
isFrameRequested = false;
|
isFrameRequested = false;
|
||||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||||
readStreamThread.IsBackground = true;
|
readStreamThread.IsBackground = true;
|
||||||
|
videoCapture = new VideoCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Camera()
|
~Camera()
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
|
videoCapture?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
@ -45,7 +48,6 @@ namespace AIParkingApplication
|
||||||
|
|
||||||
public void ReadVideoStream()
|
public void ReadVideoStream()
|
||||||
{
|
{
|
||||||
VideoCapture videoCapture = new VideoCapture(); //TODO: Need to dispose this videoCapture?
|
|
||||||
Mat videoFrame = new Mat();
|
Mat videoFrame = new Mat();
|
||||||
if (!videoCapture.Open(streamUrl))
|
if (!videoCapture.Open(streamUrl))
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,49 +62,37 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
var cardInfoResult = await apiController.GetCardInformation(cardNumber);
|
var cardInfoResult = await apiController.GetCardInformation(cardNumber);
|
||||||
if (cardInfoResult.IsValid)
|
if (cardInfoResult.IsValid)
|
||||||
|
{
|
||||||
|
if (cardInfoResult.Direction == "in")
|
||||||
{
|
{
|
||||||
plateCamera.RequestCaptureOneFrame();
|
plateCamera.RequestCaptureOneFrame();
|
||||||
overviewCamera.RequestCaptureOneFrame();
|
overviewCamera.RequestCaptureOneFrame();
|
||||||
await Task.Delay(200);
|
await Task.Delay(200);
|
||||||
|
|
||||||
var plateVideoFrame = plateCamera.CurrentFrame;
|
var plateVideoFrame = plateCamera.CurrentFrame;
|
||||||
var overviewVideoFrame = overviewCamera.CurrentFrame;
|
|
||||||
|
|
||||||
pictureBoxOverviewImage.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
pictureBoxOverviewImage.Image?.Dispose();
|
|
||||||
pictureBoxOverviewImage.Image = overviewVideoFrame.ToBitmap();
|
|
||||||
}));
|
|
||||||
|
|
||||||
FinalPlateResult result = await ProcessFrameImage(plateProcessor, plateVideoFrame, isRetryMode);
|
FinalPlateResult result = await ProcessFrameImage(plateProcessor, plateVideoFrame, isRetryMode);
|
||||||
|
|
||||||
pictureBoxPlateImage.Invoke(new Action(() =>
|
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
pictureBoxPlateImage.Image?.Dispose();
|
pictureBoxPlateImage.Image?.Dispose();
|
||||||
pictureBoxPlateImage.Image = result.PlateImage.ToBitmap();
|
pictureBoxPlateImage.Image = result.PlateImage.ToBitmap();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var cardInformation = await apiController.GetCardInformation(cardNumber);
|
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));
|
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);
|
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 (saveLogResult.Status)
|
||||||
{
|
{
|
||||||
if (isAutoOpenDoor)
|
if (isAutoOpenDoor && this.doorId == doorId)
|
||||||
{
|
{
|
||||||
if (this.doorId == doorId)
|
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
|
else
|
||||||
|
@ -117,6 +105,15 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
lblRecogizePlateStatus.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
lblRecogizePlateStatus.BackColor = Color.Red;
|
||||||
|
lblRecogizePlateStatus.Text = "THẺ ĐÃ ĐƯỢC SỬ DỤNG";
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
lblRecogizePlateStatus.Invoke(new Action(() =>
|
lblRecogizePlateStatus.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
|
@ -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)
|
private async Task<FinalPlateResult> ProcessFrameImage(PlateProcessor plateProcessor, Mat frame, bool isRetryMode)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -23,6 +23,11 @@ namespace AIParkingApplication
|
||||||
plateCascadeClassifier = new CascadeClassifier(this.plateType == PlateType.Square ? PlateDetectorConstant.SQUARE_PLATE_WEIGHT_FILENAME : PlateDetectorConstant.LONG_PLATE_WEIGHT_FILENAME);
|
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)
|
public Mat DetectPlate(Mat frame)
|
||||||
{
|
{
|
||||||
Rect[] plateRectsDetected = plateCascadeClassifier.DetectMultiScale(frame, scaleFactor, minNeighbors, HaarDetectionType.ScaleImage, minSizePlate, maxSizePlate);
|
Rect[] plateRectsDetected = plateCascadeClassifier.DetectMultiScale(frame, scaleFactor, minNeighbors, HaarDetectionType.ScaleImage, minSizePlate, maxSizePlate);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user