예제 #1
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));
        }
예제 #2
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);
 }
예제 #3
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);
 }
예제 #4
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);
        }