Compare commits

...

4 Commits

12 changed files with 235 additions and 12 deletions

View File

@ -93,6 +93,9 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
@ -109,7 +112,6 @@
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>

View File

@ -79,22 +79,22 @@ namespace AIParkingApplication
private void InitAllLanes()
{
laneIn12 = new LaneIn(10, configOnWeb.CameraData1.Id.ToString(), configOnWeb.CameraData1.StreamUrl, configOnWeb.CameraData2.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneIn12 = new LaneIn(10, configOnWeb.CameraData1.Id.ToString(), configOnWeb.CameraData1.StreamUrl, configOnWeb.CameraData2.StreamUrl, c3Device, apiController, engineApiController, appLogger, configOnWeb.CameraData1.Roi_config, true, false, true);
laneIn12.BorderStyle = BorderStyle.FixedSingle;
laneIn12.Hide();
Controls.Add(laneIn12);
laneOut34 = new LaneOut(20, configOnWeb.CameraData3.Id.ToString(), configOnWeb.CameraData3.StreamUrl, configOnWeb.CameraData4.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneOut34 = new LaneOut(20, configOnWeb.CameraData3.Id.ToString(), configOnWeb.CameraData3.StreamUrl, configOnWeb.CameraData4.StreamUrl, c3Device, apiController, engineApiController, appLogger, configOnWeb.CameraData3.Roi_config, true, false, true);
laneOut34.BorderStyle = BorderStyle.FixedSingle;
laneOut34.Hide();
Controls.Add(laneOut34);
laneIn56 = new LaneIn(10, configOnWeb.CameraData5.Id.ToString(), configOnWeb.CameraData5.StreamUrl, configOnWeb.CameraData6.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneIn56 = new LaneIn(10, configOnWeb.CameraData5.Id.ToString(), configOnWeb.CameraData5.StreamUrl, configOnWeb.CameraData6.StreamUrl, c3Device, apiController, engineApiController, appLogger, configOnWeb.CameraData5.Roi_config, true, false, true);
laneIn56.BorderStyle = BorderStyle.FixedSingle;
laneIn56.Hide();
Controls.Add(laneIn56);
laneOut78 = new LaneOut(20, configOnWeb.CameraData7.Id.ToString(), configOnWeb.CameraData7.StreamUrl, configOnWeb.CameraData8.StreamUrl, c3Device, apiController, engineApiController, appLogger, true, false, true);
laneOut78 = new LaneOut(20, configOnWeb.CameraData7.Id.ToString(), configOnWeb.CameraData7.StreamUrl, configOnWeb.CameraData8.StreamUrl, c3Device, apiController, engineApiController, appLogger, configOnWeb.CameraData7.Roi_config, true, false, true);
laneOut78.BorderStyle = BorderStyle.FixedSingle;
laneOut78.Hide();
Controls.Add(laneOut78);

View File

@ -5,6 +5,7 @@ using OpenCvSharp;
using Newtonsoft.Json;
using System.Net;
using NLog;
using System.Drawing;
namespace AIParkingApplication
{
@ -150,6 +151,36 @@ namespace AIParkingApplication
}
}
public async void SaveRoiToServer(Rectangle roiRegion, string cameraId)
{
int requestCounter = 1;
try
{
var request = new RoiConfig
{
CameraID = cameraId,
X = roiRegion.X,
Y = roiRegion.Y,
Width = roiRegion.Width,
Height = roiRegion.Height
};
HttpResponseMessage response;
do
{
response = await httpClient.PostAsJsonAsync("/api/update-roi", request);
response.EnsureSuccessStatusCode();
requestCounter += 1;
} while (response.StatusCode != HttpStatusCode.OK && requestCounter < numberOfRetry);
SaveLogRespone saveLogRespone = await response.Content.ReadAsAsync<SaveLogRespone>();
}
catch (Exception ex)
{
Console.WriteLine($"SaveRoiConfig Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}");
appLogger.Log(LogLevel.Error, string.Format("Không thể lưu ROI Config | exMessage: " + ex.Message));
}
}
public void Dispose()
{
if (httpClient != null && !isHttpClientDisposabled)
@ -487,6 +518,7 @@ namespace AIParkingApplication
public int Logs { get; set; }
}
#region LaneConfig
public class LaneConfig
{

View File

@ -18,6 +18,10 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -69,6 +69,10 @@
this.pictureBoxPlateVideo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBoxPlateVideo.TabIndex = 0;
this.pictureBoxPlateVideo.TabStop = false;
this.pictureBoxPlateVideo.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxPlateVideo_Paint);
this.pictureBoxPlateVideo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPlateVideo_MouseDown);
this.pictureBoxPlateVideo.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPlateVideo_MouseMove);
this.pictureBoxPlateVideo.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPlateVideo_MouseUp);
//
// grbPlateCamera
//

View File

