展示实时旋钮图片
This commit is contained in:
parent
71997776cf
commit
df358a4e3a
26
HisenceYoloDetection/MainForm.Designer.cs
generated
26
HisenceYoloDetection/MainForm.Designer.cs
generated
@ -194,6 +194,7 @@
|
|||||||
timer6 = new System.Windows.Forms.Timer(components);
|
timer6 = new System.Windows.Forms.Timer(components);
|
||||||
richTextBox1 = new RichTextBox();
|
richTextBox1 = new RichTextBox();
|
||||||
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
||||||
|
pictureBox1 = new PictureBox();
|
||||||
tabPage2.SuspendLayout();
|
tabPage2.SuspendLayout();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
groupBox5.SuspendLayout();
|
groupBox5.SuspendLayout();
|
||||||
@ -218,6 +219,7 @@
|
|||||||
tabPage3.SuspendLayout();
|
tabPage3.SuspendLayout();
|
||||||
panel2.SuspendLayout();
|
panel2.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)InsertDataDgv).BeginInit();
|
((System.ComponentModel.ISupportInitialize)InsertDataDgv).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// tabPage2
|
// tabPage2
|
||||||
@ -1223,15 +1225,15 @@
|
|||||||
// DevNameCombo
|
// DevNameCombo
|
||||||
//
|
//
|
||||||
DevNameCombo.FormattingEnabled = true;
|
DevNameCombo.FormattingEnabled = true;
|
||||||
DevNameCombo.Location = new Point(7, 33);
|
DevNameCombo.Location = new Point(8, 33);
|
||||||
DevNameCombo.Margin = new Padding(4, 2, 4, 2);
|
DevNameCombo.Margin = new Padding(4, 2, 4, 2);
|
||||||
DevNameCombo.Name = "DevNameCombo";
|
DevNameCombo.Name = "DevNameCombo";
|
||||||
DevNameCombo.Size = new Size(386, 33);
|
DevNameCombo.Size = new Size(524, 33);
|
||||||
DevNameCombo.TabIndex = 1;
|
DevNameCombo.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// ScanDevList
|
// ScanDevList
|
||||||
//
|
//
|
||||||
ScanDevList.Location = new Point(424, 32);
|
ScanDevList.Location = new Point(557, 33);
|
||||||
ScanDevList.Margin = new Padding(4, 2, 4, 2);
|
ScanDevList.Margin = new Padding(4, 2, 4, 2);
|
||||||
ScanDevList.Name = "ScanDevList";
|
ScanDevList.Name = "ScanDevList";
|
||||||
ScanDevList.Size = new Size(94, 35);
|
ScanDevList.Size = new Size(94, 35);
|
||||||
@ -1243,6 +1245,7 @@
|
|||||||
// groupBox2
|
// groupBox2
|
||||||
//
|
//
|
||||||
groupBox2.AutoSize = true;
|
groupBox2.AutoSize = true;
|
||||||
|
groupBox2.Controls.Add(pictureBox1);
|
||||||
groupBox2.Controls.Add(canvas3);
|
groupBox2.Controls.Add(canvas3);
|
||||||
groupBox2.Controls.Add(canvas2);
|
groupBox2.Controls.Add(canvas2);
|
||||||
groupBox2.Controls.Add(canvas1);
|
groupBox2.Controls.Add(canvas1);
|
||||||
@ -1376,6 +1379,7 @@
|
|||||||
groupBox8.Controls.Add(label35);
|
groupBox8.Controls.Add(label35);
|
||||||
groupBox8.Location = new Point(11, 326);
|
groupBox8.Location = new Point(11, 326);
|
||||||
groupBox8.Name = "groupBox8";
|
groupBox8.Name = "groupBox8";
|
||||||
|
groupBox8.RightToLeft = RightToLeft.No;
|
||||||
groupBox8.Size = new Size(596, 462);
|
groupBox8.Size = new Size(596, 462);
|
||||||
groupBox8.TabIndex = 24;
|
groupBox8.TabIndex = 24;
|
||||||
groupBox8.TabStop = false;
|
groupBox8.TabStop = false;
|
||||||
@ -1627,10 +1631,10 @@
|
|||||||
// tabPage3
|
// tabPage3
|
||||||
//
|
//
|
||||||
tabPage3.Controls.Add(panel2);
|
tabPage3.Controls.Add(panel2);
|
||||||
tabPage3.Location = new Point(4, 34);
|
tabPage3.Location = new Point(4, 33);
|
||||||
tabPage3.Margin = new Padding(4, 2, 4, 2);
|
tabPage3.Margin = new Padding(4, 2, 4, 2);
|
||||||
tabPage3.Name = "tabPage3";
|
tabPage3.Name = "tabPage3";
|
||||||
tabPage3.Size = new Size(1276, 815);
|
tabPage3.Size = new Size(1276, 816);
|
||||||
tabPage3.TabIndex = 4;
|
tabPage3.TabIndex = 4;
|
||||||
tabPage3.Text = "录入新型号";
|
tabPage3.Text = "录入新型号";
|
||||||
tabPage3.UseVisualStyleBackColor = true;
|
tabPage3.UseVisualStyleBackColor = true;
|
||||||
@ -1950,6 +1954,16 @@
|
|||||||
richTextBox1.TabIndex = 1;
|
richTextBox1.TabIndex = 1;
|
||||||
richTextBox1.Text = "";
|
richTextBox1.Text = "";
|
||||||
//
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
pictureBox1.Location = new Point(367, 454);
|
||||||
|
pictureBox1.Margin = new Padding(4, 2, 4, 2);
|
||||||
|
pictureBox1.Name = "pictureBox1";
|
||||||
|
pictureBox1.Size = new Size(284, 202);
|
||||||
|
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
|
||||||
|
pictureBox1.TabIndex = 12;
|
||||||
|
pictureBox1.TabStop = false;
|
||||||
|
//
|
||||||
// MainForm
|
// MainForm
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(12F, 25F);
|
AutoScaleDimensions = new SizeF(12F, 25F);
|
||||||
@ -1999,6 +2013,7 @@
|
|||||||
panel2.ResumeLayout(false);
|
panel2.ResumeLayout(false);
|
||||||
panel2.PerformLayout();
|
panel2.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)InsertDataDgv).EndInit();
|
((System.ComponentModel.ISupportInitialize)InsertDataDgv).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2184,5 +2199,6 @@
|
|||||||
private TextBox textBox4;
|
private TextBox textBox4;
|
||||||
private Label label36;
|
private Label label36;
|
||||||
private Label label37;
|
private Label label37;
|
||||||
|
private PictureBox pictureBox1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3415,24 +3415,19 @@ namespace HisenceYoloDetection
|
|||||||
|
|
||||||
Rect rectsql = CheckDiffSciHelper.strChangeRect(SQlxK_HisenceWord.TwoRect);
|
Rect rectsql = CheckDiffSciHelper.strChangeRect(SQlxK_HisenceWord.TwoRect);
|
||||||
Rect rectDet = CheckDiffSciHelper.strChangeRect(xK_HisenceWord.TwoRect);
|
Rect rectDet = CheckDiffSciHelper.strChangeRect(xK_HisenceWord.TwoRect);
|
||||||
bool iswhite = IsMostlyWhite(PathSql);
|
bool iswhite = IsMostlyWhite(PathSql);//判断数据库模板块背景色
|
||||||
int centerX = rectsql.X + rectsql.Width / 2;
|
|
||||||
int centerY = rectsql.Y + rectsql.Height / 2;
|
|
||||||
|
|
||||||
// 确定新的矩形框的左上角坐标和宽高
|
Mat SqlImg= Cv2.ImRead(PathSql);
|
||||||
int rectSize = 60; // 30像素向外拓展
|
Mat SqlBtn = GetCroppedImage(SqlImg, rectsql);
|
||||||
int rectX = Math.Max(0, centerX - rectSize / 2);
|
Mat BtnImg = GetCroppedImage(CutBlockMat, rectDet);//截取实时图像旋钮图片
|
||||||
int rectY = Math.Max(0, centerY - rectSize / 2);
|
Bitmap bitmap = MatToBitmap(BtnImg);
|
||||||
int rectWidth = Math.Min(rectSize, rectsql.Width - rectX);
|
pictureBox1.Image = bitmap;//展示实时旋钮图片
|
||||||
int rectHeight = Math.Min(rectSize, rectsql.Height - rectY);
|
Rect newRect = GetCenterCroppedRect(SqlBtn, 30);
|
||||||
|
string color = BtnColor(SqlBtn, newRect);
|
||||||
// 创建新的矩形框
|
|
||||||
Rect newRect = new Rect(rectX, rectY, rectWidth, rectHeight);
|
|
||||||
string color = BtnColor(CutBlockMat, newRect);
|
|
||||||
this.Invoke(new Action(() =>
|
this.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
|
|
||||||
textBox2.Text = color;
|
textBox2.Text = color;//数据库旋钮颜色
|
||||||
|
|
||||||
}));
|
}));
|
||||||
Mat matresult = CutBlockMat.Clone();
|
Mat matresult = CutBlockMat.Clone();
|
||||||
@ -3694,7 +3689,32 @@ namespace HisenceYoloDetection
|
|||||||
// 如果黑色比例大于等于0.6,返回false,否则返回true
|
// 如果黑色比例大于等于0.6,返回false,否则返回true
|
||||||
return blackRatio < 0.6;
|
return blackRatio < 0.6;
|
||||||
}
|
}
|
||||||
|
//Mat 转Bitmap
|
||||||
|
private Bitmap MatToBitmap(Mat mat)
|
||||||
|
{
|
||||||
|
// Convert OpenCV Mat to Bitmap
|
||||||
|
Bitmap bitmap;
|
||||||
|
using (var ms = new System.IO.MemoryStream(mat.ToBytes()))
|
||||||
|
{
|
||||||
|
bitmap = new Bitmap(ms);
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
static Mat GetCroppedImage(Mat picture, Rect rectDet)
|
||||||
|
{
|
||||||
|
// 确保 rectDet 在 picture 范围内
|
||||||
|
Rect validRect = new Rect(
|
||||||
|
Math.Max(rectDet.X, 0),
|
||||||
|
Math.Max(rectDet.Y, 0),
|
||||||
|
Math.Min(rectDet.Width, picture.Width - rectDet.X),
|
||||||
|
Math.Min(rectDet.Height, picture.Height - rectDet.Y)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 提取指定区域的子图像
|
||||||
|
Mat croppedImage = new Mat(picture, validRect);
|
||||||
|
|
||||||
|
return croppedImage;
|
||||||
|
}
|
||||||
private void bnGetParam2_Click_1(object sender, EventArgs e)
|
private void bnGetParam2_Click_1(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// tbExposure2.Text = Cam2.dvpGetExposure().ToString();
|
// tbExposure2.Text = Cam2.dvpGetExposure().ToString();
|
||||||
@ -3736,7 +3756,26 @@ namespace HisenceYoloDetection
|
|||||||
myLog("X轴停止归零", DateTime.Now);
|
myLog("X轴停止归零", DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//截取中心点四周的矩形框(防止按钮四周不同颜色的影响)
|
||||||
|
private Rect GetCenterCroppedRect(Mat picture, int borderSize)
|
||||||
|
{
|
||||||
|
// 获取图像尺寸
|
||||||
|
int width = picture.Width;
|
||||||
|
int height = picture.Height;
|
||||||
|
|
||||||
|
// 计算裁剪区域的矩形框
|
||||||
|
int newWidth = width - 2 * borderSize;
|
||||||
|
int newHeight = height - 2 * borderSize;
|
||||||
|
int x = borderSize;
|
||||||
|
int y = borderSize;
|
||||||
|
|
||||||
|
// 确保裁剪区域在图像范围内
|
||||||
|
Rect validRect = new Rect(x, y, newWidth, newHeight);
|
||||||
|
validRect = validRect & new Rect(0, 0, width, height);
|
||||||
|
|
||||||
|
return validRect;
|
||||||
|
}
|
||||||
|
//获取区域旋钮颜色
|
||||||
static string BtnColor(Mat img, Rect rect)
|
static string BtnColor(Mat img, Rect rect)
|
||||||
{
|
{
|
||||||
// 提取指定区域
|
// 提取指定区域
|
||||||
|
Loading…
Reference in New Issue
Block a user