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

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.Height += 60;
Mat matCutblack1 = new Mat(thr1, sqlrect);
if (IfWhiteWord)
{
matCutblack1.SetTo(Scalar.Black);
@ -268,7 +269,7 @@ namespace HisenceYoloDetection
}
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
{
Cv2.Threshold(gimg2, thr2, 100, 255, ThresholdTypes.Binary );//| ThresholdTypes.Otsu
Cv2.Threshold(gimg2, thr2, 0, 255, ThresholdTypes.Binary | ThresholdTypes.Otsu);
}
@ -324,20 +325,21 @@ namespace HisenceYoloDetection
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 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);
//string savePath3 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_thr2.png");
//// 保存结果
Cv2.ImWrite(savePath4, thr1);
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));
filter1.Row(7).SetTo(new Scalar(0.025));
// 应用卷积
@ -377,25 +379,25 @@ namespace HisenceYoloDetection
Mat devIMG_ = new Mat();
Cv2.Subtract(final_result1, final_result2, 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);
//string savePathd1 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "devIMG_.png");
//// 保存结果
Cv2.ImWrite(savePathd, devIMG);
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_, 45, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG, devIMG, 9, 255, ThresholdTypes.Binary);
Cv2.Threshold(devIMG_, devIMG_, 9, 255, ThresholdTypes.Binary);
// 结合差异
Mat sumIMG = new Mat();
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 blackhatImg = new Mat();
@ -407,7 +409,7 @@ namespace HisenceYoloDetection
bool isMatch = true;
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);
// 框选轮廓
@ -434,3 +436,4 @@ namespace HisenceYoloDetection
}
}
}

View File

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

View File

