/// <summary> /// 更新图片上的板子区域和区域树的添加 /// </summary> /// <param name="xboard"></param> /// <param name="dBackRectangle">背面板子的区域</param> /// <param name="dFrontRectangle">正面板子的区域</param> private void drawAndTree(XBoard xboard, double markerScore, DRectangle dBackRectangle, DRectangle dFrontRectangle) { if (xboard.isBack) { MCvScalar mCvScalar; //只有匹配结果分值较高时才新增 if (markerScore >= threshold) // 得分大于阈值就是坏板 { mCvScalar = new MCvScalar(0, 0, 255); // 使用红色 bgr //并且需要画X CvInvoke.Line(backBoard.matImg, dBackRectangle.Location, new DPoint(dBackRectangle.X + dBackRectangle.Width, dBackRectangle.Y + dBackRectangle.Height), mCvScalar, 20); CvInvoke.Line(backBoard.matImg, new DPoint(dBackRectangle.X + dBackRectangle.Width, dBackRectangle.Y), new DPoint(dBackRectangle.X, dBackRectangle.Y + dBackRectangle.Height), mCvScalar, 20); xboard.badTree.Add(new RRectangle(dBackRectangle.X, dBackRectangle.Y, dBackRectangle.X + dBackRectangle.Width, dBackRectangle.Y + dBackRectangle.Height, 0, 0), dBackRectangle); } else { mCvScalar = new MCvScalar(0, 255, 0); // 使用绿色 bgr xboard.okTree.Add(new RRectangle(dBackRectangle.X, dBackRectangle.Y, dBackRectangle.X + dBackRectangle.Width, dBackRectangle.Y + dBackRectangle.Height, 0, 0), dBackRectangle); } CvInvoke.Rectangle(backBoard.matImg, dBackRectangle, mCvScalar, 20); } else { MCvScalar mCvScalar; //只有匹配结果分值较高时才新增 if (markerScore >= threshold) // 得分大于阈值就是坏板 { mCvScalar = new MCvScalar(0, 0, 255); // 使用红色 bgr CvInvoke.Line(frontBoard.matImg, dFrontRectangle.Location, new DPoint(dFrontRectangle.X + dFrontRectangle.Width, dFrontRectangle.Y + dFrontRectangle.Height), mCvScalar, 20); CvInvoke.Line(frontBoard.matImg, new DPoint(dFrontRectangle.X + dFrontRectangle.Width, dFrontRectangle.Y), new DPoint(dFrontRectangle.X, dFrontRectangle.Y + dFrontRectangle.Height), mCvScalar, 20); xboard.badTree.Add(new RRectangle(dFrontRectangle.X, dFrontRectangle.Y, dFrontRectangle.X + dFrontRectangle.Width, dFrontRectangle.Y + dFrontRectangle.Height, 0, 0), dFrontRectangle); } else { mCvScalar = new MCvScalar(0, 255, 0); // 使用绿色 bgr xboard.okTree.Add(new RRectangle(dFrontRectangle.X, dFrontRectangle.Y, dFrontRectangle.X + dFrontRectangle.Width, dFrontRectangle.Y + dFrontRectangle.Height, 0, 0), dFrontRectangle); } CvInvoke.Rectangle(frontBoard.matImg, dFrontRectangle, mCvScalar, 20); } }
/// <summary> /// 执行打X板子 /// </summary> /// <param name="frontImg"></param> /// <param name="backImg"></param> /// <param name="pcb"></param> public void xxxx(Pcb pcb) { checkedNum = 0; needCheckNumAll = 0; xboardDoneNum = 0; nowWorkingPcb = pcb; frontBoard = null; backBoard = null; string frontImgPath = ConfigurationManager.AppSettings["FtpPath"] + pcb.Id + "/front.jpg"; string backImgPath = ConfigurationManager.AppSettings["FtpPath"] + pcb.Id + "/back.jpg"; if (File.Exists(frontImgPath)) { frontBoard = new XBoard(frontImgPath, false); } if (File.Exists(backImgPath)) { backBoard = new XBoard(backImgPath, false); backBoard.isBack = true; } for (int i = 0; i <= 7; i++) { if (frontBoard != null) { MySmartThreadPool.Instance().QueueWorkItem((act, n) => { lock (frontBoard) { try { DPoint point = new DPoint(); double dres = Aoi.marker_match_crop(frontBoard.matImg.Ptr, marker.Ptr, ref point, ref act); this.BeginInvoke((Action <int, double, XBoard>)((bn, bdress, board) => { xBoardAddTree(bn, bdress, board); }), n, dres, frontBoard); //if (dres > threshold) //{ // //CvInvoke.PutText(frontMatImg, dres + "", new DPoint(point.X + act.X, point.Y + act.Y), FontFace.HersheyComplex, 3, new MCvScalar(0, 0, 255)); //} //CvInvoke.PutText(frontMatImg, dres + "", new DPoint(point.X + act.X, point.Y + act.Y), FontFace.HersheyComplex, 3, new MCvScalar(0, 0, 255)); //CvInvoke.Rectangle(frontMatImg, new DRectangle(new DPoint(point.X + act.X, point.Y + act.Y), new Size(75, 75)), new MCvScalar(0, 0, 255), 20); //frontMatImg.Save(@"C:\res\f" + point.X + ".jpg"); //Console.WriteLine(dres); //Console.WriteLine("正面:" + dres); } catch (Exception er) { LogHelper.WriteLog("front marker error", er); } } }, frontMarkerCheckArea[i], i); } if (backBoard != null) { MySmartThreadPool.Instance().QueueWorkItem((act, n) => { lock (backBoard) { try { DPoint point = new DPoint(); double dres = Aoi.marker_match_crop(backBoard.matImg.Ptr, marker.Ptr, ref point, ref act); this.BeginInvoke((Action <int, double, XBoard>)((bn, bdress, board) => { xBoardAddTree(bn, bdress, board); }), n, dres, backBoard); //if (dres > threshold) //{ //} //CvInvoke.PutText(backMatImg, dres + "", new DPoint(point.X + act.X, point.Y + act.Y), FontFace.HersheyComplex, 3, new MCvScalar(0, 0, 255)); //CvInvoke.Rectangle(backMatImg, new DRectangle(new DPoint(point.X + act.X, point.Y + act.Y), new Size(75, 75)), new MCvScalar(255, 0, 0), 3); //backMatImg.Save(@"C:\res\b" + point.X + ".jpg"); //Console.WriteLine(dres); //Console.WriteLine("反面:" + dres); } catch (Exception er) { LogHelper.WriteLog("back marker error", er); } } }, backMarkerCheckArea[i], i); } //DPoint point = new DPoint(); //double dres = Aoi.marker_match(img.Ptr, marker.Ptr, ref point); //CvInvoke.Rectangle(img, new DRectangle(point, new Size(200, 200)), new MCvScalar(0, 0, 255), 20); //img.Save(@"E:\索米测试图片\result\" + i + ".jpg"); //Console.WriteLine(res); } }
/// <summary> /// 增加坏板的区域, 里面存储的都是坏板的直接区域 /// </summary> /// <param name="i"></param> /// <param name="xboard"></param> private void xBoardAddTree(int i, double dres, XBoard xboard) { if (xboard.isBack) { Console.WriteLine("反面:" + i + " " + dres); } else { Console.WriteLine("正面:" + i + " " + dres); } switch (i) { case 0: drawAndTree(xboard, dres, new DRectangle(new DPoint(597, 300), new Size(717, 1365)), new DRectangle(new DPoint(376, 271), new Size(679, 1361))); break; case 1: drawAndTree(xboard, dres, new DRectangle(new DPoint(1442, 313), new Size(685, 1350)), new DRectangle(new DPoint(1192, 277), new Size(702, 1367))); break; case 2: drawAndTree(xboard, dres, new DRectangle(new DPoint(2265, 306), new Size(688, 1359)), new DRectangle(new DPoint(2013, 271), new Size(700, 1385))); break; case 3: drawAndTree(xboard, dres, new DRectangle(new DPoint(3083, 316), new Size(713, 1362)), new DRectangle(new DPoint(2856, 295), new Size(679, 1355))); break; case 4: drawAndTree(xboard, dres, new DRectangle(new DPoint(3909, 322), new Size(701, 1357)), new DRectangle(new DPoint(3672, 295), new Size(679, 1334))); break; case 5: drawAndTree(xboard, dres, new DRectangle(new DPoint(4740, 327), new Size(698, 1368)), new DRectangle(new DPoint(4506, 295), new Size(673, 1346))); break; case 6: drawAndTree(xboard, dres, new DRectangle(new DPoint(5563, 333), new Size(694, 1353)), new DRectangle(new DPoint(5322, 295), new Size(681, 1367))); break; case 7: drawAndTree(xboard, dres, new DRectangle(new DPoint(6385, 339), new Size(669, 1358)), new DRectangle(new DPoint(6143, 316), new Size(697, 1349))); break; } #region 老的板区域 //switch (i) //{ // case 0: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(724, 594), new Size(1453, 2664)), // new DRectangle(new DPoint(1096, 592), new Size(1381, 2661))); // break; // case 1: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(2389, 585), new Size(1435, 2706)), // new DRectangle(new DPoint(2734, 607), new Size(1354, 2691))); // break; // case 2: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(4084, 600), new Size(1402, 2691)), // new DRectangle(new DPoint(4387, 643), new Size(1369, 2682))); // break; // case 3: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(5737, 600), new Size(1399, 2654)), // new DRectangle(new DPoint(6022, 703), new Size(1333, 2651))); // break; // case 4: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(7364, 568), new Size(1411, 2660)), // new DRectangle(new DPoint(7668, 718), new Size(1363, 2624))); // break; // case 5: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(9042, 598), new Size(1359, 2618)), // new DRectangle(new DPoint(9324, 706), new Size(1363, 2666))); // break; // case 6: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(10681, 576), new Size(1414, 2675)), // new DRectangle(new DPoint(10995, 775), new Size(1366, 2633))); // break; // case 7: // drawAndTree(xboard, dres, // new DRectangle(new DPoint(12358, 570), new Size(1348, 2660)), // new DRectangle(new DPoint(12630, 748), new Size(1372, 2678))); // break; //} #endregion xboardDoneNum++; //到这里结束了!!!!大于等于16,说明正反面都执行完了 //所以要执行loadData if (frontBoard != null && backBoard != null) { if (xboardDoneNum >= 16) { loadData(nowWorkingPcb); } } else if (frontBoard != null || backBoard != null) { if (xboardDoneNum >= 8) { loadData(nowWorkingPcb); } } }