Compare commits

..

No commits in common. "8967740d67e95ac1d6c00b038c298ebbb39c0195" and "e2ba2c065d016e357f76fbeca2d2d890354b6aba" have entirely different histories.

8 changed files with 92 additions and 200 deletions

View File

@ -78,6 +78,7 @@
<Compile Include="AppConstant.cs" /> <Compile Include="AppConstant.cs" />
<Compile Include="C3DeviceController.cs" /> <Compile Include="C3DeviceController.cs" />
<Compile Include="Camera.cs" /> <Compile Include="Camera.cs" />
<Compile Include="Lane.cs" />
<Compile Include="LaneIn.cs"> <Compile Include="LaneIn.cs">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
@ -91,7 +92,6 @@
<DependentUpon>LaneOut.cs</DependentUpon> <DependentUpon>LaneOut.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="PlateDetector.cs" /> <Compile Include="PlateDetector.cs" />
<Compile Include="PlateProcessor.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StatusBar.cs"> <Compile Include="StatusBar.cs">

View File

@ -17,8 +17,8 @@ namespace AIParkingApplication
public Camera(string streamUrl) public Camera(string streamUrl)
{ {
this.streamUrl = streamUrl; this.streamUrl = streamUrl;
isCapturing = true; this.isCapturing = true;
isFrameRequested = false; this.isFrameRequested = false;
lockSyncObject = new object(); lockSyncObject = new object();
} }

View File

@ -0,0 +1,22 @@
namespace AIParkingApplication
{
public class Lane
{
private LaneType laneType;
private string vehicleVideoStream;
private string plateVideoStream;
public Lane(LaneType laneType, string vehicleVideoStream, string plateVideoStream)
{
this.laneType = laneType;
this.vehicleVideoStream = vehicleVideoStream;
this.plateVideoStream = plateVideoStream;
}
}
public enum LaneType
{
IN,
OUT
}
}

View File

