public override bool doLocal() { NowResult = new LineCircRectRlt(); BlobLocalRlt myBlobLocalRlt = new BlobLocalRlt(); try { myBlobLocal.Set(NowImg, NowVisionPara); myBlobLocal.doLocal(); myBlobLocalRlt = (BlobLocalRlt)myBlobLocal.GetResult(); HTuple HomMat = new HTuple(); // //计算当前图片到示教图片的偏移矩阵 HOperatorSet.VectorAngleToRigid(myBlobLocalRlt.row, myBlobLocalRlt.col, myBlobLocalRlt.angle, myBlobLocalRlt.TeachRow, myBlobLocalRlt.TeachCol, myBlobLocalRlt.TeachAngle, out HomMat); HObject AffineImg = new HObject(); //矫正图像位置 HOperatorSet.AffineTransImage(NowImg, out AffineImg, HomMat, "constant", "false"); //开始检测 ((LineCircRectRlt)NowResult).IsOk = LineCircleRectInspBase.LineCircleRectInsp(AffineImg, NowVisionPara.LineCirRectInspParam, out ((LineCircRectRlt)NowResult).DetectContour, out ((LineCircRectRlt)NowResult).NgContour); // HOperatorSet.CopyObj(myBlobLocalRlt.ShowContour, out ((LineCircRectRlt)NowResult).ShowContour, 1, -1); //位置的逆变换 HOperatorSet.VectorAngleToRigid(myBlobLocalRlt.TeachRow, myBlobLocalRlt.TeachCol, myBlobLocalRlt.TeachAngle, myBlobLocalRlt.row, myBlobLocalRlt.col, myBlobLocalRlt.angle, out HomMat); NowResult.AffineTransResult(HomMat, out NowResult); return(true); } catch { return(false); } }
public override bool doLocal() { try { BlobLocalRlt NowResult0 = new BlobLocalRlt(); St_BlobLocalParam Blobs = NowVisionPara.Blobs; HObject RoiCont = new HObject(); HObject MinRectCont = new HObject(); HObject RegionCont = new HObject(); HOperatorSet.GenEmptyObj(out RoiCont); HOperatorSet.GenEmptyObj(out MinRectCont); HOperatorSet.GenEmptyObj(out RegionCont); BlobLocal1(NowImg, Blobs, out ListRow, out ListCol, out ListWid, out ListHei, out ListArea, out RoiCont, out MinRectCont, out RegionCont); HOperatorSet.ConcatObj(RoiCont, MinRectCont, out RoiCont); HOperatorSet.ConcatObj(RoiCont, RegionCont, out RoiCont); HOperatorSet.CopyObj(RoiCont, out NowResult0.ShowContour, 1, -1); if (RoiCont != null) { RoiCont.Dispose(); } if (RegionCont != null) { RegionCont.Dispose(); } if (MinRectCont != null) { MinRectCont.Dispose(); } NowResult0.row = ListRow[0]; NowResult0.col = ListCol[0]; NowResult0.angle = 0; NowResult0.ListRow = ListRow; NowResult0.ListCol = ListCol; NowResult0.ListWid = ListWid; NowResult0.ListHei = ListHei; NowResult0.ListArea = ListArea; NowResult = NowResult0; return(true); } catch { return(false); } }
private void TryDebugBtn_Click(object sender, EventArgs e) { txtFindTime.Clear(); Stopwatch sw = new Stopwatch(); sw.Start(); TeachLoclPara.Blobs = TeachBlobLocaltPara; LocalManager LocalCtrl = new LocalManager(); LocalCtrl.SetLocalModel(TeachLoclPara.localSetting.localModel); LocalCtrl.SetParam(GrabedImg, TeachLoclPara); LocalCtrl.doLocal(); sw.Stop(); LocalResult MyRlt = new LocalResult(); MyRlt = LocalCtrl.GetResult(); BlobLocalRlt BlobRlt = (BlobLocalRlt)MyRlt; if (GrabedImg != null && GrabedImg.IsInitialized()) { view1.ResetView(); view1.AddViewImage(GrabedImg); view1.SetDraw("blue"); view1.AddViewObject(MyRlt.ShowContour); view1.Repaint(); } if (BlobRlt.ListWid != null && BlobRlt.ListWid.Count > 0) { double X = BlobRlt.ListCol[0] * TeachLoclPara.Blobs.PixelSize; double H = BlobRlt.ListRow[0] * TeachLoclPara.Blobs.PixelSize; view1.SetString(100, 150, "red", "坐标X(mm):" + X.ToString() + " Y(mm):" + H.ToString()); if (BlobRlt.ListWid.Count > 1) { X = BlobRlt.ListWid[1] * TeachLoclPara.Blobs.PixelSize; H = BlobRlt.ListHei[1] * TeachLoclPara.Blobs.PixelSize; view1.SetString(100, 750, "blue", "高度(mm):" + H.ToString()); } } txtFindTime.Text = sw.ElapsedMilliseconds.ToString(); }
public void DoFOFProject1(LD.Config.PlcDataItem PlcItem, Object Obj) { LD.Common.PlcDevice plcDevice = PlcItem.PlcDevice; if (plcDevice == LD.Common.PlcDevice.V_02_TriggerGrab) { FileLib.Logger.Pop("接受到PLC信号,偏移检测", false, "FOF运行日志"); NowUpVisionProcess = new DoUpDnVisionProcess(); NowUpLocalRlt = new LocalResult(); NowDnLocalRlt = new LocalResult(); //起始信号清零 FileLib.Logger.Pop("启动信号清零", false, "FOF运行日志"); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_02_TriggerGrab, 0); System.Threading.Thread.Sleep(1); short ClearValue = 1; object obj = new object(); FileLib.Logger.Pop("启动地址清零成功", false, "FOF运行日志"); //读取机台编号 4 代表FOF左侧FOF偏移检测 ,5代表FOF右侧偏移检测 int StageNum = (int)LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.ArtTestStageNumRead); FileLib.Logger.Pop(" 读取机台编号:" + StageNum.ToString(), false, "FOF运行日志"); System.Threading.Thread.Sleep(1); //获取视觉示教的定位参数 NowProjectPara = ProjectParaManager.Instance.GetProjectPara(StageNum); //获取当前拍照点的视觉坐标 double OffsetX = 0; double OffsetY = 0; try { FileLib.Logger.Pop("开始FOF偏移检测上相机定位", false, "FOF运行日志"); NowVisionPara = NowProjectPara.GetVisionPara(0); NowUpVisionProcess.SetVisionPara(NowVisionPara); NowUpVisionProcess.Do(); NowUpLocalRlt = NowUpVisionProcess.MyLocalResult; BlobLocalRlt FofRlt = (BlobLocalRlt)NowUpLocalRlt; double x = FofRlt.ListWid[0] * NowVisionPara.localPara.Blobs.PixelSize; double y = FofRlt.ListHei[1] * NowVisionPara.localPara.Blobs.PixelSize; OffsetX = x + NowVisionPara.localPara.localSetting.Offset_x; OffsetY = y + NowVisionPara.localPara.localSetting.Offset_y; FileLib.Logger.Pop("偏移量: " + "OffsetX: " + OffsetX.ToString("f4") + " " + "OffsetY: " + OffsetY.ToString("f4"), false, "FOF运行日志"); } catch (Exception e0) { Logger.PopError1(e0, false, "视觉错误日志"); OffsetX = 999999; OffsetY = 999999; } ViewControl view1 = DisplaySystem.GetViewControl(CameraTest.UpCam2); view1.SetString(500, 500, "red", "OffsetX: " + OffsetX.ToString("f4") + " mm"); view1.SetString(500, 600, "red", "OffsetY: " + OffsetY.ToString("f4") + " mm"); if (Math.Abs(OffsetX) < NowVisionPara.localPara.localSetting.Offset_x_range && Math.Abs(OffsetY) < NowVisionPara.localPara.localSetting.Offset_y_range) { LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_inspect_result, 1); //检测结果Ok FileLib.Logger.Pop("检测结果写给Plc(FOF_inspect_result):OK", false, "FOF运行日志"); } else { LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_inspect_result, 2); //检测结果NG FileLib.Logger.Pop("检测结果写给Plc(FOF_inspect_result):NG", false, "FOF运行日志"); } FileLib.Logger.Pop("循环读取启动地址,保证清零成功", false, "FOF运行日志"); int ReadCount = 1; while (true) { obj = LD.Logic.PlcHandle.Instance.ReadValue(LD.Common.PlcDevice.V_02_TriggerGrab); ClearValue = (short)obj; if (ClearValue == 0) { break; } else { System.Threading.Thread.Sleep(10); if (ReadCount % 10 == 0) { FileLib.Logger.Pop("重新执行一次清零", false, "FOF运行日志"); ReadCount = 1; LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.V_02_TriggerGrab, 0); } if (ReadCount > 100) { FileLib.Logger.Pop("清零次数超过10,清零失败", false, "FOF运行日志"); } } ReadCount++; } FileLib.Logger.Pop("将偏移量写给PLC", false, "FOF运行日志"); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_offset_x, (int)(OffsetX * 1000)); LD.Logic.PlcHandle.Instance.WriteValue(LD.Common.PlcDevice.FOF_offset_y, (int)(OffsetY * 1000)); FileLib.Logger.Pop("偏移量写给PLC完成", false, "FOF运行日志"); FileLib.Logger.Pop("。", false, "FOF运行日志"); FileLib.Logger.Pop("。", false, "FOF运行日志"); FileLib.Logger.Pop("。", false, "FOF运行日志"); } }