Use Task To Make UI More Responsive In Event handler: PlateCamera_OnOneVideoFrameRequested.
This commit is contained in:
parent
b731d24880
commit
5d09d95f90
|
@ -3,6 +3,7 @@ using OpenCvSharp.Extensions;
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AIParkingApplication
|
||||
|
@ -43,15 +44,16 @@ namespace AIParkingApplication
|
|||
}
|
||||
|
||||
private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
||||
{
|
||||
Task.Factory.StartNew(new Action(async () =>
|
||||
{
|
||||
Cv2.Resize(videoFrame, videoFrame, new OpenCvSharp.Size(1280, 720));
|
||||
Mat result = squarePlateDetector.DetectPlate(videoFrame);
|
||||
|
||||
Cv2.Resize(result, result, new OpenCvSharp.Size(272, 272));
|
||||
var response = Util.SendEngineRequestAsync(result, PlateType.Square);
|
||||
OcrResult ocrResult = await Util.SendEngineRequestAsync(result, PlateType.Square);
|
||||
|
||||
Bitmap resultPlateImage;
|
||||
OcrResult ocrResult = response.Result;
|
||||
if (!string.IsNullOrEmpty(ocrResult.Ocr) && !string.IsNullOrEmpty(ocrResult.Plate))
|
||||
{
|
||||
var imageData = Convert.FromBase64String(ocrResult.Plate);
|
||||
|
@ -65,7 +67,6 @@ namespace AIParkingApplication
|
|||
resultPlateImage = result.ToBitmap();
|
||||
}
|
||||
|
||||
|
||||
lblPlateString.Invoke(new Action(() =>
|
||||
{
|
||||
lblPlateString.Text = ocrResult.Ocr;
|
||||
|
@ -76,6 +77,7 @@ namespace AIParkingApplication
|
|||
pictureBoxPlateImage.Image?.Dispose();
|
||||
pictureBoxPlateImage.Image = resultPlateImage;
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
private void OverviewCameraOnVideoFrameReceived(Mat videoFrame)
|
||||
|
|
Loading…
Reference in New Issue
Block a user