@ -38,10 +38,10 @@
this.lblCardType = new System.Windows.Forms.Label(); this.lblCardType = new System.Windows.Forms.Label();
this.lblCardNumber = new System.Windows.Forms.Label(); this.lblCardNumber = new System.Windows.Forms.Label();
this.grbCardInformation = new System.Windows.Forms.GroupBox(); this.grbCardInformation = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.lblCardTime = new System.Windows.Forms.Label(); this.lblCardTime = new System.Windows.Forms.Label();
this.lblPlateString = new System.Windows.Forms.Label(); this.lblPlateString = new System.Windows.Forms.Label();
this.lblRecogizePlateStatus = new System.Windows.Forms.Label(); this.lblRecogizePlateStatus = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateImage)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateImage)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateVideo)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateVideo)).BeginInit();
this.grbPlateCamera.SuspendLayout(); this.grbPlateCamera.SuspendLayout();
@ -53,7 +53,8 @@
// //
// pictureBoxPlateImage // pictureBoxPlateImage
// //
this.pictureBoxPlateImage.Location = new System.Drawing.Point(226, 23); this.pictureBoxPlateImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.pictureBoxPlateImage.Location = new System.Drawing.Point(226, 29);
this.pictureBoxPlateImage.Name = "pictureBoxPlateImage"; this.pictureBoxPlateImage.Name = "pictureBoxPlateImage";
this.pictureBoxPlateImage.Size = new System.Drawing.Size(200, 200); this.pictureBoxPlateImage.Size = new System.Drawing.Size(200, 200);
this.pictureBoxPlateImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBoxPlateImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@ -62,7 +63,8 @@
// //
// pictureBoxPlateVideo // pictureBoxPlateVideo
// //
this.pictureBoxPlateVideo.Location = new System.Drawing.Point(15, 23); this.pictureBoxPlateVideo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.pictureBoxPlateVideo.Location = new System.Drawing.Point(15, 29);
this.pictureBoxPlateVideo.Name = "pictureBoxPlateVideo"; this.pictureBoxPlateVideo.Name = "pictureBoxPlateVideo";
this.pictureBoxPlateVideo.Size = new System.Drawing.Size(200, 200); this.pictureBoxPlateVideo.Size = new System.Drawing.Size(200, 200);
this.pictureBoxPlateVideo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBoxPlateVideo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@ -74,17 +76,16 @@
this.grbPlateCamera.Controls.Add(this.pictureBoxPlateImage); this.grbPlateCamera.Controls.Add(this.pictureBoxPlateImage);
this.grbPlateCamera.Controls.Add(this.pictureBoxPlateVideo); this.grbPlateCamera.Controls.Add(this.pictureBoxPlateVideo);
this.grbPlateCamera.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.grbPlateCamera.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.grbPlateCamera.Location = new System.Drawing.Point(1, 208); this.grbPlateCamera.Location = new System.Drawing.Point(10, 199);
this.grbPlateCamera.Margin = new System.Windows.Forms.Padding(0);
this.grbPlateCamera.Name = "grbPlateCamera"; this.grbPlateCamera.Name = "grbPlateCamera";
this.grbPlateCamera.Size = new System.Drawing.Size(441, 237); this.grbPlateCamera.Size = new System.Drawing.Size(441, 246);
this.grbPlateCamera.TabIndex = 12; this.grbPlateCamera.TabIndex = 12;
this.grbPlateCamera.TabStop = false; this.grbPlateCamera.TabStop = false;
this.grbPlateCamera.Text = "Camera biển số"; this.grbPlateCamera.Text = "Camera biển số";
// //
// pictureBoxOverviewImage // pictureBoxOverviewImage
// //
this.pictureBoxOverviewImage.Location = new System.Drawing.Point(226, 24); this.pictureBoxOverviewImage.Location = new System.Drawing.Point(226, 30);
this.pictureBoxOverviewImage.Name = "pictureBoxOverviewImage"; this.pictureBoxOverviewImage.Name = "pictureBoxOverviewImage";
this.pictureBoxOverviewImage.Size = new System.Drawing.Size(200, 200); this.pictureBoxOverviewImage.Size = new System.Drawing.Size(200, 200);
this.pictureBoxOverviewImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBoxOverviewImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@ -93,7 +94,7 @@
// //
// pictureBoxOverviewVideo // pictureBoxOverviewVideo
// //
this.pictureBoxOverviewVideo.Location = new System.Drawing.Point(15, 24); this.pictureBoxOverviewVideo.Location = new System.Drawing.Point(15, 30);
this.pictureBoxOverviewVideo.Name = "pictureBoxOverviewVideo"; this.pictureBoxOverviewVideo.Name = "pictureBoxOverviewVideo";
this.pictureBoxOverviewVideo.Size = new System.Drawing.Size(200, 200); this.pictureBoxOverviewVideo.Size = new System.Drawing.Size(200, 200);
this.pictureBoxOverviewVideo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBoxOverviewVideo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
@ -105,10 +106,9 @@
this.grbOverviewCamera.Controls.Add(this.pictureBoxOverviewImage); this.grbOverviewCamera.Controls.Add(this.pictureBoxOverviewImage);
this.grbOverviewCamera.Controls.Add(this.pictureBoxOverviewVideo); this.grbOverviewCamera.Controls.Add(this.pictureBoxOverviewVideo);
this.grbOverviewCamera.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.grbOverviewCamera.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.grbOverviewCamera.Location = new System.Drawing.Point(1, 454); this.grbOverviewCamera.Location = new System.Drawing.Point(10, 456);
this.grbOverviewCamera.Margin = new System.Windows.Forms.Padding(0);
this.grbOverviewCamera.Name = "grbOverviewCamera"; this.grbOverviewCamera.Name = "grbOverviewCamera";
this.grbOverviewCamera.Size = new System.Drawing.Size(441, 238); this.grbOverviewCamera.Size = new System.Drawing.Size(441, 247);
this.grbOverviewCamera.TabIndex = 11; this.grbOverviewCamera.TabIndex = 11;
this.grbOverviewCamera.TabStop = false; this.grbOverviewCamera.TabStop = false;
this.grbOverviewCamera.Text = "Camera toàn cảnh"; this.grbOverviewCamera.Text = "Camera toàn cảnh";
@ -119,8 +119,7 @@
this.lblLaneLabel.BackColor = System.Drawing.Color.Red; this.lblLaneLabel.BackColor = System.Drawing.Color.Red;
this.lblLaneLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblLaneLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblLaneLabel.ForeColor = System.Drawing.SystemColors.Control; this.lblLaneLabel.ForeColor = System.Drawing.SystemColors.Control;
this.lblLaneLabel.Location = new System.Drawing.Point(1, 1); this.lblLaneLabel.Location = new System.Drawing.Point(10, 8);
this.lblLaneLabel.Margin = new System.Windows.Forms.Padding(0);
this.lblLaneLabel.Name = "lblLaneLabel"; this.lblLaneLabel.Name = "lblLaneLabel";
this.lblLaneLabel.Padding = new System.Windows.Forms.Padding(138, 5, 137, 5); this.lblLaneLabel.Padding = new System.Windows.Forms.Padding(138, 5, 137, 5);
this.lblLaneLabel.Size = new System.Drawing.Size(441, 49); this.lblLaneLabel.Size = new System.Drawing.Size(441, 49);
@ -131,7 +130,7 @@
// lblCardType // lblCardType
// //
this.lblCardType.AutoSize = true; this.lblCardType.AutoSize = true;
this.lblCardType.Location = new System.Drawing.Point(12, 64); this.lblCardType.Location = new System.Drawing.Point(12, 55);
this.lblCardType.Name = "lblCardType"; this.lblCardType.Name = "lblCardType";
this.lblCardType.Size = new System.Drawing.Size(60, 18); this.lblCardType.Size = new System.Drawing.Size(60, 18);
this.lblCardType.TabIndex = 0; this.lblCardType.TabIndex = 0;
@ -140,7 +139,7 @@
// lblCardNumber // lblCardNumber
// //
this.lblCardNumber.AutoSize = true; this.lblCardNumber.AutoSize = true;
this.lblCardNumber.Location = new System.Drawing.Point(12, 31); this.lblCardNumber.Location = new System.Drawing.Point(12, 22);
this.lblCardNumber.Name = "lblCardNumber"; this.lblCardNumber.Name = "lblCardNumber";
this.lblCardNumber.Size = new System.Drawing.Size(51, 18); this.lblCardNumber.Size = new System.Drawing.Size(51, 18);
this.lblCardNumber.TabIndex = 0; this.lblCardNumber.TabIndex = 0;
@ -154,28 +153,17 @@
this.grbCardInformation.Controls.Add(this.lblPlateString); this.grbCardInformation.Controls.Add(this.lblPlateString);
this.grbCardInformation.Controls.Add(this.lblCardNumber); this.grbCardInformation.Controls.Add(this.lblCardNumber);
this.grbCardInformation.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.grbCardInformation.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.grbCardInformation.Location = new System.Drawing.Point(1, 55); this.grbCardInformation.Location = new System.Drawing.Point(10, 61);
this.grbCardInformation.Margin = new System.Windows.Forms.Padding(0);
this.grbCardInformation.Name = "grbCardInformation"; this.grbCardInformation.Name = "grbCardInformation";
this.grbCardInformation.Size = new System.Drawing.Size(441, 104); this.grbCardInformation.Size = new System.Drawing.Size(441, 82);
this.grbCardInformation.TabIndex = 13; this.grbCardInformation.TabIndex = 13;
this.grbCardInformation.TabStop = false; this.grbCardInformation.TabStop = false;
this.grbCardInformation.Text = "Thông tin thẻ"; this.grbCardInformation.Text = "Thông tin thẻ";
// //
// button1
//
this.button1.Location = new System.Drawing.Point(360, 20);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// lblCardTime // lblCardTime
// //
this.lblCardTime.AutoSize = true; this.lblCardTime.AutoSize = true;
this.lblCardTime.Location = new System.Drawing.Point(223, 64); this.lblCardTime.Location = new System.Drawing.Point(218, 55);
this.lblCardTime.Name = "lblCardTime"; this.lblCardTime.Name = "lblCardTime";
this.lblCardTime.Size = new System.Drawing.Size(68, 18); this.lblCardTime.Size = new System.Drawing.Size(68, 18);
this.lblCardTime.TabIndex = 0; this.lblCardTime.TabIndex = 0;
@ -184,7 +172,7 @@
// lblPlateString // lblPlateString
// //
this.lblPlateString.AutoSize = true; this.lblPlateString.AutoSize = true;
this.lblPlateString.Location = new System.Drawing.Point(223, 31); this.lblPlateString.Location = new System.Drawing.Point(218, 22);
this.lblPlateString.Name = "lblPlateString"; this.lblPlateString.Name = "lblPlateString";
this.lblPlateString.Size = new System.Drawing.Size(58, 18); this.lblPlateString.Size = new System.Drawing.Size(58, 18);
this.lblPlateString.TabIndex = 0; this.lblPlateString.TabIndex = 0;
@ -196,8 +184,7 @@
this.lblRecogizePlateStatus.BackColor = System.Drawing.Color.Green; this.lblRecogizePlateStatus.BackColor = System.Drawing.Color.Green;
this.lblRecogizePlateStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblRecogizePlateStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblRecogizePlateStatus.ForeColor = System.Drawing.SystemColors.Control; this.lblRecogizePlateStatus.ForeColor = System.Drawing.SystemColors.Control;
this.lblRecogizePlateStatus.Location = new System.Drawing.Point(1, 159); this.lblRecogizePlateStatus.Location = new System.Drawing.Point(10, 150);
this.lblRecogizePlateStatus.Margin = new System.Windows.Forms.Padding(0);
this.lblRecogizePlateStatus.Name = "lblRecogizePlateStatus"; this.lblRecogizePlateStatus.Name = "lblRecogizePlateStatus";
this.lblRecogizePlateStatus.Padding = new System.Windows.Forms.Padding(12, 6, 12, 6); this.lblRecogizePlateStatus.Padding = new System.Windows.Forms.Padding(12, 6, 12, 6);
this.lblRecogizePlateStatus.Size = new System.Drawing.Size(441, 41); this.lblRecogizePlateStatus.Size = new System.Drawing.Size(441, 41);
@ -205,6 +192,16 @@
this.lblRecogizePlateStatus.Text = "KHÔNG NHẬN DIỆN ĐƯỢC BIỂN SỐ"; this.lblRecogizePlateStatus.Text = "KHÔNG NHẬN DIỆN ĐƯỢC BIỂN SỐ";
this.lblRecogizePlateStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblRecogizePlateStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// button1
//
this.button1.Location = new System.Drawing.Point(315, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// LaneIn // LaneIn
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -214,9 +211,8 @@
this.Controls.Add(this.grbOverviewCamera); this.Controls.Add(this.grbOverviewCamera);
this.Controls.Add(this.lblLaneLabel); this.Controls.Add(this.lblLaneLabel);
this.Controls.Add(this.grbCardInformation); this.Controls.Add(this.grbCardInformation);
this.Margin = new System.Windows.Forms.Padding(0);
this.Name = "LaneIn"; this.Name = "LaneIn";
this.Size = new System.Drawing.Size(443, 692); this.Size = new System.Drawing.Size(460, 710);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateImage)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateImage)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateVideo)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlateVideo)).EndInit();
this.grbPlateCamera.ResumeLayout(false); this.grbPlateCamera.ResumeLayout(false);

