Compare commits
No commits in common. "86949443bb6d715f01ac7abd6c69d7c226a9131c" and "7fcb3cc5c64b268f29fc012b0c2d1ddd2d40a652" have entirely different histories.
86949443bb
...
7fcb3cc5c6
|
@ -7,8 +7,9 @@ namespace AIParkingApplication
|
|||
public class Camera
|
||||
{
|
||||
private string streamUrl;
|
||||
private bool isCapturing;
|
||||
private object lockSyncObject;
|
||||
private volatile bool isFrameRequested;
|
||||
private Thread readStreamThread;
|
||||
|
||||
public event CameraEvent OnVideoFrameReceived;
|
||||
public event CameraEvent OnOneVideoFrameRequested;
|
||||
|
@ -16,24 +17,16 @@ namespace AIParkingApplication
|
|||
public Camera(string streamUrl)
|
||||
{
|
||||
this.streamUrl = streamUrl;
|
||||
isCapturing = true;
|
||||
isFrameRequested = false;
|
||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readStreamThread.IsBackground = true;
|
||||
lockSyncObject = new object();
|
||||
}
|
||||
|
||||
~Camera()
|
||||
public void Startcapture()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (!readStreamThread.IsAlive)
|
||||
{
|
||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readStreamThread.IsBackground = true;
|
||||
readStreamThread.Start();
|
||||
}
|
||||
Thread readVideoStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readVideoStreamThread.IsBackground = true;
|
||||
readVideoStreamThread.Start();
|
||||
}
|
||||
|
||||
public void RequestCaptureOneFrame()
|
||||
|
@ -54,6 +47,10 @@ namespace AIParkingApplication
|
|||
{
|
||||
Thread.Sleep(50); //Stream Thread Sleep
|
||||
//Thread.Sleep(40); //Video Thread Sleep
|
||||
if (!isCapturing)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
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.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested;
|
||||
|
||||
overviewCamera.Startcapture();
|
||||
plateCamera.Startcapture();
|
||||
|
||||
plateProcessor = new PlateProcessor(this.isSupportSquarePlate, this.isSupportLongPlate);
|
||||
}
|
||||
|
||||
|
@ -58,8 +61,6 @@ namespace AIParkingApplication
|
|||
{
|
||||
try
|
||||
{
|
||||
//TODO: check size before resizing
|
||||
Cv2.Resize(videoFrame, videoFrame, new Size(1280, 720));
|
||||
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(videoFrame);
|
||||
|
||||
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)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -28,19 +28,10 @@ namespace AIParkingApplication
|
|||
Rect[] plateRectsDetected = plateCascadeClassifier.DetectMultiScale(frame, scaleFactor, minNeighbors, HaarDetectionType.ScaleImage, minSizePlate, maxSizePlate);
|
||||
Console.WriteLine("Plate Detected Length: " + plateRectsDetected.Length);
|
||||
if (plateRectsDetected.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
return frame;
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace AIParkingApplication
|
|||
{
|
||||
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
|
||||
OcrResult plateOcrResultFromEngine = await Util.SendEngineRequestAsync(plateDetected, plateType);
|
||||
Bitmap finalPlateImage;
|
||||
|
@ -61,7 +64,10 @@ namespace AIParkingApplication
|
|||
{
|
||||
try
|
||||
{
|
||||
//TODO: check size before resizing
|
||||
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
|
||||
FinalPlateResult plateResult;
|
||||
|
||||
if (isSupportLongPlate)
|
||||
{
|
||||
plateResult = await DetectPlateAndDoOcrEngineAsync(PlateType.Long, frame);
|
||||
|
@ -81,11 +87,7 @@ namespace AIParkingApplication
|
|||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"{Util.GetCurrentMethodName()}\texMessage: {ex.Message}");
|
||||
return new FinalPlateResult
|
||||
{
|
||||
PlateString = string.Empty,
|
||||
PlateImage = frame.ToBitmap()
|
||||
};
|
||||
return new FinalPlateResult();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user