展示实时旋钮图片

This commit is contained in:
2024-07-29 17:35:37 +08:00
parent 71997776cf
commit df358a4e3a
2 changed files with 75 additions and 20 deletions

View File

@ -194,6 +194,7 @@
timer6 = new System.Windows.Forms.Timer(components);
richTextBox1 = new RichTextBox();
backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
pictureBox1 = new PictureBox();
tabPage2.SuspendLayout();
panel1.SuspendLayout();
groupBox5.SuspendLayout();
@ -218,6 +219,7 @@
tabPage3.SuspendLayout();
panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)InsertDataDgv).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
SuspendLayout();
//
// tabPage2
@ -1223,15 +1225,15 @@
// DevNameCombo
//
DevNameCombo.FormattingEnabled = true;
DevNameCombo.Location = new Point(7, 33);
DevNameCombo.Location = new Point(8, 33);
DevNameCombo.Margin = new Padding(4, 2, 4, 2);
DevNameCombo.Name = "DevNameCombo";
DevNameCombo.Size = new Size(386, 33);
DevNameCombo.Size = new Size(524, 33);
DevNameCombo.TabIndex = 1;
//
// ScanDevList
//
ScanDevList.Location = new Point(424, 32);
ScanDevList.Location = new Point(557, 33);
ScanDevList.Margin = new Padding(4, 2, 4, 2);
ScanDevList.Name = "ScanDevList";
ScanDevList.Size = new Size(94, 35);
@ -1243,6 +1245,7 @@
// groupBox2
//
groupBox2.AutoSize = true;
groupBox2.Controls.Add(pictureBox1);
groupBox2.Controls.Add(canvas3);
groupBox2.Controls.Add(canvas2);
groupBox2.Controls.Add(canvas1);
@ -1376,6 +1379,7 @@
groupBox8.Controls.Add(label35);
groupBox8.Location = new Point(11, 326);
groupBox8.Name = "groupBox8";
groupBox8.RightToLeft = RightToLeft.No;
groupBox8.Size = new Size(596, 462);
groupBox8.TabIndex = 24;
groupBox8.TabStop = false;
@ -1627,10 +1631,10 @@
// tabPage3
//
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.Name = "tabPage3";
tabPage3.Size = new Size(1276, 815);
tabPage3.Size = new Size(1276, 816);
tabPage3.TabIndex = 4;
tabPage3.Text = "录入新型号";
tabPage3.UseVisualStyleBackColor = true;
@ -1950,6 +1954,16 @@
richTextBox1.TabIndex = 1;
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
//
AutoScaleDimensions = new SizeF(12F, 25F);
@ -1999,6 +2013,7 @@
panel2.ResumeLayout(false);
panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)InsertDataDgv).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
ResumeLayout(false);
}
@ -2184,5 +2199,6 @@
private TextBox textBox4;
private Label label36;
private Label label37;
private PictureBox pictureBox1;
}
}

View File

@ -3415,24 +3415,19 @@ namespace HisenceYoloDetection
Rect rectsql = CheckDiffSciHelper.strChangeRect(SQlxK_HisenceWord.TwoRect);
Rect rectDet = CheckDiffSciHelper.strChangeRect(xK_HisenceWord.TwoRect);
bool iswhite = IsMostlyWhite(PathSql);
int centerX = rectsql.X + rectsql.Width / 2;
int centerY = rectsql.Y + rectsql.Height / 2;
// ȷ<><C8B7><EFBFBD>µľ<C2B5><C4BE>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD>
int rectSize = 60; // 30<33><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ
int rectX = Math.Max(0, centerX - rectSize / 2);
int rectY = Math.Max(0, centerY - rectSize / 2);
int rectWidth = Math.Min(rectSize, rectsql.Width - rectX);
int rectHeight = Math.Min(rectSize, rectsql.Height - rectY);
// <20><><EFBFBD><EFBFBD><EFBFBD>µľ<C2B5><C4BE>ο<EFBFBD>
Rect newRect = new Rect(rectX, rectY, rectWidth, rectHeight);
string color = BtnColor(CutBlockMat, newRect);
bool iswhite = IsMostlyWhite(PathSql);//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ݿ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><E9B1B3>ɫ
Mat SqlImg= Cv2.ImRead(PathSql);
Mat SqlBtn = GetCroppedImage(SqlImg, rectsql);
Mat BtnImg = GetCroppedImage(CutBlockMat, rectDet);//<2F><>ȡʵʱͼ<CAB1><CDBC><EFBFBD><EFBFBD>ťͼƬ
Bitmap bitmap = MatToBitmap(BtnImg);
pictureBox1.Image = bitmap;//չʾʵʱ<CAB5><CAB1>ťͼƬ
Rect newRect = GetCenterCroppedRect(SqlBtn, 30);
string color = BtnColor(SqlBtn, newRect);
this.Invoke(new Action(() =>
{
textBox2.Text = color;
textBox2.Text = color;//<2F><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ť<EFBFBD><C5A5>ɫ
}));
Mat matresult = CutBlockMat.Clone();
@ -3694,7 +3689,32 @@ namespace HisenceYoloDetection
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>0.6<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>false<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD>true
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)
{
// ȷ<><C8B7> rectDet <20><> picture <20><>Χ<EFBFBD><CEA7>
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)
);
// <20><>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
Mat croppedImage = new Mat(picture, validRect);
return croppedImage;
}
private void bnGetParam2_Click_1(object sender, EventArgs e)
{
// tbExposure2.Text = Cam2.dvpGetExposure().ToString();
@ -3736,7 +3756,26 @@ namespace HisenceYoloDetection
myLog("X<><58>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>", DateTime.Now);
}
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>ܵľ<DCB5><C4BE>ο򣨷<CEBF>ֹ<EFBFBD><D6B9>ť<EFBFBD><C5A5><EFBFBD>ܲ<EFBFBD>ͬ<EFBFBD><CDAC>ɫ<EFBFBD><C9AB>Ӱ<EFBFBD>
private Rect GetCenterCroppedRect(Mat picture, int borderSize)
{
// <20><>ȡͼ<C8A1><CDBC><EFBFBD>ߴ<EFBFBD>
int width = picture.Width;
int height = picture.Height;
// <20><><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE>ο<EFBFBD>
int newWidth = width - 2 * borderSize;
int newHeight = height - 2 * borderSize;
int x = borderSize;
int y = borderSize;
// ȷ<><C8B7><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7>
Rect validRect = new Rect(x, y, newWidth, newHeight);
validRect = validRect & new Rect(0, 0, width, height);
return validRect;
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5>ɫ
static string BtnColor(Mat img, Rect rect)
{
// <20><>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>