View File

@ -1,7 +1,8 @@
using OpenCvSharp; using OpenCvSharp;
using OpenCvSharp.Extensions; using OpenCvSharp.Extensions;
using System; using System;
using System.Threading.Tasks; using System.Drawing;
using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
namespace AIParkingApplication namespace AIParkingApplication
@ -10,20 +11,18 @@ namespace AIParkingApplication
{ {
private Camera overviewCamera; private Camera overviewCamera;
private Camera plateCamera; private Camera plateCamera;
private PlateProcessor plateProcessor; private PlateDetector squarePlateDetector;
public LaneIn() public LaneIn()
{ {
InitializeComponent(); InitializeComponent();
string overviewCameraVideo = @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; //@"C:\HS_test.mp4" string overviewCameraVideo = @"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"; //@"C:\HS_test.mp4"
string plateCameraVideo = @"C:\HS_test.mp4"; string plateCameraVideo = @"C:\HS_test.mp4";
//string plateCameraVideo = @"C:\CongRa_1.mp4";
overviewCamera = new Camera(overviewCameraVideo); overviewCamera = new Camera(overviewCameraVideo);
plateCamera = new Camera(plateCameraVideo); plateCamera = new Camera(plateCameraVideo);
plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived; plateCamera.OnVideoFrameReceived += PlateCameraOnVideoFrameReceived;
plateCamera.OnOneVideoFrameRequested += PlateCamera_OnOneVideoFrameRequested; plateCamera.OnOneVideoFrameRequested += PlateCamera_OnOneVideoFrameRequested; ;
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived; overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested; overviewCamera.OnOneVideoFrameRequested += OverviewCamera_OnOneVideoFrameRequested;
@ -31,7 +30,7 @@ namespace AIParkingApplication
overviewCamera.Startcapture(); overviewCamera.Startcapture();
plateCamera.Startcapture(); plateCamera.Startcapture();
plateProcessor = new PlateProcessor(true, false); squarePlateDetector = new PlateDetector(PlateType.Square, PlateDetectorConstant.MIN_SIZE_DEFAULT_SQUARE_PLATE, PlateDetectorConstant.MAX_SIZE_DEFAULT_SQUARE_PLATE, PlateDetectorConstant.SCALE_FACTOR_DEFAULT_SQUARE_PLATE, PlateDetectorConstant.MIN_NEIGHBORS_DEFAULT_SQUARE_PLATE);
} }
private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame) private void OverviewCamera_OnOneVideoFrameRequested(Mat videoFrame)
@ -45,20 +44,37 @@ namespace AIParkingApplication
private void PlateCamera_OnOneVideoFrameRequested(Mat videoFrame) 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);
Bitmap resultPlateImage;
OcrResult ocrResult = response.Result;
if (!string.IsNullOrEmpty(ocrResult.Ocr) && !string.IsNullOrEmpty(ocrResult.Plate))
{ {
var finalPlateResult = await plateProcessor.ProcessPlate(videoFrame); var imageData = Convert.FromBase64String(ocrResult.Plate);
using (var ms = new MemoryStream(imageData))
lblPlateString.Invoke(new Action(() =>
{ {
lblPlateString.Text = finalPlateResult.PlateString; resultPlateImage = new Bitmap(ms);
})); }
}
else
{
resultPlateImage = result.ToBitmap();
}
pictureBoxPlateImage.Invoke(new Action(() =>
{ lblPlateString.Invoke(new Action(() =>
pictureBoxPlateImage.Image?.Dispose(); {
pictureBoxPlateImage.Image = finalPlateResult.PlateImage; lblPlateString.Text = ocrResult.Ocr;
})); }));
pictureBoxPlateImage.Invoke(new Action(() =>
{
pictureBoxPlateImage.Image?.Dispose();
pictureBoxPlateImage.Image = resultPlateImage;
})); }));
} }
@ -82,8 +98,8 @@ namespace AIParkingApplication
private void CaptureAllCamera() private void CaptureAllCamera()
{ {
plateCamera.RequestCaptureOneFrame(); this.plateCamera.RequestCaptureOneFrame();
overviewCamera.RequestCaptureOneFrame(); this.overviewCamera.RequestCaptureOneFrame();
} }
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)