@ -1,9 +1,11 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Printing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using NLog;
using OpenCvSharp;
using OpenCvSharp.Extensions;
@ -25,6 +27,12 @@ namespace AIParkingApplication
private ApiController apiController;
private Logger appLogger;
private System.Drawing.Point StartPoint { get; set; }
private System.Drawing.Point CurrentCursorPosition { get; set; }
private Rectangle pictureBoxRoi;
private bool IsDrawBox { get; set; }
private Rect roiBoxRect;
public LaneIn(int doorId,
string cameraId,
string plateStream,
@ -33,6 +41,7 @@ namespace AIParkingApplication
ApiController apiController,
EngineApiController engineApiController,
Logger appLogger,
string roiConfig,
bool isSupportSquarePlate = true,
bool isSupportLongPlate = false,
bool isAutoOpenDoor = true,
@ -51,6 +60,7 @@ namespace AIParkingApplication
this.apiController = apiController;
this.doorControlAccess = doorControlAccess;
plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
this.pictureBoxRoi = Util.ConvertStringToRectangle(roiConfig);
}
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
@ -147,17 +157,20 @@ namespace AIParkingApplication
private async Task<FinalPlateResult> ProcessFrameImage(PlateProcessor plateProcessor, Mat frame, bool isRetryMode)
{
var starTime = DateTime.Now;
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
roiBoxRect = Util.ConvertRectangleToRect(pictureBoxRoi, pictureBoxPlateVideo);
Mat frameRoi = frame[roiBoxRect];
try
{
var starTime = DateTime.Now;
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame);
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frameRoi);
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
{
Thread.Sleep(1000);
overviewCamera.RequestCaptureOneFrame();
finalPlateResult = await plateProcessor.ProcessPlate(frame);
finalPlateResult = await plateProcessor.ProcessPlate(frameRoi);
Console.WriteLine("ProcessFrameImage Retry Mode");
}
appLogger.Log(LogLevel.Info, $"ProcessFrameImage: {(DateTime.Now - starTime).TotalMilliseconds} ms");
@ -169,7 +182,7 @@ namespace AIParkingApplication
appLogger.Log(LogLevel.Info, $"ProcessFrameImage: ex: {ex.Message}");
return new FinalPlateResult
{
PlateImage = frame,
PlateImage = frameRoi,
PlateString = string.Empty,
PlateType = PlateType.Square
};
@ -235,5 +248,44 @@ namespace AIParkingApplication
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
ConnectToDoorAccessControl();
}
private void pictureBoxPlateVideo_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
StartPoint = e.Location;
pictureBoxRoi = new Rectangle(StartPoint, new System.Drawing.Size(0, 0));
IsDrawBox = true;
}
}
private void pictureBoxPlateVideo_MouseMove(object sender, MouseEventArgs e)
{
if (IsDrawBox)
{
CurrentCursorPosition = e.Location;
pictureBoxRoi.Width = CurrentCursorPosition.X - StartPoint.X;
pictureBoxRoi.Height = CurrentCursorPosition.Y - StartPoint.Y;
}
Refresh();
}
private void pictureBoxPlateVideo_MouseUp(object sender, MouseEventArgs e)
{
IsDrawBox = false;
if (StartPoint.X + pictureBoxRoi.Width > pictureBoxPlateVideo.Width || StartPoint.Y + pictureBoxRoi.Height > pictureBoxPlateVideo.Height)
{
pictureBoxRoi.X = pictureBoxRoi.Y = 0;
pictureBoxRoi.Width = pictureBoxPlateVideo.Width;
pictureBoxRoi.Height = pictureBoxPlateVideo.Height;
}
apiController.SaveRoiToServer(pictureBoxRoi, cameraId);
}
private void pictureBoxPlateVideo_Paint(object sender, PaintEventArgs e)
{
Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0), 3);
e.Graphics.DrawRectangle(redPen, pictureBoxRoi);
}
}
}

View File

@ -153,6 +153,12 @@
<metadata name="lblPlateString.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="lblStatusInfo.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View File

@ -182,6 +182,10 @@
this.pictureBoxPlateVideo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBoxPlateVideo.TabIndex = 0;
this.pictureBoxPlateVideo.TabStop = false;
this.pictureBoxPlateVideo.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxPlateVideo_Paint);
this.pictureBoxPlateVideo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPlateVideo_MouseDown);
this.pictureBoxPlateVideo.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPlateVideo_MouseMove);
this.pictureBoxPlateVideo.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBoxPlateVideo_MouseUp);
//
// grbPlateCamera
//

View File

