diff --git a/HisenceYoloDetection/CheckDiffSciHelper.cs b/HisenceYoloDetection/CheckDiffSciHelper.cs index 4811e43..580fc6a 100644 --- a/HisenceYoloDetection/CheckDiffSciHelper.cs +++ b/HisenceYoloDetection/CheckDiffSciHelper.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; using Point = OpenCvSharp.Point; using Size = OpenCvSharp.Size; @@ -98,14 +99,14 @@ 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)); @@ -145,14 +146,14 @@ 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, 20, 255, ThresholdTypes.Binary); Cv2.Threshold(devIMG_, devIMG_, 20, 255, ThresholdTypes.Binary); @@ -176,24 +177,32 @@ namespace HisenceYoloDetection { Cv2.DrawContours(blackhatImg, new Point[][] { contour }, -1, Scalar.Black, thickness: Cv2.FILLED); // 框选轮廓 - + string savePath2 = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png"); + // 保存结果 + //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); + Cv2.ImWrite(savePath2, img2); + string savePath = Path.Combine("D:\\Hisence\\Test\\2\\ng", Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png"); + // 保存结果 + //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); + Cv2.ImWrite(savePath, blackhatImg); } else { Rect boundingRect = Cv2.BoundingRect(contour); Cv2.Rectangle(img2, boundingRect, Scalar.Red, thickness: 2); isMatch = false; + string savePath2 = Path.Combine("D:\\Hisence\\Test\\2\\ok", Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png"); + // 保存结果 + //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); + Cv2.ImWrite(savePath2, img2); + string savePath = Path.Combine("D:\\Hisence\\Test\\2\\ok", Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png"); + // 保存结果 + //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); + Cv2.ImWrite(savePath, blackhatImg); } } - string savePath2 = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_Rect.png"); - // 保存结果 - //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); - Cv2.ImWrite(savePath2, img2); - string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path1) + filename + "_diff.png"); - // 保存结果 - //string savePath = Path.Combine(saveDir, Path.GetFileNameWithoutExtension(path2) + "_diff.png"); - Cv2.ImWrite(savePath, blackhatImg); + return isMatch; } @@ -315,14 +324,14 @@ 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); // 创建卷积核 @@ -368,14 +377,14 @@ 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); @@ -383,10 +392,10 @@ namespace HisenceYoloDetection // 结合差异 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(); diff --git a/HisenceYoloDetection/MainForm.cs b/HisenceYoloDetection/MainForm.cs index bd6ea61..095cc8f 100644 --- a/HisenceYoloDetection/MainForm.cs +++ b/HisenceYoloDetection/MainForm.cs @@ -277,6 +277,7 @@ namespace HisenceYoloDetection } public void Execute(object source, System.Timers.ElapsedEventArgs e) { + t.Stop(); //ȹرնʱ //melsecPLCTCPDriver.WriteInt("548", 1); //Thread.Sleep(1000); @@ -524,6 +525,7 @@ namespace HisenceYoloDetection // tbFrameRate.Enabled = false; bnGetParam.Enabled = false; bnSetParam.Enabled = false; + } private void button3_Click(object sender, EventArgs e) { @@ -1041,8 +1043,8 @@ namespace HisenceYoloDetection // var resultMap = GetResultImage(resultMask, detectionResultShapes); } #endregion - int YPos = 8715; - int ZPos = 25000; + int YPos = 14957; + int ZPos = 4382; bool StopM = false;//һźŵ /// /// ϴ»544Ƿ񴥷䴫 @@ -1103,7 +1105,7 @@ namespace HisenceYoloDetection myLog("һβɼͼ", DateTime.Now); //ƶģ βĵַ Ƿǰƶ - MoveToP(5815, YPos, ZPos); + MoveToP(7948, YPos, ZPos); // Thread.Sleep(2000);//ɾ @@ -1123,7 +1125,7 @@ namespace HisenceYoloDetection double dismove = disreal - 876; if (dismove > 0 && dismove < 4000) { - MoveToP(5815, YPos, ZPos + (int)(dismove)); + MoveToP(7948, YPos, ZPos + (int)(dismove)); } //Thread.Sleep(2000);//ɾ // Thread.Sleep(500); @@ -1139,9 +1141,9 @@ namespace HisenceYoloDetection //} //currentXP = 54964; //Thread.Sleep(2000);//ɾ - MoveToP(51043, YPos, ZPos + (int)(dismove)); - Cam1.Snapshot(); - MoveToP(5815, YPos, ZPos); + //MoveToP(51043, YPos, ZPos + (int)(dismove)); + //Cam1.Snapshot(); + MoveToP(7948, YPos, ZPos); melsecPLCTCPDriver.WriteInt("550", 0);// //Thread.Sleep(300);//ϴ»ܹȥ @@ -1160,7 +1162,7 @@ namespace HisenceYoloDetection #else myLog("һβɼͼ", DateTime.Now); //ƶģ βĵַ Ƿǰƶ - //MoveToP(5815, YPos, ZPos); + //MoveToP(7948, YPos, ZPos); Thread.Sleep(1000);//ɾ @@ -1180,7 +1182,7 @@ namespace HisenceYoloDetection //double dismove = disreal - 876; //if (dismove > 0 && dismove < 4000) //{ - // MoveToP(5815, YPos, ZPos + (int)(dismove)); + // MoveToP(7948, YPos, ZPos + (int)(dismove)); //} Thread.Sleep(1000);//ɾ // Thread.Sleep(500); @@ -1200,7 +1202,7 @@ namespace HisenceYoloDetection //MoveToP(51043, YPos, ZPos + (int)(dismove)); Cam1.Snapshot(); - //MoveToP(5815, YPos, ZPos); + //MoveToP(7948, YPos, ZPos); //if (xKNow != null) //{ // MoveToP(xKNow.MoveX, xKNow.MoveY, xKNow.MoveZ); @@ -1449,6 +1451,12 @@ namespace HisenceYoloDetection ResultMatShow.Image = mL.ResultMap; } + else + { + Mat res_yolo = Cv2.ImRead("ng.jpg"); + + ResultMatShow.Image = res_yolo.ToBitmap(); + }//޷򶨵ͼƬ˸else޷ // MLRequest req2 = new MLRequest(); req2.currentMat = Cam1ImgTwo; @@ -2811,6 +2819,7 @@ namespace HisenceYoloDetection string blockIndex = cam1TwoML.ResultDetails[i].LabelDisplay; Rect area = new Rect(rectsx, rectsy, rectsWidth, rectsHeight); Mat matCut = new Mat(mResultCuti, area); + Stopwatch sw = new Stopwatch(); sw.Start(); //OCRʶüͼƬ @@ -2892,6 +2901,7 @@ namespace HisenceYoloDetection string TextWoidStr = OcrFuzzyTextInsert.Join("##"); //ʵʵļ string SQLStr = "";//־ʾݿĹؼ bool juanjiMatch = false; + string filenameone = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Millisecond.ToString(); switch (blockIndex) { case "1"://ȫƥ Ϣ @@ -2913,11 +2923,17 @@ namespace HisenceYoloDetection //ʾİ DisplayResult(mLcut); Defet_OnDetectionDone(mLcut.ResultMap.ToMat(), 1); + + string Path_1 = Path.Combine("D:\\Hisence\\Test\\1\\ng", filenameone + "_res.png"); + Cv2.ImWrite(Path_1, mLcut.ResultMap.ToMat()); + } else { OneIF = true; Defet_OnDetectionDone(OKMat, 1); + string Path_2 = Path.Combine("D:\\Hisence\\Test\\1\\ok", filenameone + "_res.png"); + Cv2.ImWrite(Path_2, OKMat); } } diff --git a/HisenceYoloDetection/MainForm.resx b/HisenceYoloDetection/MainForm.resx index 72c614f..62ad5ac 100644 --- a/HisenceYoloDetection/MainForm.resx +++ b/HisenceYoloDetection/MainForm.resx @@ -142,7 +142,7 @@ 733, 17 - 34 + 25