Compare commits
No commits in common. "86949443bb6d715f01ac7abd6c69d7c226a9131c" and "7fcb3cc5c64b268f29fc012b0c2d1ddd2d40a652" have entirely different histories.
86949443bb
...
7fcb3cc5c6
|
@ -7,8 +7,9 @@ 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;
|
||||||
|
@ -16,24 +17,16 @@ namespace AIParkingApplication
|
||||||
public Camera(string streamUrl)
|
public Camera(string streamUrl)
|
||||||
{
|
{
|
||||||
this.streamUrl = streamUrl;
|
this.streamUrl = streamUrl;
|
||||||
|
isCapturing = true;
|
||||||
isFrameRequested = false;
|
isFrameRequested = false;
|
||||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
lockSyncObject = new object();
|
||||||
readStreamThread.IsBackground = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Camera()
|
public void Startcapture()
|
||||||
{
|
{
|
||||||
Stop();
|
Thread readVideoStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||||
}
|
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()
|
||||||
|
@ -54,6 +47,10 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -67,11 +64,11 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void PauseCapture()
|
||||||
{
|
{
|
||||||
if (readStreamThread.IsAlive)
|
lock (lockSyncObject)
|
||||||
{
|
{
|
||||||
readStreamThread.Abort();
|
isCapturing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +61,6 @@ 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))
|
||||||
|
@ -96,18 +97,6 @@ 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,17 +29,8 @@ namespace AIParkingApplication
|
||||||
Console.WriteLine("Plate Detected Length: " + plateRectsDetected.Length);
|
Console.WriteLine("Plate Detected Length: " + plateRectsDetected.Length);
|
||||||
if (plateRectsDetected.Length > 0)
|
if (plateRectsDetected.Length > 0)
|
||||||
{
|
{
|
||||||
try
|
Mat plateImage = GetBiggestPlate(plateRectsDetected, frame);
|
||||||
{
|
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,6 +34,9 @@ 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;
|
||||||
|
@ -61,7 +64,10 @@ 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);
|
||||||
|
@ -81,11 +87,7 @@ 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