@ -112,10 +112,10 @@ namespace HisenceYoloDetection
string Cam1TwoPath = "";
string ModelChangePath = "";
//报警灯
string GreenLightingAdress = "";
string YellowLightingAdress = "";
string RedLightingAdress = "";
string WaringAdress = "";
string GreenLightingAdress = "556";
string YellowLightingAdress = "554";
string RedLightingAdress = "552";
string WaringAdress = "558";
/// <summary>
/// 查看相机列表
/// </summary>
@ -289,48 +289,56 @@ namespace HisenceYoloDetection
/// <param name="ContentType">默认 application/json , application/x-www-form-urlencoded,multipart/form-data,raw,binary </param>
/// <param name="Accept">默认application/json</param>
/// <returns></returns>
public string Post(string parameterData, string serviceUrl, string ContentType = "application/json", string Accept = "application/json")
{
//先根据用户请求的uri构造请求地址
//string serviceUrl = string.Format("{0}/{1}", this.BaseUri, uri);
//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)}");
//创建Web访问对象
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
//把用户传过来的数据转成“UTF-8”的字节流
byte[] buf = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(parameterData);
// myRequest.Method = "POST";
// myRequest.Accept = accept;
// myRequest.ContentType = contentType;
// myRequest.ContentLength = buf.Length;
myRequest.Method = "POST";
//myRequest.Accept = "application/json";
//myRequest.ContentType = "application/json"; // //Content-Type: application/x-www-form-urlencoded
myRequest.AutomaticDecompression = DecompressionMethods.GZip;
myRequest.Accept = Accept;
//myRequest.ContentType = ContentType;
myRequest.ContentType = "application/json; charset=UTF-8";
myRequest.ContentLength = buf.Length;
myRequest.MaximumAutomaticRedirections = 1;
myRequest.AllowAutoRedirect = true;
// // 发送请求
// using (Stream stream = myRequest.GetRequestStream())
// {
// stream.Write(buf, 0, buf.Length);
// }
//myRequest.Headers.Add("content-type", "application/json");
//myRequest.Headers.Add("accept-encoding", "gzip");
//myRequest.Headers.Add("accept-charset", "utf-8");
// // 获取响应内容
// 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;
// }
//}
//发送请求
Stream stream = myRequest.GetRequestStream();
stream.Write(buf, 0, buf.Length);
stream.Close();
//通过Web访问对象获取响应内容
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//通过响应内容流创建StreamReader对象因为StreamReader更高级更快
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
//string returnXml = HttpUtility.UrlDecode(reader.ReadToEnd());//如果有编码问题就用这个方法
string returnData = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
reader.Close();
myResponse.Close();
return returnData;
}
#endregion
/// <summary>
@ -340,39 +348,63 @@ namespace HisenceYoloDetection
/// <param name="e"></param>
private void MainForm_Load(object sender, EventArgs e)
{
//string path3 = "D:\\Hisence\\Test1\\3.jpg";
//Mat pathmat = Cv2.ImRead(path3);
//string path2 = "D:\\Hisence\\Test1\\4-1.jpg";
//Rect rect3 = new Rect(0, 0, 0, 0);
//CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect3, rect3, false, "D://Hisence//Test1");
//string path22 = "D:\\Hisence\\Test2\\2.jpg";
//Mat pathmat2 = Cv2.ImRead(path22);
//string path222 = "D:\\Hisence\\Test2\\3.jpg";
//Rect rect = new Rect(0, 0, 0, 0);
//CheckDiffSciHelper.CheckDiffSci(path222, pathmat2, rect, rect, true, "D://Hisence//Test2");
// 报警地址
//string url = "https://inner-apisix.hisense.com/mes-plus/api/Fcc/GetWorkOrderBOMlnfo?user_key=k7gzo1fsfcami7n5hmpxtybyluf9xeue";
////string url = "https://echo.hoppscotch.io";
//string PostUrl = url;
//string url = "http://172.16.139.146/FCCBOMWebService/FCCBomService.asmx/GetFCCBomInfoPDJson";
//DateTime dt = DateTime.Now;
//string today = dt.ToString("yyyy-MM-dd");
//string starttime=string.Format("{0:yyyy_mm_dd}", dt); //17 17 2017 2017
//string startTime = today;
//string endTime = today;
//string lineBody = "BZ-PC";
//string materialDescript = "皂盒";
//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")
//JObject patientInfo = new JObject
//{
// string ProductType = jo["ProductType"].ToString();
// string FinalDefIo = jo["FinalDefIo"].ToString();
// ["StartTime"] = startTime,
// ["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)
{
_runHandleBefore = new AutoResetEvent(false);
@ -460,7 +492,7 @@ namespace HisenceYoloDetection
OnSpeedShow();//线程开启将速度显示在界面上
OnPostionShow();//线程开启将位置显示在界面上
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
//t = new System.Timers.Timer(10000);//实例化Timer类设置间隔时间为10000毫秒
//t.Elapsed += new System.Timers.ElapsedEventHandler(Execute);//到达时间的时候执行事件;
//t.AutoReset = true;//设置是执行一次false还是一直执行(true)
@ -1291,7 +1323,7 @@ namespace HisenceYoloDetection
}
#endregion
int YPos = 14957;
int ZPos = 4382;
int ZPos = 1695;
bool StopM = false;//第一次用信号挡
/// <summary>
/// 监听洗衣机544是否触发后面对射传感器 相机
@ -1398,7 +1430,7 @@ namespace HisenceYoloDetection
if (xKNow == null)
{
myLog("数据库没有条码匹配" + m_sKEYENCEBar, DateTime.Now);
break;
// break;
}
//if(xKNow.OcrBar!= Old_xKNow.OcrBar)
//{
@ -1414,7 +1446,7 @@ namespace HisenceYoloDetection
// break;
}
Thread.Sleep(2);
// Thread.Sleep(2);
bBar = false;
#if true
@ -1886,6 +1918,8 @@ namespace HisenceYoloDetection
else
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 1);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 0);//绿灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 1);//报警
//加上人为判断是否是NG洗衣机
@ -1893,6 +1927,7 @@ namespace HisenceYoloDetection
if (dr == DialogResult.OK)
{
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
OKDsums++;
WUsums++;
@ -1910,6 +1945,7 @@ namespace HisenceYoloDetection
NGDsums++;
melsecPLCTCPDriver.WriteInt(WaringAdress, 0);//报警
melsecPLCTCPDriver.WriteInt(RedLightingAdress, 0);//红灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 1);//黄灯
this.Invoke(new Action(() =>
{
@ -2193,7 +2229,7 @@ namespace HisenceYoloDetection
Mat pathmat2 = Cv2.ImRead(path22);
string path222 = "D:\\Hisence\\Test2\\BatchW96c0ModelWNHB6X2SDSPresult2024628923102_Rect.png";
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");
@ -2204,10 +2240,11 @@ namespace HisenceYoloDetection
Rect rect2 = new Rect(0, 0, 0, 0);
CheckDiffSciHelper1.CheckDiffSci(path2, pathmat, rect2, rect2, false, "D://Hisence//Test1");
*/
// OnGetBar();
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//黄灯
melsecPLCTCPDriver.WriteInt(GreenLightingAdress, 1);//绿灯
melsecPLCTCPDriver.WriteInt(YellowLightingAdress, 0);//黄灯
TriggerCameral2();
ReadyDetect();
myLog("开启流程成功", DateTime.Now);
@ -3603,6 +3640,14 @@ namespace HisenceYoloDetection
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
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>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>29</value>
<value>52</value>
</metadata>
<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">

View File

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