From c0c8b325d0dd87fb2a55f346accdaa289e51e034 Mon Sep 17 00:00:00 2001 From: Le Chau Date: Fri, 17 Jul 2020 13:59:09 +0700 Subject: [PATCH] =?UTF-8?q?Th=C3=AAm=20t=C3=ADnh=20n=C4=83ng=20v=E1=BA=BD?= =?UTF-8?q?=20ROI=20v=C3=A0o=20khung=20cam=20b=E1=BA=AFt=20bi=E1=BB=83n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIParkingApplication/LaneIn.Designer.cs | 4 +++ AIParkingApplication/LaneIn.cs | 43 ++++++++++++++++++++++++ AIParkingApplication/LaneIn.resx | 6 ++++ AIParkingApplication/LaneOut.Designer.cs | 4 +++ AIParkingApplication/LaneOut.cs | 43 ++++++++++++++++++++++++ AIParkingApplication/LaneOut.resx | 24 +++++++++++++ 6 files changed, 124 insertions(+) diff --git a/AIParkingApplication/LaneIn.Designer.cs b/AIParkingApplication/LaneIn.Designer.cs index 621e917..9b48e6a 100644 --- a/AIParkingApplication/LaneIn.Designer.cs +++ b/AIParkingApplication/LaneIn.Designer.cs @@ -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 // diff --git a/AIParkingApplication/LaneIn.cs b/AIParkingApplication/LaneIn.cs index 20dd437..2fa3881 100644 --- a/AIParkingApplication/LaneIn.cs +++ b/AIParkingApplication/LaneIn.cs @@ -25,6 +25,11 @@ namespace AIParkingApplication private ApiController apiController; private Logger appLogger; + private System.Drawing.Point StartPoint { get; set; } + private System.Drawing.Point CurrentCursorPosition { get; set; } + private Rectangle roiBox; + private bool IsDrawBox { get; set; } + public LaneIn(int doorId, string cameraId, string plateStream, @@ -235,5 +240,43 @@ namespace AIParkingApplication overviewCamera.OnOpenVideoStreamFailed += OverviewCamera_OnOpenVideoStreamFailed; ConnectToDoorAccessControl(); } + + private void pictureBoxPlateVideo_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + StartPoint = e.Location; + roiBox = new Rectangle(StartPoint, new System.Drawing.Size(0, 0)); + IsDrawBox = true; + } + } + + private void pictureBoxPlateVideo_MouseMove(object sender, MouseEventArgs e) + { + if (IsDrawBox) + { + CurrentCursorPosition = e.Location; + roiBox.Width = CurrentCursorPosition.X - StartPoint.X; + roiBox.Height = CurrentCursorPosition.Y - StartPoint.Y; + } + Refresh(); + } + + private void pictureBoxPlateVideo_MouseUp(object sender, MouseEventArgs e) + { + if (StartPoint.X + roiBox.Width > pictureBoxPlateVideo.Width || StartPoint.Y + roiBox.Height > pictureBoxPlateVideo.Height) + { + roiBox.X = roiBox.Y = 0; + roiBox.Width = pictureBoxPlateVideo.Width; + roiBox.Height = pictureBoxPlateVideo.Height; + } + IsDrawBox = false; + } + + private void pictureBoxPlateVideo_Paint(object sender, PaintEventArgs e) + { + Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0), 4); + e.Graphics.DrawRectangle(redPen, roiBox); + } } } \ No newline at end of file diff --git a/AIParkingApplication/LaneIn.resx b/AIParkingApplication/LaneIn.resx index 17cd4f2..1cbfb72 100644 --- a/AIParkingApplication/LaneIn.resx +++ b/AIParkingApplication/LaneIn.resx @@ -153,6 +153,12 @@ True + + True + + + True + True diff --git a/AIParkingApplication/LaneOut.Designer.cs b/AIParkingApplication/LaneOut.Designer.cs index eb45171..09e8b4a 100644 --- a/AIParkingApplication/LaneOut.Designer.cs +++ b/AIParkingApplication/LaneOut.Designer.cs @@ -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 // diff --git a/AIParkingApplication/LaneOut.cs b/AIParkingApplication/LaneOut.cs index 517dc10..d2fcf09 100644 --- a/AIParkingApplication/LaneOut.cs +++ b/AIParkingApplication/LaneOut.cs @@ -27,6 +27,11 @@ namespace AIParkingApplication private Logger appLogger; private bool isUsePrinter; + private System.Drawing.Point StartPoint { get; set; } + private System.Drawing.Point CurrentCursorPosition { get; set; } + private Rectangle roiBox; + private bool IsDrawBox { get; set; } + public LaneOut(int doorId, string cameraId, string plateStream, @@ -315,5 +320,43 @@ 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; + roiBox = new Rectangle(StartPoint, new System.Drawing.Size(0, 0)); + IsDrawBox = true; + } + } + + private void pictureBoxPlateVideo_MouseMove(object sender, MouseEventArgs e) + { + if (IsDrawBox) + { + CurrentCursorPosition = e.Location; + roiBox.Width = CurrentCursorPosition.X - StartPoint.X; + roiBox.Height = CurrentCursorPosition.Y - StartPoint.Y; + } + Refresh(); + } + + private void pictureBoxPlateVideo_MouseUp(object sender, MouseEventArgs e) + { + if (StartPoint.X + roiBox.Width > pictureBoxPlateVideo.Width || StartPoint.Y + roiBox.Height > pictureBoxPlateVideo.Height) + { + roiBox.X = roiBox.Y = 0; + roiBox.Width = pictureBoxPlateVideo.Width; + roiBox.Height = pictureBoxPlateVideo.Height; + } + IsDrawBox = false; + } + + private void pictureBoxPlateVideo_Paint(object sender, PaintEventArgs e) + { + Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0), 4); + e.Graphics.DrawRectangle(redPen, roiBox); + } } } diff --git a/AIParkingApplication/LaneOut.resx b/AIParkingApplication/LaneOut.resx index db4e197..010a19c 100644 --- a/AIParkingApplication/LaneOut.resx +++ b/AIParkingApplication/LaneOut.resx @@ -126,6 +126,12 @@ True + + True + + + True + True @@ -147,6 +153,24 @@ True + + True + + + True + + + True + + + True + + + True + + + True + True