Compare commits
5 Commits
7fcb3cc5c6
...
86949443bb
Author | SHA1 | Date | |
---|---|---|---|
86949443bb | |||
fd25473dee | |||
a69ba30600 | |||
4648ac01fe | |||
f9fcca2902 |
|
@ -7,9 +7,8 @@ namespace AIParkingApplication
|
||||||
public class Camera
|
public class Camera
|
||||||
{
|
{
|
||||||
private string streamUrl;
|
private string streamUrl;
|
||||||
private bool isCapturing;
|
|
||||||
private object lockSyncObject;
|
|
||||||
private volatile bool isFrameRequested;
|
private volatile bool isFrameRequested;
|
||||||
|
private Thread readStreamThread;
|
||||||
|
|
||||||
public event CameraEvent OnVideoFrameReceived;
|
public event CameraEvent OnVideoFrameReceived;
|
||||||
public event CameraEvent OnOneVideoFrameRequested;
|
public event CameraEvent OnOneVideoFrameRequested;
|
||||||
|
@ -17,16 +16,24 @@ namespace AIParkingApplication
|
||||||
public Camera(string streamUrl)
|
public Camera(string streamUrl)
|
||||||
{
|
{
|
||||||
this.streamUrl = streamUrl;
|
this.streamUrl = streamUrl;
|
||||||
isCapturing = true;
|
|
||||||
isFrameRequested = false;
|
isFrameRequested = false;
|
||||||
lockSyncObject = new object();
|
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||||
|
readStreamThread.IsBackground = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Startcapture()
|
~Camera()
|
||||||
{
|
{
|
||||||
Thread readVideoStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
Stop();
|
||||||
readVideoStreamThread.IsBackground = true;
|
}
|
||||||
readVideoStreamThread.Start();
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
if (!readStreamThread.IsAlive)
|
||||||
|
{
|
||||||
|
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||||
|
readStreamThread.IsBackground = true;
|
||||||
|
readStreamThread.Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RequestCaptureOneFrame()
|
public void RequestCaptureOneFrame()
|
||||||
|
@ -47,10 +54,6 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
Thread.Sleep(50); //Stream Thread Sleep
|
Thread.Sleep(50); //Stream Thread Sleep
|
||||||
//Thread.Sleep(40); //Video Thread Sleep
|
//Thread.Sleep(40); //Video Thread Sleep
|
||||||
if (!isCapturing)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoCapture.Read(videoFrame) && videoFrame.Width > 0 && videoFrame.Height > 0)
|
if (videoCapture.Read(videoFrame) && videoFrame.Width > 0 && videoFrame.Height > 0)
|
||||||
{
|
{
|
||||||
|
@ -64,11 +67,11 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PauseCapture()
|
public void Stop()
|
||||||
{
|
{
|
||||||
lock (lockSyncObject)
|
if (readStreamThread.IsAlive)
|
||||||
{
|
{
|
||||||
isCapturing = false;
|
readStreamThread.Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,6 @@ namespace AIParkingApplication
|
||||||
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
|
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
|
||||||
overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested;
|
overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested;
|
||||||
|
|
||||||
overviewCamera.Startcapture();
|
|
||||||
plateCamera.Startcapture();
|
|
||||||
|
|
||||||
plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate);
|
plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +58,8 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//TODO: check size before resizing
|
||||||
|
Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720));
|
||||||
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
||||||
|
|
||||||
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
|
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
|
||||||
|
@ -97,6 +96,18 @@ namespace AIParkingApplication
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
plateCamera.Stop();
|
||||||
|
overviewCamera.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
plateCamera.Start();
|
||||||
|
overviewCamera.Start();
|
||||||
|
}
|
||||||
|
|
||||||
private void OverviewCameraOnVideoFrameReceived(Mat videoFrame)
|
private void OverviewCameraOnVideoFrameReceived(Mat videoFrame)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -29,8 +29,17 @@ namespace AIParkingApplication
|
||||||
Console.WriteLine("Plate Detected Length: " + plateRectsDetected.Length);
|
Console.WriteLine("Plate Detected Length: " + plateRectsDetected.Length);
|
||||||
if (plateRectsDetected.Length > 0)
|
if (plateRectsDetected.Length > 0)
|
||||||
{
|
{
|
||||||
Mat plateImage = GetBiggestPlate(plateRectsDetected, frame);
|
try
|
||||||
return plateImage;
|
{
|
||||||
|
Mat plateImage = GetBiggestPlate(plateRectsDetected, frame);
|
||||||
|
Cv2.Resize(plateImage, plateImage, new Size(272, 272));
|
||||||
|
return plateImage;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"DetectPlate\t{ex.Message}");
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,9 +34,6 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
Mat plateDetected = plateType == PlateType.Square ? squarePlateDetector.DetectPlate(frame) : longPlateDetector.DetectPlate(frame);
|
Mat plateDetected = plateType == PlateType.Square ? squarePlateDetector.DetectPlate(frame) : longPlateDetector.DetectPlate(frame);
|
||||||
|
|
||||||
//TODO: check size before resizing
|
|
||||||
Cv2.Resize(plateDetected, plateDetected, new OpenCvSharp.Size(272, 272));
|
|
||||||
|
|
||||||
//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;
|
Bitmap finalPlateImage;
|
||||||
|
@ -64,10 +61,7 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//TODO: check size before resizing
|
|
||||||
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
|
|
||||||
FinalPlateResult plateResult;
|
FinalPlateResult plateResult;
|
||||||
|
|
||||||
if (isSupportLongPlate)
|
if (isSupportLongPlate)
|
||||||
{
|
{
|
||||||
plateResult = await DetectPlateAndDoOcrEngineAsync(PlateType.Long, frame);
|
plateResult = await DetectPlateAndDoOcrEngineAsync(PlateType.Long, frame);
|
||||||
|
@ -87,7 +81,11 @@ namespace AIParkingApplication
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
|
Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
|
||||||
return new FinalPlateResult();
|
return new FinalPlateResult
|
||||||
|
{
|
||||||
|
PlateString = string.Empty,
|
||||||
|
PlateImage = frame.ToBitmap()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user