@ -27,6 +27,12 @@ namespace AIParkingApplication
private Logger appLogger;
private bool isUsePrinter;
private System.Drawing.Point StartPoint { get; set; }
private System.Drawing.Point CurrentCursorPosition { get; set; }
private Rectangle pictureBoxRoi;
private bool IsDrawBox { get; set; }
private Rect roiBoxRect;
public LaneOut(int doorId,
string cameraId,
string plateStream,
@ -35,6 +41,7 @@ namespace AIParkingApplication
ApiController apiController,
EngineApiController engineApiController,
Logger appLogger,
string roiConfig,
bool isSupportSquarePlate = true,
bool isSupportLongPlate = false,
bool isAutoOpenDoor = true,
@ -55,6 +62,7 @@ namespace AIParkingApplication
printer = new Printer(appLogger);
plateProcessor = new PlateProcessor(engineApiController, this.isSupportSquarePlate, this.isSupportLongPlate);
ReadUsePrinterConfig();
this.pictureBoxRoi = Util.ConvertStringToRectangle(roiConfig);
}
private async void C3Device_OnNewCardReceived(int doorId, string cardNumber)
@ -191,10 +199,13 @@ namespace AIParkingApplication
private async Task<FinalPlateResult> ProcessFrameImage(PlateProcessor plateProcessor, Mat frame, bool isRetryMode)
{
var starTime = DateTime.Now;
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
Rect roiBoxRect = Util.ConvertRectangleToRect(pictureBoxRoi, pictureBoxPlateVideo);
Mat frameRoi = frame[roiBoxRect];
try
{
var starTime = DateTime.Now;
Cv2.Resize(frame, frame, new OpenCvSharp.Size(1280, 720));
FinalPlateResult finalPlateResult = await plateProcessor.ProcessPlate(frame);
if (isRetryMode && !plateProcessor.IsPlateStringValid(finalPlateResult.PlateString))
@ -315,5 +326,44 @@ namespace AIParkingApplication
overviewCamera.OnVideoFrameReceived += OverviewCameraOnVideoFrameReceived;
overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed;
}
private void pictureBoxPlateVideo_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
StartPoint = e.Location;
pictureBoxRoi = new Rectangle(StartPoint, new System.Drawing.Size(0, 0));
IsDrawBox = true;
}
}
private void pictureBoxPlateVideo_MouseMove(object sender, MouseEventArgs e)
{
if (IsDrawBox)
{
CurrentCursorPosition = e.Location;
pictureBoxRoi.Width = CurrentCursorPosition.X - StartPoint.X;
pictureBoxRoi.Height = CurrentCursorPosition.Y - StartPoint.Y;
}
Refresh();
}
private void pictureBoxPlateVideo_MouseUp(object sender, MouseEventArgs e)
{
IsDrawBox = false;
if (StartPoint.X + pictureBoxRoi.Width > pictureBoxPlateVideo.Width || StartPoint.Y + pictureBoxRoi.Height > pictureBoxPlateVideo.Height)
{
pictureBoxRoi.X = pictureBoxRoi.Y = 0;
pictureBoxRoi.Width = pictureBoxPlateVideo.Width;
pictureBoxRoi.Height = pictureBoxPlateVideo.Height;
}
apiController.SaveRoiToServer(pictureBoxRoi, cameraId);
}
private void pictureBoxPlateVideo_Paint(object sender, PaintEventArgs e)
{
Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0), 3);
e.Graphics.DrawRectangle(redPen, pictureBoxRoi);
}
}
}

View File

@ -126,6 +126,12 @@
<metadata name="pictureBoxPlateImageIn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pictureBoxOverviewImageIn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pictureBoxPlateImageIn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="grbCardInformation.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -147,6 +153,24 @@
<metadata name="lblCardNumber.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lblCardType.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="lblCardTimeOut.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="lblMoneyAmount.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="lblCardNumber.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="pictureBoxPlateImage.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using OpenCvSharp;
using System;
using System.Configuration;
using System.Diagnostics;
@ -7,6 +8,7 @@ using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AIParkingApplication
{
@ -135,6 +137,30 @@ namespace AIParkingApplication
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tAddOrUpdateAppSettings\t{ex.Message}");
}
}
public static Rect ConvertRectangleToRect(Rectangle pictureBoxRoi, PictureBox pictureBoxPlateVideo)
{
Rect temp = new Rect
{
X = pictureBoxRoi.X * 1280 / pictureBoxPlateVideo.Width,
Y = pictureBoxRoi.Y * 720 / pictureBoxPlateVideo.Height,
Width = pictureBoxRoi.Width * 1280 / pictureBoxPlateVideo.Width,
Height = pictureBoxRoi.Height * 720 / pictureBoxPlateVideo.Height
};
return temp;
}
public static Rectangle ConvertStringToRectangle(string input)
{
var roi = JsonConvert.DeserializeObject<RoiConfig>(input);
return new Rectangle
{
X = roi.X,
Y = roi.Y,
Height = roi.Height,
Width = roi.Width
};
}
}
public class PlateRequestEngineModel
@ -165,4 +191,22 @@ namespace AIParkingApplication
public const string HTTP_POST_METHOD = "POST";
public const string HTTP_POST_CONTENTTYPE = "application/json";
}
public class RoiConfig
{
[JsonProperty("x")]
public int X { get; set; }
[JsonProperty("y")]
public int Y { get; set; }
[JsonProperty("width")]
public int Width { get; set; }
[JsonProperty("height")]
public int Height { get; set; }
[JsonProperty("camera_id")]
public string CameraID { get; set; }
}
}

View File

@ -8,5 +8,6 @@
<package id="OpenCvSharp4" version="4.3.0.20200524" targetFramework="net461" />
<package id="OpenCvSharp4.runtime.win" version="4.3.0.20200524" targetFramework="net461" />
<package id="OpenCvSharp4.Windows" version="4.3.0.20200524" targetFramework="net461" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
</packages>