程序无法正常运行,代码中数据改动较多

This commit is contained in:
YZJ 2024-07-13 13:10:27 +08:00
parent 08ab697a02
commit 43a8668e7c
6 changed files with 350 additions and 302 deletions

View File

@ -77,6 +77,7 @@ namespace HisenceYoloDetection
detrect.Width += 20; detrect.Width += 20;
detrect.Height += 60; detrect.Height += 60;
Mat matCutblack1 = new Mat(thr1, sqlrect); Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord) if (IfWhiteWord)
{ {
matCutblack1.SetTo(Scalar.Black); matCutblack1.SetTo(Scalar.Black);
@ -268,7 +269,7 @@ namespace HisenceYoloDetection
} }
else else
{ {
Cv2.Threshold(gimg1, thr1, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu Cv2.Threshold(gimg1, thr1, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
} }
@ -292,7 +293,7 @@ namespace HisenceYoloDetection
} }
else else
{ {
Cv2.Threshold(gimg2, thr2, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
} }
@ -324,35 +325,36 @@ namespace HisenceYoloDetection
DateTime dt = DateTime.Now; DateTime dt = DateTime.Now;
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString(); string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString();
//string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png"); string savePath4 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr1.png");
//// 保存结果 // 保存结果
//Cv2.ImWrite(savePath4, thr1); Cv2.ImWrite(savePath4, thr1);
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png"); string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
//// 保存结果 // 保存结果
//Cv2.ImWrite(savePath3, thr2); Cv2.ImWrite(savePath3, thr2);
// 创建卷积核 // 创建卷积核
Mat filter1 = new Mat(15,15, MatType.CV_32F, new Scalar(0));
filter1.Row(7).SetTo(new Scalar(0.025));
filter1.Col(7).SetTo(new Scalar(0.025));
Mat filter1 = new Mat(15, 15, MatType.CV_32F, new Scalar(0));
filter1.Row(7).SetTo(new Scalar(0.025));
filter1.Row(7).SetTo(new Scalar(0.025));
// 应用卷积 // 应用卷积
Mat final_result1 = new Mat(); Mat final_result1 = new Mat();
Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); Cv2.Filter2D(thr1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); Cv2.Filter2D(final_result1, final_result1, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//Cv2.Filter2D(final_result1, final_result1, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); //Cv2.Filter2D(final_result1, final_result1, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Mat final_result2 = new Mat(); Mat final_result2 = new Mat();
Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); Cv2.Filter2D(thr2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); Cv2.Filter2D(final_result2, final_result2, -1, filter1, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//Cv2.Filter2D(final_result2, final_result2, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect); //Cv2.Filter2D(final_result2, final_result2, -1, filter2, anchor: new Point(-1, -1), 0, BorderTypes.Reflect);
//裁剪才行 //裁剪才行
@ -377,25 +379,25 @@ namespace HisenceYoloDetection
Mat devIMG_ = new Mat(); Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, devIMG); Cv2.Subtract(final_result1, final_result2, devIMG);
Cv2.Subtract(final_result2, final_result1, devIMG_); Cv2.Subtract(final_result2, final_result1, devIMG_);
//string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png"); string savePathd = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG.png");
//// 保存结果 // 保存结果
//Cv2.ImWrite(savePathd, devIMG); Cv2.ImWrite(savePathd, devIMG);
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png"); string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
//// 保存结果 // 保存结果
//Cv2.ImWrite(savePathd1, devIMG_); Cv2.ImWrite(savePathd1, devIMG_);
// 对差异图像应用阈值 // 对差异图像应用阈值
Cv2.Threshold(devIMG, devIMG, 45, 255, ThresholdTypes.Binary); Cv2.Threshold(devIMG, devIMG, 9, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 45, 255, ThresholdTypes.Binary); Cv2.Threshold(devIMG_, devIMG_, 9, 255, ThresholdTypes.Binary);
// 结合差异 // 结合差异
Mat sumIMG = new Mat(); Mat sumIMG = new Mat();
Cv2.Add(devIMG, devIMG_, sumIMG); Cv2.Add(devIMG, devIMG_, sumIMG);
//string savePaths = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "sumIMG.png"); string savePaths = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "sumIMG.png");
//// 保存结果 // 保存结果
//Cv2.ImWrite(savePaths, sumIMG); Cv2.ImWrite(savePaths, sumIMG);
// 应用形态学操作 // 应用形态学操作
Mat kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3)); Mat kernelCL = Cv2.GetStructuringElement(MorphShapes.Rect, new Size(3, 3));
Mat blackhatImg = new Mat(); Mat blackhatImg = new Mat();
@ -407,7 +409,7 @@ namespace HisenceYoloDetection
bool isMatch = true; bool isMatch = true;
foreach (var contour in contours) foreach (var contour in contours)
{ {
if (Cv2.ContourArea(contour) <= 100) if (Cv2.ContourArea(contour) <= 500)
{ {
Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED); Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED);
// 框选轮廓 // 框选轮廓
@ -434,3 +436,4 @@ namespace HisenceYoloDetection
} }
} }
} }

View File