View File

@ -156,15 +156,6 @@
<metadata name="lblPlateString.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="lblPlateString.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="button1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lblCardTime.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lblPlateString.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lblRecogizePlateStatus.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="lblRecogizePlateStatus.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>

View File

@ -38,38 +38,11 @@ namespace AIParkingApplication
} }
} }
private Rect ExtendPlateRect(Rect plateRect, int extendWidth = 50, int extendHeigh = 50) //TODO: 50 for plate square.
{
int newX = plateRect.X - extendWidth;
int newY = plateRect.Y - extendHeigh;
int newWidth = plateRect.Width + extendWidth * 2;
int newHeigh = plateRect.Height + extendHeigh * 2;
return new Rect(newX, newY, newWidth, newHeigh);
}
private Mat GetBiggestPlate(Rect[] plateRects, Mat frame) private Mat GetBiggestPlate(Rect[] plateRects, Mat frame)
{ {
Rect biggestPlateRect = plateRects.OrderByDescending(x => x.Width).FirstOrDefault(); Rect biggestPlateRect = plateRects.OrderByDescending(x => x.Width).FirstOrDefault();
Console.WriteLine("===================================================");
for (int i = 0; i < plateRects.Length; i++)
{
Console.WriteLine($"{i}\t{plateRects[i].Width}\t{plateRects[i].Height}");
}
Console.WriteLine($"GetBiggestPlate - Width: {biggestPlateRect.Width}\tHeight: {biggestPlateRect.Height}"); Console.WriteLine($"GetBiggestPlate - Width: {biggestPlateRect.Width}\tHeight: {biggestPlateRect.Height}");
Mat plateImage = frame[biggestPlateRect];
Rect extendedRect = ExtendPlateRect(biggestPlateRect);
//TODO: check oversize frame
Mat plateImage;
try
{
plateImage = frame[extendedRect];
}
catch (Exception ex)
{
Console.WriteLine("Error While Extending Plate Rect");
plateImage = frame[biggestPlateRect];
throw;
}
return plateImage; return plateImage;
} }
} }
@ -84,7 +57,7 @@ namespace AIParkingApplication
{ {
public const double SCALE_FACTOR_DEFAULT_SQUARE_PLATE = 1.03; public const double SCALE_FACTOR_DEFAULT_SQUARE_PLATE = 1.03;
public static int MIN_NEIGHBORS_DEFAULT_SQUARE_PLATE = 2; public static int MIN_NEIGHBORS_DEFAULT_SQUARE_PLATE = 2;
public static Size MIN_SIZE_DEFAULT_SQUARE_PLATE = new Size(105, 100); public static Size MIN_SIZE_DEFAULT_SQUARE_PLATE = new Size(80, 75);
public static Size MAX_SIZE_DEFAULT_SQUARE_PLATE = new Size(450, 400); public static Size MAX_SIZE_DEFAULT_SQUARE_PLATE = new Size(450, 400);
public static double SCALE_FACTOR_DEFAULT_LONG_PLATE = 1.5; public static double SCALE_FACTOR_DEFAULT_LONG_PLATE = 1.5;

View File

@ -1,106 +0,0 @@
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
namespace AIParkingApplication
{
public class PlateProcessor
{
private bool isSupportSquarePlate;
private bool isSupportLongPlate;
private PlateDetector squarePlateDetector;
private PlateDetector longPlateDetector;
public PlateProcessor(bool isSupportSquarePlate = true, bool isSupportLongPlate = false)
{
this.isSupportSquarePlate = isSupportSquarePlate;
this.isSupportLongPlate = isSupportLongPlate;
if (this.isSupportSquarePlate)
{
squarePlateDetector = new PlateDetector(PlateType.Square, PlateDetectorConstant.MIN_SIZE_DEFAULT_SQUARE_PLATE, PlateDetectorConstant.MAX_SIZE_DEFAULT_SQUARE_PLATE, PlateDetectorConstant.SCALE_FACTOR_DEFAULT_SQUARE_PLATE, PlateDetectorConstant.MIN_NEIGHBORS_DEFAULT_SQUARE_PLATE);
}
if (this.isSupportLongPlate)
{
longPlateDetector = new PlateDetector(PlateType.Long, PlateDetectorConstant.MIN_SIZE_DEFAULT_LONG_PLATE, PlateDetectorConstant.MAX_SIZE_DEFAULT_LONG_PLATE, PlateDetectorConstant.SCALE_FACTOR_DEFAULT_LONG_PLATE, PlateDetectorConstant.MIN_NEIGHBORS_DEFAULT_LONG_PLATE);
}
}
private async Task<FinalPlateResult> DetectPlateAndDoOcrEngineAsync(PlateType plateType, Mat frame)
{
//TODO: check size before resizing
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;
if (!string.IsNullOrEmpty(plateOcrResultFromEngine.Ocr) && !string.IsNullOrEmpty(plateOcrResultFromEngine.Plate))
{
byte[] imageData = Convert.FromBase64String(plateOcrResultFromEngine.Plate);
using (var ms = new MemoryStream(imageData))
{
finalPlateImage = new Bitmap(ms);
}
}
else
{
finalPlateImage = plateDetected.ToBitmap();
}
return new FinalPlateResult
{
PlateString = plateOcrResultFromEngine.Ocr,
PlateImage = finalPlateImage
};
}
public async Task<FinalPlateResult> ProcessPlate(Mat frame)
{
//TODO: check size before resizing
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
FinalPlateResult plateResult;
if (isSupportLongPlate)
{
plateResult = await DetectPlateAndDoOcrEngineAsync(PlateType.Long, frame);
if (string.IsNullOrEmpty(plateResult.PlateString))
{
plateResult = await DetectPlateAndDoOcrEngineAsync(PlateType.Square, frame);
}
}
else
{
Console.WriteLine("Recall Square Plates");
plateResult = await DetectPlateAndDoOcrEngineAsync(PlateType.Square, frame);
}
return plateResult;
}
//TODO: Complete this
private string NormalizePlateString(string plateString)
{
return plateString;
}
//TODO: Complete this
private bool IsPlateStringValid(string plateString)
{
bool isValid = true;
return isValid;
}
public class FinalPlateResult
{
public string PlateString { get; set; }
public Bitmap PlateImage { get; set; }
}
}
}