public override void DisplayDetail(HWindow_Final window)//显示详细信息 { base.DisplayDetail(window); HObject ho_Rectangle = Func_HalconFunction.GenRectangle1(Func_Mathematics.ToRectangle1(ROI)); window.DispObj(ho_Rectangle, color, "margin"); }
private void btn_slg_ReDrowROI_Click(object sender, EventArgs e) { DrawMode(true); //绘制模式开启 getRegionUseThreshold.parameter.rectangle2 = Func_HalconFunction.DrawRectangle2Mod(hWindow_Final1.hWindowControl.HalconWindow, getRegionUseThreshold.parameter.rectangle2); DrawMode(false); //绘制模式关闭 RunOnce(); //运行测试 }
public override int Measure(HObject ho_Image) //测量 { base.Measure(ho_Image); //调用基类的测量方法 measureResult = Result.OK; color = "green"; ROI = parameter.rectangle2.GetShapePositioned() as Rectangle2; //获取ROI矩形 HObject ho_ROI = Func_HalconFunction.GenRectangle2(ROI); //创建ROI矩形形状 ho_Shape = Func_ImageProcessing.Threshold_SelectMaxRegion(ho_Image, ho_ROI, parameter.hv_MinGray, parameter.hv_MaxGray); //创建结果形状 HOperatorSet.AreaCenter(ho_Shape, out hv_Area, out centerPoint.hv_Row, out centerPoint.hv_Column); //求取区域面积 ho_ROI.Dispose(); if (minValue > hv_Area || hv_Area > maxValue) //?面积在设定范围内 { measureResult = Result.NG; if (Exist)//?无料 { measureResult = Result.无料; function = "产品有无"; } color = "red"; } MeasureDone = true;//已测量标志为true return(Convert.ToInt32(measureResult)); }
public override void DisplayDetail(HWindow_Final window)//显示详细信息 { try { ho_Shape.Dispose(); } catch (Exception) { } ho_Shape = Func_HalconFunction.GenRegionLine(GetShapePositioned() as Line); window.DispObj(ho_Shape, shapeColor); //显示形状 window.DispString(DP.hv_Column, DP.hv_Row, name, "orange"); //显示文字 }
public override int Measure(HObject ho_Image) //测量 { measureResult = Result.OK; //测量结果初始OK try { ho_ROI.Dispose(); } catch (Exception) { }//释放ho_ROI资源 Rectangle2 ROI = parameter.rectangle2.GetShapePositioned() as Rectangle2; //获取ROI矩形 ho_ROI = Func_HalconFunction.GenRectangle2(ROI); //创建ROI //灰度处理,并选出最大面积 try { ho_SelectedRegions.Dispose(); } catch (Exception) { }//释放ho_SelectedRegions资源 ho_SelectedRegions = Func_ImageProcessing.Threshold_SelectMaxRegion(ho_Image, ho_ROI, parameter.hv_MinGray, parameter.hv_MaxGray); if (ROI.hv_Phi.D != 0)//角度不为零? { //hv_HomMat2D;//变换矩阵 HOperatorSet.VectorAngleToRigid(ROI.hv_Row, ROI.hv_Column, 0, ROI.hv_Row, ROI.hv_Column, -ROI.hv_Phi, out HTuple hv_HomMat2D); //将区域旋转为水平的变换矩阵 // ho_RegionRotate;//水平后的Region HOperatorSet.AffineTransRegion(ho_SelectedRegions, out HObject ho_RegionRotate, hv_HomMat2D, "nearest_neighbor"); //应用变换 SetLine(Func_ImageProcessing.getLine_FromRegion(ho_RegionRotate, TPLR, b, AngularPoint)); //从区域获取线 HOperatorSet.VectorAngleToRigid(ROI.hv_Row, ROI.hv_Column, 0, ROI.hv_Row, ROI.hv_Column, ROI.hv_Phi, out hv_HomMat2D); //将线从水平变回原角度的变换矩阵 HOperatorSet.AffineTransPixel(hv_HomMat2D, hv_Row1, hv_Column1, out hv_Row1, out hv_Column1); //应用变换 HOperatorSet.AffineTransPixel(hv_HomMat2D, hv_Row2, hv_Column2, out hv_Row2, out hv_Column2); //应用变换 } else { SetLine(Func_ImageProcessing.getLine_FromRegion(ho_SelectedRegions, TPLR, b, AngularPoint));//从区域获取线 } if (DP == null) { DP = new Point(0, 0); } DP.hv_Column = (hv_Column1); DP.hv_Row = (hv_Row1); AxByC0 = AxByC0.GetAxByC(this); //求该线的一半直线方程 MeasureDone = true; //已测量标志为true return(Convert.ToInt32(measureResult)); }
public override void DisplayDetail(HWindow_Final window)//显示详细信息 { HObject ho_Rectangle = Func_HalconFunction.GenRectangle2(parameter.rectangle2.GetShapePositioned() as Rectangle2); window.DispObj(ho_Rectangle, "blue", "margin"); ho_Rectangle.Dispose(); base.DisplayDetail(window); }
public override void DisplayDetail(HWindow_Final window)//显示详细信息 { window.DispObj(ho_ROI, "blue", "margin"); window.DispObj(ho_SelectedRegions, "green", "fill"); HObject ho_Line = Func_HalconFunction.GenRegionLine(this); window.DispObj(ho_Line, "red", "fill"); ho_Line.Dispose(); window.DispString(DP.hv_Column, DP.hv_Row, name, "orange");//显示文字 }
private void tsmi_Next_Click(object sender, EventArgs e) { DrawMode(true); //绘制模式开启 Rectangle2 rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 HObject ho_Rectangle = Func_HalconFunction.GenRectangle2(rectangle2); //创建矩形 hWindow_Final1.DispObj(ho_Rectangle, "blue"); //显示矩形 getCircleUseThreshold.AddRegion(new GetRegionUseThreshold(new Threshold(rectangle2))); //添加该项 }
private void btn_SelectROI_Click(object sender, EventArgs e) { DrawMode(true); //绘制模式开启 Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 (transformation.line as GetLineUseThreshold).parameter.rectangle2 = Func_Mathematics.ToRectangle2(rectangle1); //ROI矩形赋值 prepared = true; RunOnce(); }
private void btn_SelectROI_Click(object sender, EventArgs e) { DrawMode(true); Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); getRegionUseThreshold.parameter.rectangle2 = Func_Mathematics.ToRectangle2(rectangle1); DrawMode(false); prepared = true; RunOnce(); }
private void tsmi_Next_Click(object sender, EventArgs e) { DrawMode(true); //绘制模式开启 Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 HObject ho_Rectangle = Func_HalconFunction.GenRectangle1(rectangle1); //创建矩形 hWindow_Final1.DispObj(ho_Rectangle, "blue"); //显示矩形 GetLineUseThreshold line = new GetLineUseThreshold(new Threshold(Func_Mathematics.ToRectangle2(rectangle1))); getSetOfLines.AddLine(line); }
private void btn_Draw_Click(object sender, EventArgs e) { DrawMode(true); //绘制模式开启 line.SetLine(Func_HalconFunction.DrawLine(hWindow_Final1.hWindowControl.HalconWindow)); //画线 DrawMode(false); //绘制模式关闭 nud_xStart.Value = (decimal)line.hv_Column1.D; //赋值 nud_yStart.Value = (decimal)line.hv_Row1.D; //赋值 nud_xEnd.Value = (decimal)line.hv_Column2.D; //赋值 nud_yEnd.Value = (decimal)line.hv_Row2.D; //赋值 prepared = true; RunOnce(); }
private void button1_Click(object sender, EventArgs e) { if (getCircleUseMetrology == null) { getCircleUseMetrology = new GetCircleUseMetrology(); data = getCircleUseMetrology; circle = null; } hWindow_Final1.HobjectToHimage(ho_Image); //刷新图片 DrawMode(true); //绘制模式开启 getCircleUseMetrology.parameter.Circle = Func_HalconFunction.DrawCircle(hWindow_Final1.hWindowControl.HalconWindow); DrawMode(false); //绘制模式关闭 prepared = true; //可以运行 RunOnce(); //运行一次 }
private void btn_DrawROIs_Click(object sender, EventArgs e) { getSetOfLines.RemoveAll(); //删除所有项 hWindow_Final1.HobjectToHimage(ho_Image); //刷新图片 hWindow_Final1.ContextMenuStrip = contextMenuStrip1; //启用右键菜单 DrawMode(true); //绘制模式开启 Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 HObject ho_Rectangle = Func_HalconFunction.GenRectangle1(rectangle1); //创建矩形 hWindow_Final1.DispObj(ho_Rectangle, "blue"); //显示矩形 //创建该项 GetLineUseThreshold line = new GetLineUseThreshold(new Threshold(Func_Mathematics.ToRectangle2(rectangle1))); getSetOfLines.AddLine(line); //添加该项 cmb_slg_SelectItem.SelectedItem = null; // slgLine = null; }
private void btn_slg_ReDrowROI_Click(object sender, EventArgs e) { DrawMode(true);//绘制模式开启 Rectangle1 rectangle1 = Func_Mathematics.ToRectangle1(slgLine.parameter.rectangle2); Rectangle2 rectangle2; if (rectangle1 != null) { rectangle1 = Func_HalconFunction.DrawRectangle1Mod(hWindow_Final1.hWindowControl.HalconWindow, rectangle1);//画矩形 rectangle2 = Func_Mathematics.ToRectangle2(rectangle1); } else { rectangle2 = Func_HalconFunction.DrawRectangle2Mod(hWindow_Final1.hWindowControl.HalconWindow, slgLine.parameter.rectangle2); } DrawMode(false); //绘制模式关闭 slgLine.parameter.rectangle2 = rectangle2; RunOnce(); //运行测试 }
public override void DisplayDetail(HWindow_Final window)//显示详细信息 { try { ho_Shape.Dispose(); } catch (Exception) { } Circle circlePositioned = GetShapePositioned() as Circle; ho_Shape = Func_HalconFunction.GenCircle(circlePositioned); try { DP.SetPoint(circlePositioned); } catch (Exception) { DP = new Point(circlePositioned.hv_Column, circlePositioned.hv_Row); } base.DisplayDetail(window); HOperatorSet.GenRegionPoints(out HObject ho_Point, hv_Row, hv_Column); window.DispObj(ho_Point, "red", "fill"); ho_Point.Dispose(); window.DispString(DP.hv_Column - StringHeight, DP.hv_Row, name, "orange"); }
private void btn_DrawROIs_Click(object sender, EventArgs e) { if (getCircleUseThreshold == null) { getCircleUseThreshold = new GetCircleUseThreshold(); data = getCircleUseThreshold; circle = null; } getCircleUseThreshold.RemoveAll(); //删除所有项 hWindow_Final1.HobjectToHimage(ho_Image); //刷新图片 hWindow_Final1.ContextMenuStrip = contextMenuStrip1; //启用右键菜单 DrawMode(true); //绘制模式开启 Rectangle2 rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 HObject ho_Rectangle = Func_HalconFunction.GenRectangle2(rectangle2); //创建矩形 hWindow_Final1.DispObj(ho_Rectangle, "blue"); //显示矩形 getCircleUseThreshold.AddRegion(new GetRegionUseThreshold(new Threshold(rectangle2))); //添加该项 }
private void btn_DrawCircle_Click(object sender, EventArgs e) { if (circle == null) { circle = new Circle(); data = circle; } hWindow_Final1.HobjectToHimage(ho_Image); //刷新显示区 DrawMode(true); //绘制模式开启 circle.SetCircle(Func_HalconFunction.DrawCircle(hWindow_Final1.hWindowControl.HalconWindow)); //画圆编辑模式 DrawMode(false); //绘制模式关闭 getCircleUseThreshold = null; nud_Circle_x.Value = (decimal)circle.hv_Column.D; //赋值 nud_Circle_y.Value = (decimal)circle.hv_Row.D; //赋值 nud_Radius.Value = (decimal)circle.hv_Radius.D; //赋值 prepared = true; //可以运行 RunOnce(); //运行一次 }
public override void DisplayDetail(HWindow_Final window)//显示详细信息 { if (unit1 != null) { unit1.DisplayDetail(window); //显示unit1形状的详细信息 } if (unit2 != null) { unit2.DisplayDetail(window); //显示unit2形状的详细信息 } window.DispString(DP.hv_Column, DP.hv_Row - StringHeight, name, color); //显示名称 window.DispString(DP.hv_Column, DP.hv_Row, ((double)hv_PxDistance).ToString("f3"), color); //显示像素距离 window.DispString(DP.hv_Column, DP.hv_Row + StringHeight, ((double)hv_RealDistance).ToString("f3"), color); //显示实际距离 Line line = new Line(pStart.hv_Column, pStart.hv_Row, pEnd.hv_Column, pEnd.hv_Row); //创建结果线 HObject ho_Line = Func_HalconFunction.GenRegionLine(line); //创建结果线 window.DispObj(ho_Line, color, "fill"); //显示结果线 ho_Line.Dispose(); //释放ho_Line }
private void btn_Draw_Click(object sender, EventArgs e) { hWindow_Final1.HobjectToHimage(ho_Image);//刷新 TabPage tabPage = tabControl1.SelectedTab; if (tabPage != null) { if (tabPage.Name == "tp_Threshold") { if (!(line is GetLineUseThreshold)) { line = new GetLineUseThreshold(); data = line; } if (chk_Angle.Checked) { DrawMode(true); //绘制模式开启 (line as GetLineUseThreshold).parameter.rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 } else { DrawMode(true); //绘制模式开启 Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 (line as GetLineUseThreshold).parameter.rectangle2 = Func_Mathematics.ToRectangle2(rectangle1); //ROI矩形赋值 } sign = LineStyle.灰度抓取; } if (tabPage.Name == "tp_Measure_Pos") { if (!(line is GetLineUseMeasure_Pos))//?不是GetLineUseMeasure_Pos { line = new GetLineUseMeasure_Pos(); data = line; } DrawMode(true); //绘制模式开启 (line as GetLineUseMeasure_Pos).parameter.line.SetLine(Func_HalconFunction.DrawLine(hWindow_Final1.hWindowControl.HalconWindow)); //画ROI线 DrawMode(false); //绘制模式关闭 if (!chk_Angle.Checked) { double dx = (line as GetLineUseMeasure_Pos).parameter.line.hv_Column1 - (line as GetLineUseMeasure_Pos).parameter.line.hv_Column2; double dy = (line as GetLineUseMeasure_Pos).parameter.line.hv_Row1 - (line as GetLineUseMeasure_Pos).parameter.line.hv_Row2; double mx = ((line as GetLineUseMeasure_Pos).parameter.line.hv_Column1 + (line as GetLineUseMeasure_Pos).parameter.line.hv_Column2) / 2; double my = ((line as GetLineUseMeasure_Pos).parameter.line.hv_Row1 + (line as GetLineUseMeasure_Pos).parameter.line.hv_Row2) / 2; if (Math.Abs(dx) > Math.Abs(dy))//?横向距离长 { (line as GetLineUseMeasure_Pos).parameter.line.hv_Row1 = (int)my; (line as GetLineUseMeasure_Pos).parameter.line.hv_Row2 = (int)my; } else//?纵向距离长 { (line as GetLineUseMeasure_Pos).parameter.line.hv_Column1 = (int)mx; (line as GetLineUseMeasure_Pos).parameter.line.hv_Column2 = (int)mx; } } sign = LineStyle.边缘检测; } if (tabPage.Name == "tp_Canny") { if (!(line is GetLineUseCanny))//?不是GetLineUseMeasure_Pos { line = new GetLineUseCanny(); data = line; } if (chk_Angle.Checked) { DrawMode(true); //绘制模式开启 (line as GetLineUseCanny).parameter.rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 } else { DrawMode(true); //绘制模式开启 Rectangle1 rectangle1 = Func_HalconFunction.DrawRectangle1(hWindow_Final1.hWindowControl.HalconWindow); //画矩形 DrawMode(false); //绘制模式关闭 (line as GetLineUseCanny).parameter.rectangle2 = Func_Mathematics.ToRectangle2(rectangle1); //ROI矩形赋值 } sign = LineStyle.边缘拟合; } if (tabPage.Name == "tp_Metrology") { if (!(line is GetLineUseMetrology)) { line = new GetLineUseMetrology(); data = line; } DrawMode(true); //绘制模式开启 (line as GetLineUseMetrology).parameter.Line = Func_HalconFunction.DrawLine(hWindow_Final1.hWindowControl.HalconWindow); DrawMode(false); //绘制模式关闭 sign = LineStyle.直线拟合; } prepared = true; RunOnce(); } }
/// <summary> /// 测量 /// </summary> /// <param name="ho_Image"></param> /// <returns></returns> public override int Measure(HObject ho_Image) { base.Measure(ho_Image);//调用基类的测量方法 ho_Shape = Func_HalconFunction.GenCircle(GetShapePositioned() as Circle); return(1); }
public override void DisplayResult(HWindow_Final window) { try { ho_Shape.Dispose(); } catch (Exception) { } ho_Shape = Func_HalconFunction.GenRegionLine(this); window.DispObj(ho_Shape, shapeColor);//显示形状 }
public override void DisplayResult(HWindow_Final window)//显示简单信息 { try { ho_Shape.Dispose(); } catch (Exception) { } ho_Shape = Func_HalconFunction.GenRegionLine(GetShapePositioned() as Line); window.DispObj(ho_Shape, shapeColor);//显示形状 }
public override void DisplayResult(HWindow_Final window)//显示简单信息 { HObject ho_Rectangle = Func_HalconFunction.GenRectangle1(Func_Mathematics.ToRectangle1(ROI)); window.DispObj(ho_Rectangle, color, "margin"); }
/// <summary> /// 测量 /// </summary> /// <param name="ho_Image"></param> /// <returns></returns> public override int Measure(HObject ho_Image) { base.Measure(ho_Image); //调用基类的测量方法 ho_Shape = Func_HalconFunction.GenRectangle1(GetShapePositioned() as Rectangle1); //创建定位后的形状 return(1); }