@ -29,10 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
components = new System.ComponentModel.Container(); components = new System.ComponentModel.Container();
OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat2 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat1 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat2 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat3 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat4 = new OpenCvSharp.Mat();
OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat(); OpenCvSharp.Mat mat5 = new OpenCvSharp.Mat();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
tabPage2 = new TabPage(); tabPage2 = new TabPage();
@ -125,9 +125,14 @@
panel4 = new Panel(); panel4 = new Panel();
panel5 = new Panel(); panel5 = new Panel();
groupBox2 = new GroupBox(); groupBox2 = new GroupBox();
canvas4 = new XKRS.UI.Canvas();
canvas3 = new XKRS.UI.Canvas();
canvas2 = new XKRS.UI.Canvas();
canvas1 = new XKRS.UI.Canvas();
originMatShow = new PictureBox(); originMatShow = new PictureBox();
ResultMatShow = new PictureBox(); ResultMatShow = new PictureBox();
panel8 = new Panel(); panel8 = new Panel();
canvas5 = new XKRS.UI.Canvas();
textBox2 = new TextBox(); textBox2 = new TextBox();
label36 = new Label(); label36 = new Label();
textBox1 = new TextBox(); textBox1 = new TextBox();
@ -189,11 +194,6 @@
richTextBox1 = new RichTextBox(); richTextBox1 = new RichTextBox();
contextMenuStrip1 = new ContextMenuStrip(components); contextMenuStrip1 = new ContextMenuStrip(components);
backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
canvas1 = new XKRS.UI.Canvas();
canvas2 = new XKRS.UI.Canvas();
canvas3 = new XKRS.UI.Canvas();
canvas4 = new XKRS.UI.Canvas();
canvas5 = new XKRS.UI.Canvas();
tabPage2.SuspendLayout(); tabPage2.SuspendLayout();
panel1.SuspendLayout(); panel1.SuspendLayout();
groupBox5.SuspendLayout(); groupBox5.SuspendLayout();
@ -271,7 +271,7 @@
DistanceShow.Margin = new Padding(4, 2, 4, 2); DistanceShow.Margin = new Padding(4, 2, 4, 2);
DistanceShow.Name = "DistanceShow"; DistanceShow.Name = "DistanceShow";
DistanceShow.ReadOnly = true; DistanceShow.ReadOnly = true;
DistanceShow.Size = new Size(127, 23); DistanceShow.Size = new Size(117, 23);
DistanceShow.TabIndex = 10; DistanceShow.TabIndex = 10;
// //
// label21 // label21
@ -322,11 +322,11 @@
groupBox4.Controls.Add(label13); groupBox4.Controls.Add(label13);
groupBox4.Controls.Add(label12); groupBox4.Controls.Add(label12);
groupBox4.Controls.Add(label11); groupBox4.Controls.Add(label11);
groupBox4.Location = new Point(786, 101); groupBox4.Location = new Point(622, 101);
groupBox4.Margin = new Padding(4, 2, 4, 2); groupBox4.Margin = new Padding(4, 2, 4, 2);
groupBox4.Name = "groupBox4"; groupBox4.Name = "groupBox4";
groupBox4.Padding = new Padding(4, 2, 4, 2); groupBox4.Padding = new Padding(4, 2, 4, 2);
groupBox4.Size = new Size(716, 351); groupBox4.Size = new Size(880, 351);
groupBox4.TabIndex = 13; groupBox4.TabIndex = 13;
groupBox4.TabStop = false; groupBox4.TabStop = false;
groupBox4.Text = "位置显示"; groupBox4.Text = "位置显示";
@ -358,7 +358,7 @@
SetlnEditmiZOP.Location = new Point(526, 296); SetlnEditmiZOP.Location = new Point(526, 296);
SetlnEditmiZOP.Margin = new Padding(4, 2, 4, 2); SetlnEditmiZOP.Margin = new Padding(4, 2, 4, 2);
SetlnEditmiZOP.Name = "SetlnEditmiZOP"; SetlnEditmiZOP.Name = "SetlnEditmiZOP";
SetlnEditmiZOP.Size = new Size(127, 23); SetlnEditmiZOP.Size = new Size(116, 23);
SetlnEditmiZOP.TabIndex = 27; SetlnEditmiZOP.TabIndex = 27;
// //
// SetlnEditmiYOP // SetlnEditmiYOP
@ -382,7 +382,7 @@
SetlnEditmiZH.Location = new Point(526, 242); SetlnEditmiZH.Location = new Point(526, 242);
SetlnEditmiZH.Margin = new Padding(4, 2, 4, 2); SetlnEditmiZH.Margin = new Padding(4, 2, 4, 2);
SetlnEditmiZH.Name = "SetlnEditmiZH"; SetlnEditmiZH.Name = "SetlnEditmiZH";
SetlnEditmiZH.Size = new Size(127, 23); SetlnEditmiZH.Size = new Size(116, 23);
SetlnEditmiZH.TabIndex = 23; SetlnEditmiZH.TabIndex = 23;
// //
// SetlnEditmiYH // SetlnEditmiYH
@ -406,7 +406,7 @@
lnEditmiZOP.Location = new Point(526, 189); lnEditmiZOP.Location = new Point(526, 189);
lnEditmiZOP.Margin = new Padding(4, 2, 4, 2); lnEditmiZOP.Margin = new Padding(4, 2, 4, 2);
lnEditmiZOP.Name = "lnEditmiZOP"; lnEditmiZOP.Name = "lnEditmiZOP";
lnEditmiZOP.Size = new Size(127, 23); lnEditmiZOP.Size = new Size(116, 23);
lnEditmiZOP.TabIndex = 19; lnEditmiZOP.TabIndex = 19;
// //
// lnEditmiYOP // lnEditmiYOP
@ -441,7 +441,7 @@
lnEditmiZS.Margin = new Padding(4, 2, 4, 2); lnEditmiZS.Margin = new Padding(4, 2, 4, 2);
lnEditmiZS.Name = "lnEditmiZS"; lnEditmiZS.Name = "lnEditmiZS";
lnEditmiZS.ReadOnly = true; lnEditmiZS.ReadOnly = true;
lnEditmiZS.Size = new Size(127, 23); lnEditmiZS.Size = new Size(116, 23);
lnEditmiZS.TabIndex = 15; lnEditmiZS.TabIndex = 15;
// //
// lnEditmiYS // lnEditmiYS
@ -478,7 +478,7 @@
lnEditmiZHS.Margin = new Padding(4, 2, 4, 2); lnEditmiZHS.Margin = new Padding(4, 2, 4, 2);
lnEditmiZHS.Name = "lnEditmiZHS"; lnEditmiZHS.Name = "lnEditmiZHS";
lnEditmiZHS.ReadOnly = true; lnEditmiZHS.ReadOnly = true;
lnEditmiZHS.Size = new Size(127, 23); lnEditmiZHS.Size = new Size(116, 23);
lnEditmiZHS.TabIndex = 11; lnEditmiZHS.TabIndex = 11;
// //
// lnEditmiYHS // lnEditmiYHS
@ -608,17 +608,17 @@
ModeleShow.Margin = new Padding(4, 2, 4, 2); ModeleShow.Margin = new Padding(4, 2, 4, 2);
ModeleShow.Name = "ModeleShow"; ModeleShow.Name = "ModeleShow";
ModeleShow.Padding = new Padding(4, 2, 4, 2); ModeleShow.Padding = new Padding(4, 2, 4, 2);
ModeleShow.Size = new Size(744, 351); ModeleShow.Size = new Size(596, 351);
ModeleShow.TabIndex = 12; ModeleShow.TabIndex = 12;
ModeleShow.TabStop = false; ModeleShow.TabStop = false;
ModeleShow.Text = "模组显示"; ModeleShow.Text = "模组显示";
// //
// handStopBtn // handStopBtn
// //
handStopBtn.Location = new Point(342, 250); handStopBtn.Location = new Point(323, 250);
handStopBtn.Margin = new Padding(4, 2, 4, 2); handStopBtn.Margin = new Padding(4, 2, 4, 2);
handStopBtn.Name = "handStopBtn"; handStopBtn.Name = "handStopBtn";
handStopBtn.Size = new Size(161, 78); handStopBtn.Size = new Size(107, 78);
handStopBtn.TabIndex = 23; handStopBtn.TabIndex = 23;
handStopBtn.Text = "手动阻塞"; handStopBtn.Text = "手动阻塞";
handStopBtn.UseVisualStyleBackColor = true; handStopBtn.UseVisualStyleBackColor = true;
@ -626,10 +626,10 @@
// //
// HandRuningBtn // HandRuningBtn
// //
HandRuningBtn.Location = new Point(527, 250); HandRuningBtn.Location = new Point(466, 250);
HandRuningBtn.Margin = new Padding(4, 2, 4, 2); HandRuningBtn.Margin = new Padding(4, 2, 4, 2);
HandRuningBtn.Name = "HandRuningBtn"; HandRuningBtn.Name = "HandRuningBtn";
HandRuningBtn.Size = new Size(161, 78); HandRuningBtn.Size = new Size(106, 78);
HandRuningBtn.TabIndex = 22; HandRuningBtn.TabIndex = 22;
HandRuningBtn.Text = "手动放行"; HandRuningBtn.Text = "手动放行";
HandRuningBtn.UseVisualStyleBackColor = true; HandRuningBtn.UseVisualStyleBackColor = true;
@ -638,10 +638,10 @@
// ZBackwardrbx // ZBackwardrbx
// //
ZBackwardrbx.Appearance = Appearance.Button; ZBackwardrbx.Appearance = Appearance.Button;
ZBackwardrbx.Location = new Point(527, 169); ZBackwardrbx.Location = new Point(466, 169);
ZBackwardrbx.Margin = new Padding(4, 2, 4, 2); ZBackwardrbx.Margin = new Padding(4, 2, 4, 2);
ZBackwardrbx.Name = "ZBackwardrbx"; ZBackwardrbx.Name = "ZBackwardrbx";
ZBackwardrbx.Size = new Size(161, 58); ZBackwardrbx.Size = new Size(106, 58);
ZBackwardrbx.TabIndex = 21; ZBackwardrbx.TabIndex = 21;
ZBackwardrbx.Text = "Z反向"; ZBackwardrbx.Text = "Z反向";
ZBackwardrbx.TextAlign = ContentAlignment.MiddleCenter; ZBackwardrbx.TextAlign = ContentAlignment.MiddleCenter;
@ -651,10 +651,10 @@
// YBackwardrbx // YBackwardrbx
// //
YBackwardrbx.Appearance = Appearance.Button; YBackwardrbx.Appearance = Appearance.Button;
YBackwardrbx.Location = new Point(342, 169); YBackwardrbx.Location = new Point(323, 169);
YBackwardrbx.Margin = new Padding(4, 2, 4, 2); YBackwardrbx.Margin = new Padding(4, 2, 4, 2);
YBackwardrbx.Name = "YBackwardrbx"; YBackwardrbx.Name = "YBackwardrbx";
YBackwardrbx.Size = new Size(161, 58); YBackwardrbx.Size = new Size(107, 58);
YBackwardrbx.TabIndex = 20; YBackwardrbx.TabIndex = 20;
YBackwardrbx.Text = "Y反向"; YBackwardrbx.Text = "Y反向";
YBackwardrbx.TextAlign = ContentAlignment.MiddleCenter; YBackwardrbx.TextAlign = ContentAlignment.MiddleCenter;
@ -667,7 +667,7 @@
XBackwardrbx.Location = new Point(162, 169); XBackwardrbx.Location = new Point(162, 169);
XBackwardrbx.Margin = new Padding(4, 2, 4, 2); XBackwardrbx.Margin = new Padding(4, 2, 4, 2);
XBackwardrbx.Name = "XBackwardrbx"; XBackwardrbx.Name = "XBackwardrbx";
XBackwardrbx.Size = new Size(161, 58); XBackwardrbx.Size = new Size(116, 58);
XBackwardrbx.TabIndex = 19; XBackwardrbx.TabIndex = 19;
XBackwardrbx.Text = "X反向"; XBackwardrbx.Text = "X反向";
XBackwardrbx.TextAlign = ContentAlignment.MiddleCenter; XBackwardrbx.TextAlign = ContentAlignment.MiddleCenter;
@ -677,10 +677,10 @@
// ZForwardrbx // ZForwardrbx
// //
ZForwardrbx.Appearance = Appearance.Button; ZForwardrbx.Appearance = Appearance.Button;
ZForwardrbx.Location = new Point(527, 98); ZForwardrbx.Location = new Point(466, 98);
ZForwardrbx.Margin = new Padding(4, 2, 4, 2); ZForwardrbx.Margin = new Padding(4, 2, 4, 2);
ZForwardrbx.Name = "ZForwardrbx"; ZForwardrbx.Name = "ZForwardrbx";
ZForwardrbx.Size = new Size(161, 58); ZForwardrbx.Size = new Size(106, 58);
ZForwardrbx.TabIndex = 18; ZForwardrbx.TabIndex = 18;
ZForwardrbx.Text = "Z正向"; ZForwardrbx.Text = "Z正向";
ZForwardrbx.TextAlign = ContentAlignment.MiddleCenter; ZForwardrbx.TextAlign = ContentAlignment.MiddleCenter;
@ -690,10 +690,10 @@
// YForwardrbx // YForwardrbx
// //
YForwardrbx.Appearance = Appearance.Button; YForwardrbx.Appearance = Appearance.Button;
YForwardrbx.Location = new Point(342, 96); YForwardrbx.Location = new Point(323, 97);
YForwardrbx.Margin = new Padding(4, 2, 4, 2); YForwardrbx.Margin = new Padding(4, 2, 4, 2);
YForwardrbx.Name = "YForwardrbx"; YForwardrbx.Name = "YForwardrbx";
YForwardrbx.Size = new Size(161, 58); YForwardrbx.Size = new Size(107, 58);
YForwardrbx.TabIndex = 17; YForwardrbx.TabIndex = 17;
YForwardrbx.Text = "Y正向"; YForwardrbx.Text = "Y正向";
YForwardrbx.TextAlign = ContentAlignment.MiddleCenter; YForwardrbx.TextAlign = ContentAlignment.MiddleCenter;
@ -706,7 +706,7 @@
XForwardrbx.Location = new Point(162, 98); XForwardrbx.Location = new Point(162, 98);
XForwardrbx.Margin = new Padding(4, 2, 4, 2); XForwardrbx.Margin = new Padding(4, 2, 4, 2);
XForwardrbx.Name = "XForwardrbx"; XForwardrbx.Name = "XForwardrbx";
XForwardrbx.Size = new Size(161, 58); XForwardrbx.Size = new Size(116, 58);
XForwardrbx.TabIndex = 16; XForwardrbx.TabIndex = 16;
XForwardrbx.Text = "X正向"; XForwardrbx.Text = "X正向";
XForwardrbx.TextAlign = ContentAlignment.MiddleCenter; XForwardrbx.TextAlign = ContentAlignment.MiddleCenter;
@ -716,10 +716,10 @@
// ZZerorbx // ZZerorbx
// //
ZZerorbx.Appearance = Appearance.Button; ZZerorbx.Appearance = Appearance.Button;
ZZerorbx.Location = new Point(527, 21); ZZerorbx.Location = new Point(466, 21);
ZZerorbx.Margin = new Padding(4, 2, 4, 2); ZZerorbx.Margin = new Padding(4, 2, 4, 2);
ZZerorbx.Name = "ZZerorbx"; ZZerorbx.Name = "ZZerorbx";
ZZerorbx.Size = new Size(161, 58); ZZerorbx.Size = new Size(106, 58);
ZZerorbx.TabIndex = 15; ZZerorbx.TabIndex = 15;
ZZerorbx.Text = "Z归零"; ZZerorbx.Text = "Z归零";
ZZerorbx.TextAlign = ContentAlignment.MiddleCenter; ZZerorbx.TextAlign = ContentAlignment.MiddleCenter;
@ -729,10 +729,10 @@
// YZerorbx // YZerorbx
// //
YZerorbx.Appearance = Appearance.Button; YZerorbx.Appearance = Appearance.Button;
YZerorbx.Location = new Point(342, 21); YZerorbx.Location = new Point(323, 20);
YZerorbx.Margin = new Padding(4, 2, 4, 2); YZerorbx.Margin = new Padding(4, 2, 4, 2);
YZerorbx.Name = "YZerorbx"; YZerorbx.Name = "YZerorbx";
YZerorbx.Size = new Size(161, 58); YZerorbx.Size = new Size(107, 59);
YZerorbx.TabIndex = 14; YZerorbx.TabIndex = 14;
YZerorbx.Text = "Y归零"; YZerorbx.Text = "Y归零";
YZerorbx.TextAlign = ContentAlignment.MiddleCenter; YZerorbx.TextAlign = ContentAlignment.MiddleCenter;
@ -745,7 +745,7 @@
XZerorbx.Location = new Point(162, 21); XZerorbx.Location = new Point(162, 21);
XZerorbx.Margin = new Padding(4, 2, 4, 2); XZerorbx.Margin = new Padding(4, 2, 4, 2);
XZerorbx.Name = "XZerorbx"; XZerorbx.Name = "XZerorbx";
XZerorbx.Size = new Size(161, 58); XZerorbx.Size = new Size(116, 58);
XZerorbx.TabIndex = 13; XZerorbx.TabIndex = 13;
XZerorbx.Text = "X归零"; XZerorbx.Text = "X归零";
XZerorbx.TextAlign = ContentAlignment.MiddleCenter; XZerorbx.TextAlign = ContentAlignment.MiddleCenter;
@ -757,7 +757,7 @@
PLCPostion.Location = new Point(8, 250); PLCPostion.Location = new Point(8, 250);
PLCPostion.Margin = new Padding(4, 2, 4, 2); PLCPostion.Margin = new Padding(4, 2, 4, 2);
PLCPostion.Name = "PLCPostion"; PLCPostion.Name = "PLCPostion";
PLCPostion.Size = new Size(125, 95); PLCPostion.Size = new Size(99, 95);
PLCPostion.TabIndex = 2; PLCPostion.TabIndex = 2;
PLCPostion.Text = "定位"; PLCPostion.Text = "定位";
PLCPostion.UseVisualStyleBackColor = true; PLCPostion.UseVisualStyleBackColor = true;
@ -768,7 +768,7 @@
PLCDiskZero.Location = new Point(8, 133); PLCDiskZero.Location = new Point(8, 133);
PLCDiskZero.Margin = new Padding(4, 2, 4, 2); PLCDiskZero.Margin = new Padding(4, 2, 4, 2);
PLCDiskZero.Name = "PLCDiskZero"; PLCDiskZero.Name = "PLCDiskZero";
PLCDiskZero.Size = new Size(125, 95); PLCDiskZero.Size = new Size(99, 95);
PLCDiskZero.TabIndex = 1; PLCDiskZero.TabIndex = 1;
PLCDiskZero.Text = "归零"; PLCDiskZero.Text = "归零";
PLCDiskZero.UseVisualStyleBackColor = true; PLCDiskZero.UseVisualStyleBackColor = true;
@ -779,7 +779,7 @@
PLCPowerON.Location = new Point(8, 21); PLCPowerON.Location = new Point(8, 21);
PLCPowerON.Margin = new Padding(4, 2, 4, 2); PLCPowerON.Margin = new Padding(4, 2, 4, 2);
PLCPowerON.Name = "PLCPowerON"; PLCPowerON.Name = "PLCPowerON";
PLCPowerON.Size = new Size(125, 95); PLCPowerON.Size = new Size(99, 95);
PLCPowerON.TabIndex = 0; PLCPowerON.TabIndex = 0;
PLCPowerON.Text = "使能ON"; PLCPowerON.Text = "使能ON";
PLCPowerON.UseVisualStyleBackColor = true; PLCPowerON.UseVisualStyleBackColor = true;
@ -1220,6 +1220,90 @@
groupBox2.Text = "图片"; groupBox2.Text = "图片";
groupBox2.Enter += groupBox2_Enter; groupBox2.Enter += groupBox2_Enter;
// //
// canvas4
//
canvas4.AllowSelectDefect = true;
canvas4.BrushColor = null;
canvas4.ImagePath = "";
mat1.IsEnabledDispose = true;
canvas4.ImaMAt = mat1;
canvas4.ImgData = null;
canvas4.Location = new Point(367, 517);
canvas4.MoveStep = 5F;
canvas4.Name = "canvas4";
canvas4.Route = 0D;
canvas4.Scale = 1D;
canvas4.Size = new Size(351, 198);
canvas4.TabIndex = 7;
canvas4.WholeScale = 0F;
canvas4.XMove = 0F;
canvas4.XScale = 0F;
canvas4.YMove = 0F;
canvas4.YScale = 0F;
//
// canvas3
//
canvas3.AllowSelectDefect = true;
canvas3.BrushColor = null;
canvas3.ImagePath = "";
mat2.IsEnabledDispose = true;
canvas3.ImaMAt = mat2;
canvas3.ImgData = null;
canvas3.Location = new Point(0, 515);
canvas3.MoveStep = 5F;
canvas3.Name = "canvas3";
canvas3.Route = 0D;
canvas3.Scale = 1D;
canvas3.Size = new Size(351, 198);
canvas3.TabIndex = 6;
canvas3.WholeScale = 0F;
canvas3.XMove = 0F;
canvas3.XScale = 0F;
canvas3.YMove = 0F;
canvas3.YScale = 0F;
//
// canvas2
//
canvas2.AllowSelectDefect = true;
canvas2.BrushColor = null;
canvas2.ImagePath = "";
mat3.IsEnabledDispose = true;
canvas2.ImaMAt = mat3;
canvas2.ImgData = null;
canvas2.Location = new Point(367, 237);
canvas2.MoveStep = 5F;
canvas2.Name = "canvas2";
canvas2.Route = 0D;
canvas2.Scale = 1D;
canvas2.Size = new Size(351, 198);
canvas2.TabIndex = 5;
canvas2.WholeScale = 0F;
canvas2.XMove = 0F;
canvas2.XScale = 0F;
canvas2.YMove = 0F;
canvas2.YScale = 0F;
//
// canvas1
//
canvas1.AllowSelectDefect = true;
canvas1.BrushColor = null;
canvas1.ImagePath = "";
mat4.IsEnabledDispose = true;
canvas1.ImaMAt = mat4;
canvas1.ImgData = null;
canvas1.Location = new Point(8, 237);
canvas1.MoveStep = 5F;
canvas1.Name = "canvas1";
canvas1.Route = 0D;
canvas1.Scale = 1D;
canvas1.Size = new Size(351, 198);
canvas1.TabIndex = 4;
canvas1.WholeScale = 0F;
canvas1.XMove = 0F;
canvas1.XScale = 0F;
canvas1.YMove = 0F;
canvas1.YScale = 0F;
//
// originMatShow // originMatShow
// //
originMatShow.Location = new Point(8, 21); originMatShow.Location = new Point(8, 21);
@ -1266,6 +1350,27 @@
panel8.TabIndex = 2; panel8.TabIndex = 2;
panel8.Paint += panel8_Paint; panel8.Paint += panel8_Paint;
// //
// canvas5
//
canvas5.AllowSelectDefect = true;
canvas5.BrushColor = null;
canvas5.ImagePath = "";
mat5.IsEnabledDispose = true;
canvas5.ImaMAt = mat5;
canvas5.ImgData = null;
canvas5.Location = new Point(7, 515);
canvas5.MoveStep = 5F;
canvas5.Name = "canvas5";
canvas5.Route = 0D;
canvas5.Scale = 1D;
canvas5.Size = new Size(351, 198);
canvas5.TabIndex = 18;
canvas5.WholeScale = 0F;
canvas5.XMove = 0F;
canvas5.XScale = 0F;
canvas5.YMove = 0F;
canvas5.YScale = 0F;
//
// textBox2 // textBox2
// //
textBox2.Location = new Point(437, 287); textBox2.Location = new Point(437, 287);
@ -1828,111 +1933,6 @@
contextMenuStrip1.Name = "contextMenuStrip1"; contextMenuStrip1.Name = "contextMenuStrip1";
contextMenuStrip1.Size = new Size(61, 4); contextMenuStrip1.Size = new Size(61, 4);
// //
// canvas1
//
canvas1.AllowSelectDefect = true;
canvas1.BrushColor = null;
canvas1.ImagePath = "";
mat4.IsEnabledDispose = true;
canvas1.ImaMAt = mat4;
canvas1.ImgData = null;
canvas1.Location = new Point(8, 237);
canvas1.MoveStep = 5F;
canvas1.Name = "canvas1";
canvas1.Route = 0D;
canvas1.Scale = 1D;
canvas1.Size = new Size(351, 198);
canvas1.TabIndex = 4;
canvas1.WholeScale = 0F;
canvas1.XMove = 0F;
canvas1.XScale = 0F;
canvas1.YMove = 0F;
canvas1.YScale = 0F;
//
// canvas2
//
canvas2.AllowSelectDefect = true;
canvas2.BrushColor = null;
canvas2.ImagePath = "";
mat3.IsEnabledDispose = true;
canvas2.ImaMAt = mat3;
canvas2.ImgData = null;
canvas2.Location = new Point(367, 237);
canvas2.MoveStep = 5F;
canvas2.Name = "canvas2";
canvas2.Route = 0D;
canvas2.Scale = 1D;
canvas2.Size = new Size(351, 198);
canvas2.TabIndex = 5;
canvas2.WholeScale = 0F;
canvas2.XMove = 0F;
canvas2.XScale = 0F;
canvas2.YMove = 0F;
canvas2.YScale = 0F;
//
// canvas3
//
canvas3.AllowSelectDefect = true;
canvas3.BrushColor = null;
canvas3.ImagePath = "";
mat2.IsEnabledDispose = true;
canvas3.ImaMAt = mat2;
canvas3.ImgData = null;
canvas3.Location = new Point(0, 515);
canvas3.MoveStep = 5F;
canvas3.Name = "canvas3";
canvas3.Route = 0D;
canvas3.Scale = 1D;
canvas3.Size = new Size(351, 198);
canvas3.TabIndex = 6;
canvas3.WholeScale = 0F;
canvas3.XMove = 0F;
canvas3.XScale = 0F;
canvas3.YMove = 0F;
canvas3.YScale = 0F;
//
// canvas4
//
canvas4.AllowSelectDefect = true;
canvas4.BrushColor = null;
canvas4.ImagePath = "";
mat1.IsEnabledDispose = true;
canvas4.ImaMAt = mat1;
canvas4.ImgData = null;
canvas4.Location = new Point(367, 517);
canvas4.MoveStep = 5F;
canvas4.Name = "canvas4";
canvas4.Route = 0D;
canvas4.Scale = 1D;
canvas4.Size = new Size(351, 198);
canvas4.TabIndex = 7;
canvas4.WholeScale = 0F;
canvas4.XMove = 0F;
canvas4.XScale = 0F;
canvas4.YMove = 0F;
canvas4.YScale = 0F;
//
// canvas5
//
canvas5.AllowSelectDefect = true;
canvas5.BrushColor = null;
canvas5.ImagePath = "";
mat5.IsEnabledDispose = true;
canvas5.ImaMAt = mat5;
canvas5.ImgData = null;
canvas5.Location = new Point(7, 515);
canvas5.MoveStep = 5F;
canvas5.Name = "canvas5";
canvas5.Route = 0D;
canvas5.Scale = 1D;
canvas5.Size = new Size(351, 198);
canvas5.TabIndex = 18;
canvas5.WholeScale = 0F;
canvas5.XMove = 0F;
canvas5.XScale = 0F;
canvas5.YMove = 0F;
canvas5.YScale = 0F;
//
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(8F, 17F); AutoScaleDimensions = new SizeF(8F, 17F);

