Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 public override int Measure(HObject ho_Image)
 {
     SetLine(Func_ImageProcessing.getLine_FromMetrology(ho_Image, parameter, parameter.Line, out contours, out cross));
     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(1);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 测量
 /// </summary>
 /// <param name="ho_Image"></param>
 /// <returns></returns>
 public override int Measure(HObject ho_Image)
 {
     //边缘提取拟合成线
     SetLine(Func_ImageProcessing.getLine_FromCanny(ho_Image, parameter, parameter.rectangle2.GetShapePositioned() as Rectangle2));
     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(1);
 }
Ejemplo n.º 5
0
        public override int Measure(HObject ho_Image)
        {
            HObject ho_RegionUnion;

            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            foreach (var item in RegionList)
            {
                item.Measure(ho_Image);                                                  //每一项执行测量
                HOperatorSet.Union2(ho_RegionUnion, item.Ho_Region, out ho_RegionUnion); //联合成一个大区域
            }
            SetCircle(Func_ImageProcessing.getCircle_FromRegion(ho_RegionUnion));        //从区域获取最大外接圆
            MeasureDone = true;                                                          //已测量标志为true
            return(1);
        }
Ejemplo n.º 6
0
        public override int Measure(HObject ho_Image)                                                                          //测量
        {
            parameter.line.Measure(ho_Image);                                                                                  //测量
            Point point = Func_ImageProcessing.getPoint(ho_Image, parameter);                                                  //求出检测到的点

            SetLine(Func_Mathematics.Line_Point_Length_To_VerticalLine(parameter.line, point, parameter.hv_RoiWidthLen2 / 2)); //根据检测长度生成边缘线
            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(1);
        }
Ejemplo n.º 7
0
 public override int Measure(HObject ho_Image)
 {
     SetCircle(Func_ImageProcessing.getCircle_FromMetrology(ho_Image, parameter, parameter.Circle, out contours, out cross));
     MeasureDone = true;//已测量标志为true
     return(1);
 }