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;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace AIParkingApplication
|
namespace AIParkingApplication
|
||||||
|
@ -44,37 +45,38 @@ namespace AIParkingApplication
|
||||||
|
|
||||||
private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame)
|
||||||
{
|
{
|
||||||
Cv2.Resize(videoFrame, videoFrame, new OpenCvSharp.Size(1280, 720));
|
Task.Factory.StartNew(new Action(async () =>
|
||||||
Mat result = squarePlateDetector.DetectPlate(videoFrame);
|
|
||||||
|
|
||||||
Cv2.Resize(result, result, new OpenCvSharp.Size(272, 272));
|
|
||||||
var response = 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);
|
Cv2.Resize(videoFrame, videoFrame, new OpenCvSharp.Size(1280, 720));
|
||||||
using (var ms = new MemoryStream(imageData))
|
Mat result = squarePlateDetector.DetectPlate(videoFrame);
|
||||||
|
|
||||||
|
Cv2.Resize(result, result, new OpenCvSharp.Size(272, 272));
|
||||||
|
OcrResult ocrResult = await Util.SendEngineRequestAsync(result, PlateType.Square);
|
||||||
|
|
||||||
|
Bitmap resultPlateImage;
|
||||||
|
if (!string.IsNullOrEmpty(ocrResult.Ocr) && !string.IsNullOrEmpty(ocrResult.Plate))
|
||||||
{
|
{
|
||||||
resultPlateImage = new Bitmap(ms);
|
var imageData = Convert.FromBase64String(ocrResult.Plate);
|
||||||
|
using (var ms = new MemoryStream(imageData))
|
||||||
|
{
|
||||||
|
resultPlateImage = new Bitmap(ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resultPlateImage = result.ToBitmap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
resultPlateImage = result.ToBitmap();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
lblPlateString.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
lblPlateString.Text = ocrResult.Ocr;
|
||||||
|
}));
|
||||||
|
|
||||||
lblPlateString.Invoke(new Action(() =>
|
pictureBoxPlateImage.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
lblPlateString.Text = ocrResult.Ocr;
|
pictureBoxPlateImage.Image?.Dispose();
|
||||||
}));
|
pictureBoxPlateImage.Image = resultPlateImage;
|
||||||
|
}));
|
||||||
pictureBoxPlateImage.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
pictureBoxPlateImage.Image?.Dispose();
|
|
||||||
pictureBoxPlateImage.Image = resultPlateImage;
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user