View File

@ -112,10 +112,10 @@ namespace HisenceYoloDetection
string Cam1TwoPath = ""; string Cam1TwoPath = "";
string ModelChangePath = ""; string ModelChangePath = "";
//报警灯 //报警灯
string GreenLightingAdress = ""; string GreenLightingAdress = "556";
string YellowLightingAdress = ""; string YellowLightingAdress = "554";
string RedLightingAdress = ""; string RedLightingAdress = "552";
string WaringAdress = ""; string WaringAdress = "558";
/// <summary> /// <summary>
/// 查看相机列表 /// 查看相机列表
/// </summary> /// </summary>
@ -289,89 +289,121 @@ namespace HisenceYoloDetection
/// <param name="ContentType">默认 application/json , application/x-www-form-urlencoded,multipart/form-data,raw,binary </param> /// <param name="ContentType">默认 application/json , application/x-www-form-urlencoded,multipart/form-data,raw,binary </param>
/// <param name="Accept">默认application/json</param> /// <param name="Accept">默认application/json</param>
/// <returns></returns> /// <returns></returns>
public string Post(string parameterData, string serviceUrl, string ContentType = "application/json", string Accept = "application/json") //public string Post(string parameterData, string serviceUrl, string contentType = "application/x-www-form-urlencoded", string accept = "application/json")
//{
// try
// {
// // 创建 Web 请求对象
// HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
// byte[] buf = Encoding.UTF8.GetBytes($"inputvalue={Uri.EscapeDataString(parameterData)}");
// myRequest.Method = "POST";
// myRequest.Accept = accept;
// myRequest.ContentType = contentType;
// myRequest.ContentLength = buf.Length;
// // 发送请求
// using (Stream stream = myRequest.GetRequestStream())
// {
// stream.Write(buf, 0, buf.Length);
// }
// // 获取响应内容
// using (HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse())
// using (StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8))
// {
// return reader.ReadToEnd();
// }
// }
// catch (WebException ex)
// {
// if (ex.Response != null)
// {
// using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
// {
// string errorResponse = reader.ReadToEnd();
// Console.WriteLine("WebException: " + errorResponse);
// return errorResponse;
// }
// }
// else
// {
// Console.WriteLine("WebException: " + ex.Message);
// return null;
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine("Exception: " + ex.Message);
// return null;
// }
//}
#endregion
/// <summary>
/// 主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{ {
//先根据用户请求的uri构造请求地址 //string path3 = "D:\\Hisence\\Test1\\3.jpg";
//string serviceUrl = string.Format("{0}/{1}", this.BaseUri, uri); //Mat pathmat = Cv2.ImRead(path3);
//string path2 = "D:\\Hisence\\Test1\\4-1.jpg";
//创建Web访问对象 //Rect rect3 = new Rect(0, 0, 0, 0);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
//把用户传过来的数据转成“UTF-8”的字节流
byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(parameterData);
myRequest.Method = "POST"; //CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect3, rect3, false, "D://Hisence//Test1");
//myRequest.Accept = "application/json"; //string path22 = "D:\\Hisence\\Test2\\2.jpg";
//myRequest.ContentType = "application/json"; // //Content-Type: application/x-www-form-urlencoded //Mat pathmat2 = Cv2.ImRead(path22);
myRequest.AutomaticDecompression = DecompressionMethods.GZip; //string path222 = "D:\\Hisence\\Test2\\3.jpg";
myRequest.Accept = Accept; //Rect rect = new Rect(0, 0, 0, 0);
//myRequest.ContentType = ContentType;
myRequest.ContentType = "application/json; charset=UTF-8";
myRequest.ContentLength = buf.Length;
myRequest.MaximumAutomaticRedirections = 1;
myRequest.AllowAutoRedirect = true;
//myRequest.Headers.Add("content-type", "application/json");
//myRequest.Headers.Add("accept-encoding", "gzip");
//myRequest.Headers.Add("accept-charset", "utf-8");
//发送请求 //CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2");
Stream stream = myRequest.GetRequestStream();
stream.Write(buf, 0, buf.Length);
stream.Close();
//通过Web访问对象获取响应内容 // 报警地址
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); //string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
//通过响应内容流创建StreamReader对象因为StreamReader更高级更快
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
//string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
reader.Close(); //DateTime dt = DateTime.Now;
myResponse.Close(); //string today = dt.ToString("yyyy-MM-dd");
return returnData; //string startTime = today;
} //string endTime = today;
#endregion //string lineBody = "BZ-PC";
//string materialDescript = "皂盒";
/// <summary> //JObject patientInfo = new JObject
/// 主窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
//报警地址
//string url = "https://inner-apisix.hisense.com/mes-plus/api/Fcc/GetWorkOrderBOMlnfo?user_key=k7gzo1fsfcami7n5hmpxtybyluf9xeue";
////string url = "https://echo.hoppscotch.io";
//string PostUrl = url;
//DateTime dt= DateTime.Now;
//string starttime=string.Format("{0:yyyy_mm_dd}", dt); //17 17 2017 2017
//string startTime = starttime;
//string EndTime = starttime;
//string lineBody = "ZZ-P";
//string MaterialDescripts = "制冷器";
//string MaterialDescripts2 = "工艺管";
//JObject patientinfo = new JObject();
//JArray ids = new JArray();
//ids.Add(MaterialDescripts);
//ids.Add(MaterialDescripts2);
//patientinfo["startTime"] = startTime;
//patientinfo["EndTime"] = EndTime;
//patientinfo["lineBody"] = lineBody;
//patientinfo["MaterialDescripts"] = ids;
//string sendData = JsonConvert.SerializeObject(patientinfo);
////eg: 发送Url需要的格式sendData={"ids":[123],"Name":小黑}
//string resultData = Post(sendData, PostUrl);
//resultData = "{\r\n\t\"Result\": [],\r\n\t\"success\": false,\r\n\t\"ReturnMsg\": \"参数-starttime 不正确!\"\r\n}";
//JObject jo = (JObject)JsonConvert.DeserializeObject(resultData);
//string sucessIf = jo["success"].ToString();
//if(sucessIf.ToLower()=="true")
//{ //{
// string ProductType = jo["ProductType"].ToString(); // ["StartTime"] = startTime,
// string FinalDefIo = jo["FinalDefIo"].ToString(); // ["EndTime"] = endTime,
// //解析字段 // ["LineBody"] = lineBody,
// ["MaterialDescripts"] = new JArray { materialDescript }
//};
//string sendData = patientInfo.ToString();
//string resultData = Post(sendData, url, "application/x-www-form-urlencoded", "application/json");
//if (resultData != null)
//{
// JObject responseJson = JObject.Parse(resultData);
// bool success = responseJson["success"] != null && (bool)responseJson["success"];
// if (success)
// {
// string productType = responseJson["ProductType"] != null ? responseJson["ProductType"].ToString() : "N/A";
// string finalDefIo = responseJson["FinalDefIo"] != null ? responseJson["FinalDefIo"].ToString() : "N/A";
// // 解析字段
// }
// else
// {
// string returnMsg = responseJson["ReturnMsg"] != null ? responseJson["ReturnMsg"].ToString() : "Unknown error";
// Console.WriteLine("请求失败:" + returnMsg);
// }
//}
//else
//{
// Console.WriteLine("请求失败:未返回数据");
//} //}
if (_runHandleBefore == null) if (_runHandleBefore == null)
{ {
@ -460,7 +492,7 @@ namespace HisenceYoloDetection
OnSpeedShow();//线程开启将速度显示在界面上 OnSpeedShow();//线程开启将速度显示在界面上
OnPostionShow();//线程开启将位置显示在界面上 OnPostionShow();//线程开启将位置显示在界面上
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯 melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
//t = new System.Timers.Timer(10000);//实例化Timer类设置间隔时间为10000毫秒 //t = new System.Timers.Timer(10000);//实例化Timer类设置间隔时间为10000毫秒
//t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件; //t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件;
//t.AutoReset = true;//设置是执行一次false还是一直执行(true) //t.AutoReset = true;//设置是执行一次false还是一直执行(true)
@ -777,7 +809,7 @@ namespace HisenceYoloDetection
Cam1.OnHImageOutput -= OnCameraMatOutPut; Cam1.OnHImageOutput -= OnCameraMatOutPut;
Cam1.OnHImageOutput += OnCameraMatOutPut; Cam1.OnHImageOutput += OnCameraMatOutPut;
//Cam2.OnHImageOutput -= OnCameraMatOutPut2; //Cam2.OnHImageOutput -= OnCameraMatOutPut2;
// Cam2.OnHImageOutput += OnCameraMatOutPut2; // Cam2.OnHImageOutput += OnCameraMatOutPut2;
OKOrNGShow.Image = OKbitmap; OKOrNGShow.Image = OKbitmap;
//初始化扫码枪 //初始化扫码枪
@ -1228,18 +1260,18 @@ namespace HisenceYoloDetection
xKNow = GetModeFromBar("VWJ070541V0WW824F120223");//从数据库中查询到这个条码的四轴的值 xKNow = GetModeFromBar("VWJ070541V0WW824F120223");//从数据库中查询到这个条码的四轴的值
if (xKNow==null) if (xKNow == null)
{ {
myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now); myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now);
break; break;
} }
//if(xKNow.OcrBar!= Old_xKNow.OcrBar) //if(xKNow.OcrBar!= Old_xKNow.OcrBar)
//{ //{
//} //}
if (Regex.IsMatch(xKNow.MoveX.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveY.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveZ.ToString(), @"^[0-9]+$")) if (Regex.IsMatch(xKNow.MoveX.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveY.ToString(), @"^[0-9]+$") && Regex.IsMatch(xKNow.MoveZ.ToString(), @"^[0-9]+$"))
{ {
// Old_xKNow = xKNow; // Old_xKNow = xKNow;
myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now); myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now);
bBarTriger = true; bBarTriger = true;
//MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴 //MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴
@ -1291,7 +1323,7 @@ namespace HisenceYoloDetection
} }
#endregion #endregion
int YPos = 14957; int YPos = 14957;
int ZPos = 4382; int ZPos = 1695;
bool StopM = false;//第一次用信号挡 bool StopM = false;//第一次用信号挡
/// <summary> /// <summary>
/// 监听洗衣机544是否触发后面对射传感器 相机 /// 监听洗衣机544是否触发后面对射传感器 相机
@ -1398,7 +1430,7 @@ namespace HisenceYoloDetection
if (xKNow == null) if (xKNow == null)
{ {
myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now); myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now);
break; // break;
} }
//if(xKNow.OcrBar!= Old_xKNow.OcrBar) //if(xKNow.OcrBar!= Old_xKNow.OcrBar)
//{ //{
@ -1408,21 +1440,21 @@ namespace HisenceYoloDetection
{ {
// Old_xKNow = xKNow; // Old_xKNow = xKNow;
myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now); myLog("型号匹配成功" + xKNow.OcrBar, DateTime.Now);
//MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴 //MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ);// PLC控制电机移动四轴
} }
// break; // break;
} }
Thread.Sleep(2); // Thread.Sleep(2);
bBar = false; bBar = false;
#if true #if true
// if (bBarTriger)//证明读码器读到东西 // if (bBarTriger)//证明读码器读到东西
{ {
myLog("第一次采集图像", DateTime.Now); myLog("第一次采集图像", DateTime.Now);
//移动模组 读三次测距的地址 看是否往前移动 //移动模组 读三次测距的地址 看是否往前移动
@ -1448,7 +1480,7 @@ namespace HisenceYoloDetection
{ {
MoveToP(5815, YPos, ZPos + (int)(dismove)); MoveToP(5815, YPos, ZPos + (int)(dismove));
} }
Cam1.SnapshotCount = 0; Cam1.SnapshotCount = 0;
Cam1.Snapshot(); Cam1.Snapshot();
@ -1460,8 +1492,8 @@ namespace HisenceYoloDetection
//{ //{
// MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ); // MoveToP(xKNow.MoveTwoX, xKNow.MoveTwoY, xKNow.MoveTwoZ);
//} //}
// MoveToP(51043, YPos, ZPos + (int)(dismove)); // MoveToP(51043, YPos, ZPos + (int)(dismove));
//Cam1.Snapshot(); //Cam1.Snapshot();
MoveToP(5815, YPos, ZPos); MoveToP(5815, YPos, ZPos);
melsecPLCTCPDriver.WriteInt("550", 0);//方行 melsecPLCTCPDriver.WriteInt("550", 0);//方行
@ -1609,13 +1641,13 @@ namespace HisenceYoloDetection
//第二次拍照 //第二次拍照
if (SnapshotCount == 2) if (SnapshotCount == 2)
{ {
Cam1ImgTwo = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg"); Cam1ImgTwo = Cv2.ImRead("D:\\Hisence\\类型\\1\\002.jpg");
//Cam1ImgTwo = cameraMat; //Cam1ImgTwo = cameraMat;
IfCam1TwoTriger = true; IfCam1TwoTriger = true;
//originMatShow2.Image = cameraMat.ToBitmap(); //originMatShow2.Image = cameraMat.ToBitmap();
} }
@ -1698,7 +1730,7 @@ namespace HisenceYoloDetection
{ {
xK_HisenceSQLWord = xkWordList[0]; xK_HisenceSQLWord = xkWordList[0];
} }
if(xKNow==null) if (xKNow == null)
{ {
myLog("未匹配条码" + IOcrBAr, DateTime.Now); myLog("未匹配条码" + IOcrBAr, DateTime.Now);
break; break;
@ -1728,7 +1760,7 @@ namespace HisenceYoloDetection
//} //}
myLog("型号匹配成功" + IOcrBAr, DateTime.Now); myLog("型号匹配成功" + IOcrBAr, DateTime.Now);
} }
@ -1739,7 +1771,7 @@ namespace HisenceYoloDetection
} }
//相机1第二次拍照 //相机1第二次拍照
// if (IfCam1TwoTriger && bBarTriger) // if (IfCam1TwoTriger && bBarTriger)
{ {
IfCam1TwoTriger = false; IfCam1TwoTriger = false;
bBarTriger = false;//可能没什么用了 bBarTriger = false;//可能没什么用了
@ -1752,7 +1784,7 @@ namespace HisenceYoloDetection
Defet_OnDetectionDone(whiteMat, 5); Defet_OnDetectionDone(whiteMat, 5);
Defet_OnDetectionDone(whiteMat, 6); Defet_OnDetectionDone(whiteMat, 6);
Defet_OnDetectionDone(whiteMat, 7); Defet_OnDetectionDone(whiteMat, 7);
XK_HisenceWord xK_MatchDet = new XK_HisenceWord(); XK_HisenceWord xK_MatchDet = new XK_HisenceWord();
xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile; xK_MatchDet.TwoIFWhile = xK_HisenceSQLWord.TwoIFWhile;
AllDsums++; AllDsums++;
@ -1774,14 +1806,14 @@ namespace HisenceYoloDetection
List<string> strMatListOne = new List<string>(); List<string> strMatListOne = new List<string>();
List<string> strMatFuzzyListOne = new List<string>(); List<string> strMatFuzzyListOne = new List<string>();
Mat mResultCut = req.currentMat.Clone(); Mat mResultCut = req.currentMat.Clone();
if (mL.ResultMap != null) if (mL.ResultMap != null)
{ {
mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg"); mL.ResultMap.Save("D://cam1//" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString() + "1result.jpg");
ResultMatShow.Image = mL.ResultMap; ResultMatShow.Image = mL.ResultMap;
} }
////进行推理 ////进行推理
//MLRequest req2 = new MLRequest(); //MLRequest req2 = new MLRequest();
//req2.currentMat = Cam1ImgTwo; //req2.currentMat = Cam1ImgTwo;
@ -1801,7 +1833,7 @@ namespace HisenceYoloDetection
List<string> strMatListTwo = new List<string>(); List<string> strMatListTwo = new List<string>();
List<string> strMatFuzzyListTwo = new List<string>(); List<string> strMatFuzzyListTwo = new List<string>();
// Mat mResultCut2 = req2.currentMat.Clone(); // Mat mResultCut2 = req2.currentMat.Clone();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>(); Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>(); Dictionary<string, bool> keyValueResult2 = new Dictionary<string, bool>();
#region #region
@ -1839,18 +1871,18 @@ namespace HisenceYoloDetection
//Mat mCut = new Mat(); //Mat mCut = new Mat();
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
// InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel); InsertSqlRunDataButton(ref keyValueResult, false, ref mResultCut, mL, mLButton, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
// InsertSqlRunData(ref keyValueResult2, false, ref mResultCut2, mL2, ref xK_HisenceSQLWord, ref xK_MatchDet, ref strMatListTwo, ref strMatFuzzyListTwo, ref paddleOcrModel);
sw.Stop(); sw.Stop();
myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now); myLog("插入面板时间" + sw.ElapsedMilliseconds, DateTime.Now);
} }
if (MatchStr) if (MatchStr)
{ {
@ -1867,7 +1899,7 @@ namespace HisenceYoloDetection
// int sqlblocksum= // int sqlblocksum=
melsecPLCTCPDriver.WriteInt("550", 0);//方行 melsecPLCTCPDriver.WriteInt("550", 0);//方行
if (MatchStr) if (MatchStr)
@ -1886,19 +1918,22 @@ namespace HisenceYoloDetection
else else
{ {
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯 melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警 melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
//加上人为判断是否是NG洗衣机 //加上人为判断是否是NG洗衣机
DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); DialogResult dr = MessageBox.Show("是否误检?", "是否误检", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK) if (dr == DialogResult.OK)
{ {
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯 melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警 melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
OKDsums++; OKDsums++;
WUsums++; WUsums++;
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
double percent = (double)WUsums/ AllDsums; double percent = (double)WUsums / AllDsums;
string percentText = percent.ToString("0.0%");//最后percentText的值为10.0% string percentText = percent.ToString("0.0%");//最后percentText的值为10.0%
textBox1.Text = percentText; textBox1.Text = percentText;
OKOrNGShow.Image = OKbitmap; OKOrNGShow.Image = OKbitmap;
@ -1906,11 +1941,12 @@ namespace HisenceYoloDetection
myLog("匹配失败", DateTime.Now); myLog("匹配失败", DateTime.Now);
} }
else else
{ {
NGDsums++; NGDsums++;
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警 melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯 melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
this.Invoke(new Action(() => this.Invoke(new Action(() =>
{ {
OKOrNGShow.Image = NGbitmap; OKOrNGShow.Image = NGbitmap;
@ -1918,7 +1954,7 @@ namespace HisenceYoloDetection
myLog("匹配成功", DateTime.Now); myLog("匹配成功", DateTime.Now);
} }
} }
@ -2005,7 +2041,7 @@ namespace HisenceYoloDetection
// //
if (data.Length > 10) if (data.Length > 10)
{ {
m_sKEYENCEBar=string.Empty; m_sKEYENCEBar = string.Empty;
m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data); m_sKEYENCEBar = System.Text.Encoding.UTF8.GetString(data);
// myLog("型号Ocr" + m_sKEYENCEBar, DateTime.Now); // myLog("型号Ocr" + m_sKEYENCEBar, DateTime.Now);
_runHandleBefore.Set(); _runHandleBefore.Set();
@ -2193,21 +2229,22 @@ namespace HisenceYoloDetection
Mat pathmat2 = Cv2.ImRead(path22); Mat pathmat2 = Cv2.ImRead(path22);
string path222 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628923102_Rect.png"; string path222 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628923102_Rect.png";
Rect rect1 = new Rect(1929, 745, 396, 377); Rect rect1 = new Rect(1929, 745, 396, 377);
Rect rect = new Rect(368, 53, 396, 377);
CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2"); CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2");
string path = "D:\\Hisence\\Test1\\1.png"; string path = "D:\\Hisence\\Test1\\1.png";
Mat pathmat =Cv2.ImRead(path); Mat pathmat =Cv2.ImRead(path);
string path2 = "D:\\Hisence\\Test1\\2.png"; string path2 = "D:\\Hisence\\Test1\\2.png";
Rect rect2 = new Rect(0, 0, 0, 0); Rect rect2 = new Rect(0, 0, 0, 0);
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1"); CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
*/
*/
// OnGetBar(); // OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//黄灯 melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
TriggerCameral2(); TriggerCameral2();
ReadyDetect(); ReadyDetect();
myLog("开启流程成功", DateTime.Now); myLog("开启流程成功", DateTime.Now);
@ -2607,7 +2644,7 @@ namespace HisenceYoloDetection
Mat mResultCut = CamOneI.currentMat.Clone(); Mat mResultCut = CamOneI.currentMat.Clone();
//Mat mCut = new Mat(); //Mat mCut = new Mat();
Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>(); Dictionary<string, bool> keyValueResult = new Dictionary<string, bool>();
InsertSqlRunDataButton(ref keyValueResult, true, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel); InsertSqlRunDataButton(ref keyValueResult, true, ref mResultCut, mL3, mLButton, ref xK_HisenceSQLWord, ref xkWord, ref strMatListOne, ref strMatFuzzyListOne, ref paddleOcrModel);
@ -3041,7 +3078,7 @@ namespace HisenceYoloDetection
break; break;
case 7: case 7:
{ {
// canvas7.ImaMAt = detectionImage; // canvas7.ImaMAt = detectionImage;
} }
break; break;
case 8: case 8:
@ -3071,7 +3108,7 @@ namespace HisenceYoloDetection
/// <param name="strMatList">返回的定位框的结果</param> /// <param name="strMatList">返回的定位框的结果</param>
/// <param name="strMatRefList"></param> /// <param name="strMatRefList"></param>
/// <param name="IOcrModel"></param> /// <param name="IOcrModel"></param>
public void InsertSqlRunDataButton(ref Dictionary<string, bool> keyValueResult, bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel) public void InsertSqlRunDataButton(ref Dictionary<string, bool> keyValueResult, bool saveimage, ref Mat currentMatC, MLResult cam1TwoML, MLResult cam1Button, ref XK_HisenceWord SQlxK_HisenceWord, ref XK_HisenceWord xK_HisenceWord, ref List<string> strMatList, ref List<string> strMatRefList, ref PaddleOcrModel IOcrModel)
{ {
#if true #if true
//try //try
@ -3480,7 +3517,7 @@ namespace HisenceYoloDetection
{ {
SQLStr = SQlxK_HisenceWord.SevenblockMainWord; SQLStr = SQlxK_HisenceWord.SevenblockMainWord;
bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord); bool OneIF1 = ManagerModelHelper.StrMatch2(xK_HisenceWord.SevenblockMainWord, SQlxK_HisenceWord.SevenblockMainWord);
Rect rect = new Rect(0, 0, 0, 0); Rect rect = new Rect(0, 0, 0, 0);
string PathSql = SQlxK_HisenceWord.SevenblockPath; string PathSql = SQlxK_HisenceWord.SevenblockPath;
@ -3603,6 +3640,14 @@ namespace HisenceYoloDetection
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
melsecPLCTCPDriver.WriteInt("550", 0); melsecPLCTCPDriver.WriteInt("550", 0);
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
} }
} }
} }

View File

@ -142,7 +142,7 @@
<value>733, 17</value> <value>733, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>29</value> <value>52</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@ -11,7 +11,7 @@ using static OpenCvSharp.FileStorage;
public class MelsecPLCTCPDriver1 public class MelsecPLCTCPDriver
{ {
private MelsecMcNet melsecMc = new MelsecMcNet(); private MelsecMcNet melsecMc = new MelsecMcNet();
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet(); // private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();

View File

@ -12,7 +12,7 @@ using static OpenCvSharp.FileStorage;
public class MelsecPLCTCPDriver public class MelsecPLCTCPDriver1
{ {
// private MelsecMcNet melsecMc = new MelsecMcNet(); // private MelsecMcNet melsecMc = new MelsecMcNet();
// private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet(); // private HslCommunication.ModBus.ModbusTcpNet melsecMc = new HslCommunication.ModBus.ModbusTcpNet();