Compare commits

...

7 Commits

Author SHA1 Message Date
DucDangAnh
148896423f Camera - Destructor check videoCapture null. 2020-06-29 15:06:00 +07:00
DucDangAnh
e30cc8470d LaneIn - Change lblRecogizePlateStatus Text 2020-06-29 15:05:26 +07:00
DucDangAnh
0f39bd31f3 PlateDetector - Add Destructor To Dispose plateCascadeClassifier 2020-06-29 15:05:07 +07:00
DucDangAnh
f63da8a968 Camera - use videoCapture as a field. 2020-06-29 15:02:31 +07:00
DucDangAnh
5259eba6b5 LaneIn - Refactor C3Device_OnNewCardReceived 2020-06-29 14:39:38 +07:00
DucDangAnh
ab14853d29 LaneIn - Check CardInfomation. 2020-06-29 13:56:04 +07:00
DucDangAnh
f280376752 LaneIn - Merge isAutoOpenDoor && this.doorId == doorId 2020-06-29 11:46:07 +07:00
3 changed files with 55 additions and 39 deletions

View File

@@ -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))
{

View File

@@ -62,49 +62,37 @@ namespace AIParkingApplication
{
var cardInfoResult = await apiController.GetCardInformation(cardNumber);
if (cardInfoResult.IsValid)
{
if (cardInfoResult.Direction == "in")
{
plateCamera.RequestCaptureOneFrame();
overviewCamera.RequestCaptureOneFrame();
await Task.Delay(200);
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);
pictureBoxPlateImage.Invoke(new Action(() =>
{
pictureBoxPlateImage.Image?.Dispose();
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));
//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 (isAutoOpenDoor && this.doorId == 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";
}));
}
}
OpenDoor(doorId);
}
}
else
@@ -117,6 +105,15 @@ namespace AIParkingApplication
}
}
else
{
lblRecogizePlateStatus.Invoke(new Action(() =>
{
lblRecogizePlateStatus.BackColor = Color.Red;
lblRecogizePlateStatus.Text = "THẺ ĐÃ ĐƯỢC SỬ DỤNG";
}));
}
}
else
{
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)
{
try

View File

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