private void action()
        {
            HObject ho_Rectangle, ho_ImageReduced;
            HObject ho_ImageMedian, ho_Regions, ho_ObjectSelected, ho_Rectangle1;
            HObject ho_Rectangle2, ho_RegionDifference, ho_RegionDifference1;
            HObject ho_ConnectedRegions;
            HTuple  hv_Row1 = null;
            HTuple  hv_Column1 = null, hv_Phi1 = null, hv_Length11 = null;
            HTuple  hv_Length21 = null, hv_Area = null, hv_Row2 = null;
            HTuple  hv_Column2 = null, hv_a1 = null, hv_Indices = null;
            HTuple  hv_Reduced = null, hv_a2 = null, hv_Row3 = null;
            HTuple  hv_Column3 = null, hv_Phi2 = null, hv_Length12 = null;
            HTuple  hv_Length22 = null, hv_caokuang = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImageMedian);
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            try
            {
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_centerRowm, hv_centerColumnm, hv_Phim, hv_Length1m,
                                           hv_Length2m);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Rectangle, out ho_ImageReduced);
                ho_ImageMedian.Dispose();
                HOperatorSet.MedianImage(ho_ImageReduced, out ho_ImageMedian, "circle", 3, "mirrored");
                ho_Regions.Dispose();
                HOperatorSet.AutoThreshold(ho_ImageMedian, out ho_Regions, 7);
                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_Regions, out ho_ObjectSelected, 1);
                HOperatorSet.SmallestRectangle2(ho_ObjectSelected, out hv_Row1, out hv_Column1,
                                                out hv_Phi1, out hv_Length11, out hv_Length21);
                ho_Rectangle1.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Phi1, hv_Length11 - 3,
                                           hv_Length21 - 3);
                ho_Rectangle2.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle2, hv_Row1, hv_Column1, hv_Phi1, hv_Length11 - 5,
                                           hv_Length21 - 5);
                ho_RegionDifference.Dispose();
                HOperatorSet.Difference(ho_Rectangle1, ho_Rectangle2, out ho_RegionDifference
                                        );
                ho_RegionDifference1.Dispose();
                HOperatorSet.Difference(ho_RegionDifference, ho_ObjectSelected, out ho_RegionDifference1
                                        );
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_RegionDifference1, out ho_ConnectedRegions);
                HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row2, out hv_Column2);
                hv_a1 = hv_Area.TupleMax();
                HOperatorSet.TupleFind(hv_Area, hv_a1, out hv_Indices);
                HOperatorSet.TupleRemove(hv_Area, hv_Indices, out hv_Reduced);
                hv_a2 = hv_Reduced.TupleMax();
                HOperatorSet.SmallestRectangle2(ho_ConnectedRegions, out hv_Row3, out hv_Column3,
                                                out hv_Phi2, out hv_Length12, out hv_Length22);
                hv_caokuang = (hv_a1 + hv_a2) / 4.0;
                HOperatorSet.Union1(ho_RegionDifference1, out RegionToDisp);

                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("caokuang");
                hv_result = hv_result.TupleConcat(hv_caokuang.D * pixeldist);
                result    = hv_result.Clone();

                ho_Rectangle.Dispose();
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_ImageMedian.Dispose();
                ho_Regions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_Rectangle1.Dispose();
                ho_Rectangle2.Dispose();
                ho_RegionDifference.Dispose();
                ho_RegionDifference1.Dispose();
                ho_ConnectedRegions.Dispose();
                algorithm.Region.Dispose();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("caokuang");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();

                ho_Rectangle.Dispose();
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_ImageMedian.Dispose();
                ho_Regions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_Rectangle1.Dispose();
                ho_Rectangle2.Dispose();
                ho_RegionDifference.Dispose();
                ho_RegionDifference1.Dispose();
                ho_ConnectedRegions.Dispose();
                algorithm.Region.Dispose();
            }
        }
Exemplo n.º 2
0
        // Local procedures
        public PointH GetMarkCenter(HObject ho_Image)
        {
            // Local iconic variables
            HObject ho_Regions, ho_Regions1, ho_RegionClosing, ho_RegionOpening;
            HObject ho_ConnectedRegions, ho_SelectedRegions2, ho_RegionFillUp1, ho_RegionFillUp2;
            HObject ho_SelectedRegions1;

            // Local control variables
            HTuple hv_AreaMax = null;
            HTuple hv_Y, hv_X;
            HTuple hv_Width, hv_Height, hv_Area;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_Regions1);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp1);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);

            try
            {
                //Find by region
                ho_Regions.Dispose();
                HOperatorSet.AutoThreshold(ho_Image, out ho_Regions, 2);
                //ho_RegionClosing.Dispose();
                //HOperatorSet.ClosingCircle(ho_Regions, out ho_RegionClosing, 3.5);
                //ho_RegionOpening.Dispose();
                //HOperatorSet.OpeningCircle(ho_RegionClosing, out ho_RegionOpening, 3.5);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                ho_RegionFillUp1.Dispose();
                HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp1);
                ho_SelectedRegions2.Dispose();
                HOperatorSet.SelectShape(ho_RegionFillUp1, out ho_SelectedRegions2, "area", "and", hv_MinAreaMark, hv_MaxAreaMark);
                ho_RegionFillUp2.Dispose();
                HOperatorSet.FillUp(ho_SelectedRegions2, out ho_RegionFillUp2);

                ho_RegionOpening.Dispose();
                HOperatorSet.ClosingCircle(ho_RegionFillUp2, out ho_RegionOpening, 3.5);
                ho_RegionOpening.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionFillUp2, out ho_RegionOpening, 3.5);
                ho_RegionFillUp1.Dispose();
                HOperatorSet.FillUp(ho_RegionOpening, out ho_RegionFillUp1);

                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShapeStd(ho_RegionFillUp1, out ho_SelectedRegions1, "max_area", 70);
                HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_AreaMax, out hv_Y, out hv_X);
                HOperatorSet.RegionFeatures(ho_SelectedRegions1, "width", out hv_Width);
                HOperatorSet.RegionFeatures(ho_SelectedRegions1, "height", out hv_Height);
                HOperatorSet.RegionFeatures(ho_SelectedRegions1, "area", out hv_Area);
                HOperatorSet.SetColor(hv_DispWindown, "red");
                HalconHelp halconHelp = new HalconHelp();
                string     strArea    = "";
                for (int i = 0; i < hv_Area.Length; i++)
                {
                    strArea += hv_Area[i].D.ToString() + ",";
                }
                halconHelp.disp_message(hv_DispWindown, "Area:" + strArea.TrimEnd(','), "image", 10, 1000, "red", "true");
                if (hv_X.Length <= 0 || hv_Y.Length <= 0)
                {
                    //未找到Mark点
                    return(new PointH());
                }
                double dd = hv_Width[0].D - hv_Height[0].D;
                if (Math.Abs(dd) > 3)
                {
                    //Mark点在视野的边界
                    return(new PointH());
                }
                HOperatorSet.DispObj(ho_SelectedRegions1, hv_DispWindown);
                return(new PointH(hv_X[0], hv_Y[0]));
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_Regions.Dispose();
                ho_RegionClosing.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_RegionFillUp2.Dispose();
                ho_SelectedRegions1.Dispose();

                throw HDevExpDefaultException;
            }
            finally
            {
                ho_Regions.Dispose();
                ho_RegionClosing.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_RegionFillUp2.Dispose();
                ho_SelectedRegions1.Dispose();
            }
        }
        private void action()
        {
            HObject ho_Rectangle, ho_ImageReduced, ho_ConnectedRegions2, ho_ObjectSelected3, ho_cl;
            HObject ho_Regions, ho_ObjectSelected, ho_RegionFillUp;
            HObject ho_Contours, ho_Rectangle1, ho_Rectangle3, ho_RegionDifference;
            HObject ho_ImageReduced1, ho_Border, ho_SelectedContours = null;
            HObject ho_ObjectSelected1 = null, ho_ObjectSelected2 = null;
            HObject ho_ContoursSplit1 = null, ho_RegionLines = null, ho_Region = null;
            HObject ho_RegionIntersection = null, ho_ConnectedRegions = null;
            HObject ho_Circle = null, ho_RegionLines1 = null, ho_Region1 = null;
            HObject ho_RegionIntersection1 = null, ho_ConnectedRegions1 = null;
            HObject ho_Circle1 = null;

            // Local control variables


            HTuple hv_Row4 = null;
            HTuple hv_Column4 = null, hv_Phi2 = null, hv_Length12 = null;
            HTuple hv_Length22 = null, hv_Area2 = null, hv_Row5 = null;
            HTuple hv_Column5 = null, hv_p = null, hv_fx = new HTuple();
            HTuple hv_cz = new HTuple(), hv_dz = new HTuple(), hv_lll = null;
            HTuple hv_Mean = null, hv_Deviation1 = null, hv_Length8 = null;
            HTuple hv_Number = new HTuple(), hv_Rowo1 = new HTuple();
            HTuple hv_Colo1 = new HTuple(), hv_Rowo2 = new HTuple();
            HTuple hv_Colo2 = new HTuple(), hv_as = new HTuple(), hv_ac = new HTuple();
            HTuple hv_b = new HTuple(), hv_cs = new HTuple(), hv_cc = new HTuple();
            HTuple hv_ds1 = new HTuple(), hv_ds2 = new HTuple(), hv_dc1 = new HTuple();
            HTuple hv_dc2 = new HTuple(), hv_Length3 = new HTuple();
            HTuple hv_dd = new HTuple(), hv_Floor = new HTuple(), hv_Length4 = new HTuple();
            HTuple hv_Sequence1 = new HTuple(), hv_Length5 = new HTuple();
            HTuple hv_Sequence = new HTuple(), hv_Sequence2 = new HTuple();
            HTuple hv_Reduced1 = new HTuple(), hv_Reduced2 = new HTuple();
            HTuple hv_Reduced3 = new HTuple(), hv_Reduced4 = new HTuple();
            HTuple hv_d1 = new HTuple(), hv_Length6 = new HTuple();
            HTuple hv_Sequence3 = new HTuple(), hv_Area = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Selectedc = new HTuple(), hv_Selectedr = new HTuple();
            HTuple hv_Newtuple = new HTuple(), hv_d2 = new HTuple();
            HTuple hv_Length7 = new HTuple(), hv_Sequence4 = new HTuple();
            HTuple hv_Area1 = new HTuple(), hv_Row3 = new HTuple();
            HTuple hv_Column3 = new HTuple(), hv_Selectedc1 = new HTuple();
            HTuple hv_Selectedr1 = new HTuple(), hv_Newtuple5 = new HTuple();
            HTuple hv_Selectedds1 = new HTuple(), hv_Selecteddc1 = new HTuple();
            HTuple hv_Selectedds2 = new HTuple(), hv_Selecteddc2 = new HTuple();
            HTuple hv_hs1 = new HTuple(), hv_hs1r = new HTuple(), hv_hs1c = new HTuple();
            HTuple hv_hs2 = new HTuple(), hv_hs2r = new HTuple(), hv_hs2c = new HTuple();
            HTuple hv_hc1 = new HTuple(), hv_hc2 = new HTuple(), hv_jdr = new HTuple();
            HTuple hv_jdc = new HTuple(), hv_jds = new HTuple(), hv_jdC = new HTuple();
            HTuple hv_jxr = new HTuple(), hv_jxc = new HTuple(), hv_jxs = new HTuple();
            HTuple hv_jxC = new HTuple(), hv_ydr = new HTuple(), hv_ydc = new HTuple();
            HTuple hv_yds = new HTuple(), hv_ydC = new HTuple(), hv_yxr = new HTuple();
            HTuple hv_yxc = new HTuple(), hv_yxs = new HTuple(), hv_yxC = new HTuple();
            HTuple hv_jin = new HTuple(), hv_yu = new HTuple(), hv_jp = new HTuple(), hv_Indices = new HTuple();
            HTuple hv_yp = new HTuple(), hv_j = new HTuple(), hv_luoju1 = new HTuple(), hv_Area3 = new HTuple(), hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_luoju2 = new HTuple(), hv_dajing = new HTuple();
            HTuple hv_xiaojing = new HTuple(), hv_changdu = new HTuple();
            HTuple hv_tiaoshu = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle3);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Border);
            HOperatorSet.GenEmptyObj(out ho_SelectedContours);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected2);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplit1);
            HOperatorSet.GenEmptyObj(out ho_RegionLines);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_RegionLines1);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected3);
            HOperatorSet.GenEmptyObj(out ho_cl);
            HOperatorSet.Union1(algorithm.Region, out RegionToDisp);
            try
            {
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_centerRowm, hv_centerColumnm, hv_Phim, hv_Length1m,
                                           hv_Length2m);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Rectangle, out ho_ImageReduced);
                ho_Regions.Dispose();
                HOperatorSet.AutoThreshold(ho_ImageReduced, out ho_Regions, 3);

                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_Regions, out ho_ObjectSelected, 1);
                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_Regions, out ho_ObjectSelected, 1);
                ho_ConnectedRegions2.Dispose();
                HOperatorSet.Connection(ho_ObjectSelected, out ho_ConnectedRegions2);
                HOperatorSet.AreaCenter(ho_ConnectedRegions2, out hv_Area3, out hv_Row1, out hv_Column1);
                HOperatorSet.TupleFind(hv_Area3, hv_Area3.TupleMax(), out hv_Indices);
                ho_ObjectSelected3.Dispose();
                HOperatorSet.SelectObj(ho_ConnectedRegions2, out ho_ObjectSelected3, hv_Indices + 1);
                ho_cl.Dispose();
                HOperatorSet.ClosingCircle(ho_ObjectSelected3, out ho_cl, 3.5);
                ho_RegionFillUp.Dispose();
                HOperatorSet.FillUp(ho_ObjectSelected3, out ho_RegionFillUp);
                ho_Contours.Dispose();
                HOperatorSet.GenContourRegionXld(ho_RegionFillUp, out ho_Contours, "border");
                HOperatorSet.SmallestRectangle2Xld(ho_Contours, out hv_Row4, out hv_Column4,
                                                   out hv_Phi2, out hv_Length12, out hv_Length22);
                HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area2, out hv_Row5, out hv_Column5);
                hv_p = ((hv_Phi2 - hv_Phim)).TupleAbs();
                while ((int)(new HTuple(hv_p.TupleGreater((new HTuple(90)).TupleRad()))) != 0)
                {
                    hv_p = ((hv_p - ((new HTuple(180)).TupleRad()))).TupleAbs();
                }
                if ((int)(new HTuple(hv_p.TupleGreater((new HTuple(45)).TupleRad()))) != 0)
                {
                    hv_fx = hv_Phi2.Clone();
                    hv_cz = hv_Length12.Clone();
                    hv_dz = hv_Length22.Clone();
                }
                else
                {
                    hv_fx = hv_Phi2 + ((new HTuple(90)).TupleRad());
                    hv_cz = hv_Length22.Clone();
                    hv_dz = hv_Length12.Clone();
                }
                hv_lll = ((((hv_cz * hv_dz) * 4) - hv_Area2) / 2) / hv_cz;
                ho_Rectangle1.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row4, hv_Column4, hv_fx, hv_cz,
                                           hv_dz + 5);
                ho_Rectangle3.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle3, hv_Row4, hv_Column4, hv_Phi2, hv_Length12 + 200,
                                           hv_lll);
                ho_RegionDifference.Dispose();
                HOperatorSet.Difference(ho_Rectangle1, ho_Rectangle3, out ho_RegionDifference
                                        );
                ho_ImageReduced1.Dispose();
                HOperatorSet.ReduceDomain(ho_ImageReduced, ho_RegionDifference, out ho_ImageReduced1
                                          );
                HOperatorSet.Intensity(ho_RegionDifference, ho_ImageReduced1, out hv_Mean, out hv_Deviation1);
                ho_Border.Dispose();
                HOperatorSet.ThresholdSubPix(ho_ImageReduced1, out ho_Border, hv_Mean);
                HOperatorSet.LengthXld(ho_Border, out hv_Length8);
                if ((int)(new HTuple((new HTuple(hv_Length8.TupleLength())).TupleGreater(1))) != 0)
                {
                    ho_SelectedContours.Dispose();
                    HOperatorSet.SelectContoursXld(ho_Border, out ho_SelectedContours, "contour_length",
                                                   0.5 * (hv_Length8.TupleMax()), 1.5 * (hv_Length8.TupleMax()), -0.5, 0.5);
                    HOperatorSet.CountObj(ho_SelectedContours, out hv_Number);
                    if ((int)(new HTuple(hv_Number.TupleEqual(2))) != 0)
                    {
                        ho_ObjectSelected1.Dispose();
                        HOperatorSet.SelectObj(ho_SelectedContours, out ho_ObjectSelected1, 1);
                        ho_ObjectSelected2.Dispose();
                        HOperatorSet.SelectObj(ho_SelectedContours, out ho_ObjectSelected2, 2);
                        HOperatorSet.GetContourXld(ho_ObjectSelected1, out hv_Rowo1, out hv_Colo1);
                        HOperatorSet.GetContourXld(ho_ObjectSelected2, out hv_Rowo2, out hv_Colo2);
                        HOperatorSet.TupleTan(hv_fx + ((new HTuple(0.000001)).TupleRad()), out hv_as);
                        HOperatorSet.TupleTan(hv_fx + ((new HTuple(90.000001)).TupleRad()), out hv_ac);
                        hv_b  = -1;
                        hv_cs = (-(hv_Row4 + (5000 * (((hv_fx + ((new HTuple(90)).TupleRad()))).TupleSin()
                                                      )))) - (hv_as * (hv_Column4 - (5000 * (((hv_fx + ((new HTuple(90)).TupleRad()))).TupleCos()
                                                                                             ))));
                        hv_cc = (-(hv_Row4 + (5000 * (hv_fx.TupleSin())))) - (hv_ac * (hv_Column4 - (5000 * (hv_fx.TupleCos()
                                                                                                             ))));
                        hv_ds1 = (((((hv_as * hv_Colo1) + (hv_b * (-hv_Rowo1))) + hv_cs)).TupleAbs()) / (((1 + (hv_as * hv_as))).TupleSqrt()
                                                                                                         );
                        hv_ds2 = (((((hv_as * hv_Colo2) + (hv_b * (-hv_Rowo2))) + hv_cs)).TupleAbs()) / (((1 + (hv_as * hv_as))).TupleSqrt()
                                                                                                         );
                        hv_dc1 = (((((hv_ac * hv_Colo1) + (hv_b * (-hv_Rowo1))) + hv_cc)).TupleAbs()) / (((1 + (hv_ac * hv_ac))).TupleSqrt()
                                                                                                         );
                        hv_dc2 = (((((hv_ac * hv_Colo2) + (hv_b * (-hv_Rowo2))) + hv_cc)).TupleAbs()) / (((1 + (hv_ac * hv_ac))).TupleSqrt()
                                                                                                         );
                        ho_ContoursSplit1.Dispose();
                        HOperatorSet.SegmentContoursXld(ho_ObjectSelected2, out ho_ContoursSplit1,
                                                        "lines_circles", 5, 4, 2);
                        HOperatorSet.LengthXld(ho_ContoursSplit1, out hv_Length3);
                        hv_dd = hv_Length3.TupleMean();
                        HOperatorSet.TupleFloor(hv_dd, out hv_Floor);
                        HOperatorSet.TupleLength(hv_Colo1, out hv_Length4);
                        HOperatorSet.TupleGenSequence(hv_Length4 - hv_Floor, hv_Length4 - 1, 1, out hv_Sequence1);
                        HOperatorSet.TupleLength(hv_Colo2, out hv_Length5);
                        HOperatorSet.TupleGenSequence(0, hv_Floor - 1, 1, out hv_Sequence);
                        HOperatorSet.TupleGenSequence(hv_Length5 - hv_Floor, hv_Length5 - 1, 1, out hv_Sequence2);
                        HOperatorSet.TupleRemove(hv_ds1, hv_Sequence, out hv_Reduced1);
                        HOperatorSet.TupleRemove(hv_ds1, hv_Sequence1, out hv_Reduced2);
                        HOperatorSet.TupleRemove(hv_ds2, hv_Sequence, out hv_Reduced3);
                        HOperatorSet.TupleRemove(hv_ds2, hv_Sequence2, out hv_Reduced4);
                        hv_d1 = hv_Reduced1 - hv_Reduced2;
                        HOperatorSet.TupleLength(hv_d1, out hv_Length6);
                        HOperatorSet.TupleGenSequence(1, hv_Length6, 1, out hv_Sequence3);
                        ho_RegionLines.Dispose();
                        HOperatorSet.GenRegionLine(out ho_RegionLines, 0, 0, 0, hv_Length6);
                        ho_Region.Dispose();
                        HOperatorSet.GenRegionPoints(out ho_Region, hv_d1, hv_Sequence3);
                        ho_RegionIntersection.Dispose();
                        HOperatorSet.Intersection(ho_RegionLines, ho_Region, out ho_RegionIntersection
                                                  );
                        ho_ConnectedRegions.Dispose();
                        HOperatorSet.Connection(ho_RegionIntersection, out ho_ConnectedRegions);
                        HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row2, out hv_Column2);
                        HOperatorSet.TupleSelect(hv_Colo1, ((hv_Column2 + (hv_dd / 2))).TupleFloor(),
                                                 out hv_Selectedc);
                        HOperatorSet.TupleSelect(hv_Rowo1, ((hv_Column2 + (hv_dd / 2))).TupleFloor(),
                                                 out hv_Selectedr);
                        HOperatorSet.TupleGenConst(new HTuple(hv_Selectedr.TupleLength()), 1, out hv_Newtuple);
                        ho_Circle.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle, hv_Selectedr, hv_Selectedc, hv_Newtuple);
                        hv_d2 = hv_Reduced3 - hv_Reduced4;
                        HOperatorSet.TupleLength(hv_d2, out hv_Length7);
                        HOperatorSet.TupleGenSequence(1, hv_Length7, 1, out hv_Sequence4);
                        ho_RegionLines1.Dispose();
                        HOperatorSet.GenRegionLine(out ho_RegionLines1, 0, 0, 0, hv_Length7);
                        ho_Region1.Dispose();
                        HOperatorSet.GenRegionPoints(out ho_Region1, hv_d2, hv_Sequence4);
                        ho_RegionIntersection1.Dispose();
                        HOperatorSet.Intersection(ho_Region1, ho_RegionLines1, out ho_RegionIntersection1
                                                  );
                        ho_ConnectedRegions1.Dispose();
                        HOperatorSet.Connection(ho_RegionIntersection1, out ho_ConnectedRegions1);
                        HOperatorSet.AreaCenter(ho_ConnectedRegions1, out hv_Area1, out hv_Row3,
                                                out hv_Column3);
                        HOperatorSet.TupleSelect(hv_Colo2, ((hv_Column3 + (hv_dd / 2))).TupleFloor(),
                                                 out hv_Selectedc1);
                        HOperatorSet.TupleSelect(hv_Rowo2, ((hv_Column3 + (hv_dd / 2))).TupleFloor(),
                                                 out hv_Selectedr1);
                        HOperatorSet.TupleGenConst(new HTuple(hv_Selectedr1.TupleLength()), 1, out hv_Newtuple5);
                        ho_Circle1.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle1, hv_Selectedr1, hv_Selectedc1, hv_Newtuple5);
                        HOperatorSet.TupleSelect(hv_ds1, ((hv_Column2 + (hv_dd / 2))).TupleFloor(), out hv_Selectedds1);
                        HOperatorSet.TupleSelect(hv_dc1, ((hv_Column2 + (hv_dd / 2))).TupleFloor(), out hv_Selecteddc1);
                        HOperatorSet.TupleSelect(hv_ds2, ((hv_Column3 + (hv_dd / 2))).TupleFloor(), out hv_Selectedds2);
                        HOperatorSet.TupleSelect(hv_dc2, ((hv_Column3 + (hv_dd / 2))).TupleFloor(), out hv_Selecteddc2);
                        if ((int)(new HTuple((new HTuple(hv_Selectedds1.TupleMean())).TupleLess(hv_Selectedds2.TupleMean()
                                                                                                ))) != 0)
                        {
                            hv_hs1  = hv_Selectedds1.Clone();
                            hv_hs1r = hv_Selectedr.Clone();
                            hv_hs1c = hv_Selectedc.Clone();
                            hv_hs2  = hv_Selectedds2.Clone();
                            hv_hs2r = hv_Selectedr1.Clone();
                            hv_hs2c = hv_Selectedc1.Clone();
                            hv_hc1  = hv_Selecteddc1.Clone();
                            hv_hc2  = hv_Selecteddc2.Clone();
                        }
                        else
                        {
                            hv_hs1  = hv_Selectedds2.Clone();
                            hv_hs2r = hv_Selectedr.Clone();
                            hv_hs2c = hv_Selectedc.Clone();
                            hv_hs2  = hv_Selectedds1.Clone();
                            hv_hs1r = hv_Selectedr1.Clone();
                            hv_hs1c = hv_Selectedc1.Clone();
                            hv_hc2  = hv_Selecteddc1.Clone();
                            hv_hc1  = hv_Selecteddc2.Clone();
                        }
                        hv_jdr = new HTuple();
                        hv_jdc = new HTuple();
                        hv_jds = new HTuple();
                        hv_jdC = new HTuple();
                        hv_jxr = new HTuple();
                        hv_jxc = new HTuple();
                        hv_jxs = new HTuple();
                        hv_jxC = new HTuple();
                        hv_ydr = new HTuple();
                        hv_ydc = new HTuple();
                        hv_yds = new HTuple();
                        hv_ydC = new HTuple();
                        hv_yxr = new HTuple();
                        hv_yxc = new HTuple();
                        hv_yxs = new HTuple();
                        hv_yxC = new HTuple();
                        hv_jin = new HTuple(hv_hs1.TupleLength());
                        hv_yu  = new HTuple(hv_hs2.TupleLength());
                        hv_jp  = hv_hs1.TupleMean();
                        hv_yp  = hv_hs2.TupleMean();
                        HTuple end_val128  = hv_jin - 1;
                        HTuple step_val128 = 1;
                        for (hv_j = 0; hv_j.Continue(end_val128, step_val128); hv_j = hv_j.TupleAdd(step_val128))
                        {
                            if ((int)(new HTuple(((hv_hs1.TupleSelect(hv_j))).TupleLess(hv_jp))) != 0)
                            {
                                hv_jdr = hv_jdr.TupleConcat(hv_hs1r.TupleSelect(hv_j));
                                hv_jdc = hv_jdc.TupleConcat(hv_hs1c.TupleSelect(hv_j));
                                hv_jds = hv_jds.TupleConcat(hv_hs1.TupleSelect(hv_j));
                                hv_jdC = hv_jdC.TupleConcat(hv_hc1.TupleSelect(hv_j));
                            }
                            else
                            {
                                hv_jxr = hv_jxr.TupleConcat(hv_hs1r.TupleSelect(hv_j));
                                hv_jxc = hv_jxc.TupleConcat(hv_hs1c.TupleSelect(hv_j));
                                hv_jxs = hv_jxs.TupleConcat(hv_hs1.TupleSelect(hv_j));
                                hv_jxC = hv_jxC.TupleConcat(hv_hc1.TupleSelect(hv_j));
                            }
                        }
                        HTuple end_val141  = hv_yu - 1;
                        HTuple step_val141 = 1;
                        for (hv_j = 0; hv_j.Continue(end_val141, step_val141); hv_j = hv_j.TupleAdd(step_val141))
                        {
                            if ((int)(new HTuple(((hv_hs2.TupleSelect(hv_j))).TupleGreater(hv_yp))) != 0)
                            {
                                hv_ydr = hv_ydr.TupleConcat(hv_hs2r.TupleSelect(hv_j));
                                hv_ydc = hv_ydc.TupleConcat(hv_hs2c.TupleSelect(hv_j));
                                hv_yds = hv_yds.TupleConcat(hv_hs2.TupleSelect(hv_j));
                                hv_ydC = hv_ydC.TupleConcat(hv_hc2.TupleSelect(hv_j));
                            }
                            else
                            {
                                hv_yxr = hv_yxr.TupleConcat(hv_hs2r.TupleSelect(hv_j));
                                hv_yxc = hv_yxc.TupleConcat(hv_hs2c.TupleSelect(hv_j));
                                hv_yxs = hv_yxs.TupleConcat(hv_hs2.TupleSelect(hv_j));
                                hv_yxC = hv_yxC.TupleConcat(hv_hc2.TupleSelect(hv_j));
                            }
                        }
                        hv_luoju1 = (((hv_hc1.TupleMax()) - (hv_hc1.TupleMin())) / ((new HTuple(hv_hc1.TupleLength()
                                                                                                )) - 1)) * 2;
                        hv_luoju2 = (((hv_hc2.TupleMax()) - (hv_hc2.TupleMin())) / ((new HTuple(hv_hc2.TupleLength()
                                                                                                )) - 1)) * 2;
                        hv_dajing   = (hv_yds.TupleMean()) - (hv_jds.TupleMean());
                        hv_xiaojing = (hv_yxs.TupleMean()) - (hv_jxs.TupleMean());
                        hv_changdu  = (((hv_hc1.TupleConcat(hv_hc2))).TupleMax()) - (((hv_hc1.TupleConcat(
                                                                                           hv_hc2))).TupleMin());
                        hv_tiaoshu = (((((((new HTuple(hv_jds.TupleLength())).TupleConcat(new HTuple(hv_jxs.TupleLength()
                                                                                                     )))).TupleConcat(new HTuple(hv_yds.TupleLength())))).TupleConcat(new HTuple(hv_yxs.TupleLength()
                                                                                                                                                                                 )))).TupleMax();
                    }
                }
                HOperatorSet.Union2(ho_Circle, ho_Circle1, out RegionToDisp);



                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("大径平均值");
                hv_result = hv_result.TupleConcat(hv_dajing.D * pixeldist);
                hv_result = hv_result.TupleConcat("螺纹长度");
                hv_result = hv_result.TupleConcat(hv_changdu.D * pixeldist);
                hv_result = hv_result.TupleConcat("螺纹条数");
                hv_result = hv_result.TupleConcat(hv_tiaoshu.D);
                hv_result = hv_result.TupleConcat("螺距1");
                hv_result = hv_result.TupleConcat(hv_luoju1.D * pixeldist);
                hv_result = hv_result.TupleConcat("螺距2");
                hv_result = hv_result.TupleConcat(hv_luoju2.D * pixeldist);
                result    = hv_result.Clone();

                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Regions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_RegionFillUp.Dispose();
                ho_Contours.Dispose();
                ho_Rectangle1.Dispose();
                ho_Rectangle3.Dispose();
                ho_RegionDifference.Dispose();
                ho_ImageReduced1.Dispose();
                ho_Border.Dispose();
                ho_SelectedContours.Dispose();
                ho_ObjectSelected1.Dispose();
                ho_ObjectSelected2.Dispose();
                ho_ContoursSplit1.Dispose();
                ho_RegionLines.Dispose();
                ho_Region.Dispose();
                ho_RegionIntersection.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_Circle.Dispose();
                ho_RegionLines1.Dispose();
                ho_Region1.Dispose();
                ho_RegionIntersection1.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_Circle1.Dispose();
                ho_ConnectedRegions2.Dispose();
                ho_ObjectSelected3.Dispose();
                ho_cl.Dispose();
                algorithm.Region.Dispose();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("大径平均值");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("螺纹长度");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("螺纹条数");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("螺距1");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("螺距2");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();

                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Regions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_RegionFillUp.Dispose();
                ho_Contours.Dispose();
                ho_Rectangle1.Dispose();
                ho_Rectangle3.Dispose();
                ho_RegionDifference.Dispose();
                ho_ImageReduced1.Dispose();
                ho_Border.Dispose();
                ho_SelectedContours.Dispose();
                ho_ObjectSelected1.Dispose(); ho_cl.Dispose();
                ho_ObjectSelected2.Dispose();
                ho_ContoursSplit1.Dispose();
                ho_RegionLines.Dispose();
                ho_Region.Dispose();
                ho_RegionIntersection.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_Circle.Dispose();
                ho_RegionLines1.Dispose();
                ho_Region1.Dispose();
                ho_RegionIntersection1.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_Circle1.Dispose();
                ho_ConnectedRegions2.Dispose();
                ho_ObjectSelected3.Dispose();
                algorithm.Region.Dispose();
            }
        }
Exemplo n.º 4
0
        public PointH GetMarkCenterXLD(HObject ho_Image)
        {
            // Local iconic variables
            HObject ho_Regions, ho_Regions1, ho_RegionClosing, ho_RegionOpening;
            HObject ho_ConnectedRegions, ho_SelectedRegions2, ho_RegionFillUp1, ho_RegionFillUp2;
            HObject ho_SelectedRegions1;
            HObject ho_ROIOuter, ho_ROIInner, ho_ROI, ho_ROIEdges, ho_RimReduced;
            HObject ho_Edges, ho_ContoursSplit, ho_RelEdges, ho_UnionContours;
            HObject ho_ContCircle1;
            HTuple  hv_Number = null, hv_Row3 = null, hv_Column3 = null;
            HTuple  hv_Radius2 = null, hv_StartPhi2 = null, hv_EndPhi2 = null;
            HTuple  hv_PointOrder3 = null;

            // Local control variables
            HTuple hv_AreaMax = null;
            HTuple hv_Y, hv_X;
            HTuple hv_Width, hv_Height, hv_Area;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_Regions1);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp1);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);

            HOperatorSet.GenEmptyObj(out ho_ROIOuter);
            HOperatorSet.GenEmptyObj(out ho_ROIInner);
            HOperatorSet.GenEmptyObj(out ho_ROI);
            HOperatorSet.GenEmptyObj(out ho_ROIEdges);
            HOperatorSet.GenEmptyObj(out ho_RimReduced);
            HOperatorSet.GenEmptyObj(out ho_Edges);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_RelEdges);
            HOperatorSet.GenEmptyObj(out ho_UnionContours);
            HOperatorSet.GenEmptyObj(out ho_ContCircle1);

            try
            {
                //Find by region
                ho_Regions.Dispose();
                HOperatorSet.AutoThreshold(ho_Image, out ho_Regions, 2);
                //ho_RegionClosing.Dispose();
                //HOperatorSet.ClosingCircle(ho_Regions, out ho_RegionClosing, 3.5);
                //ho_RegionOpening.Dispose();
                //HOperatorSet.OpeningCircle(ho_RegionClosing, out ho_RegionOpening, 3.5);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                ho_RegionFillUp1.Dispose();
                HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp1);
                ho_SelectedRegions2.Dispose();
                HOperatorSet.SelectShape(ho_RegionFillUp1, out ho_SelectedRegions2, "area", "and", hv_MinAreaMark, hv_MaxAreaMark);
                ho_RegionFillUp2.Dispose();
                HOperatorSet.FillUp(ho_SelectedRegions2, out ho_RegionFillUp2);

                ho_RegionOpening.Dispose();
                HOperatorSet.ClosingCircle(ho_RegionFillUp2, out ho_RegionOpening, 3.5);
                ho_RegionOpening.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionFillUp2, out ho_RegionOpening, 3.5);
                ho_RegionFillUp1.Dispose();
                HOperatorSet.FillUp(ho_RegionOpening, out ho_RegionFillUp1);

                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShapeStd(ho_RegionFillUp1, out ho_SelectedRegions1, "max_area", 70);
                HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_AreaMax, out hv_Y, out hv_X);
                HOperatorSet.RegionFeatures(ho_SelectedRegions1, "width", out hv_Width);
                HOperatorSet.RegionFeatures(ho_SelectedRegions1, "height", out hv_Height);
                HOperatorSet.RegionFeatures(ho_SelectedRegions1, "area", out hv_Area);
                HalconHelp halconHelp = new HalconHelp();
                HOperatorSet.SetColor(hv_DispWindown, "red");
                string strArea = "";
                for (int i = 0; i < hv_Area.Length; i++)
                {
                    strArea += hv_Area[i].D.ToString() + ",";
                }
                halconHelp.disp_message(hv_DispWindown, "Area:" + strArea.TrimEnd(','), "image", 10, 1000, "red", "true");
                //HOperatorSet.SetColor(hv_DispWindown, "red");
                if (hv_X.Length <= 0 || hv_Y.Length <= 0)
                {
                    //未找到Mark点
                    return(new PointH());
                }
                double dd = hv_Width[0].D - hv_Height[0].D;
                if (Math.Abs(dd) > 9)
                {
                    //Mark点在视野的边界
                    return(new PointH());
                }


                //Find by XLD
                HOperatorSet.DilationCircle(ho_SelectedRegions1, out ho_ROIOuter, 8.5);
                ho_ROIInner.Dispose();
                HOperatorSet.ErosionCircle(ho_SelectedRegions1, out ho_ROIInner, 8.5);
                ho_ROI.Dispose();
                HOperatorSet.Difference(ho_ROIOuter, ho_ROIInner, out ho_ROI);
                ho_ROIEdges.Dispose();
                HOperatorSet.Union1(ho_ROI, out ho_ROIEdges);
                //Reduce the region of interest (domain) to the extracted
                //regions containing the edges.
                ho_RimReduced.Dispose();
                HOperatorSet.ReduceDomain(ho_Image, ho_ROIEdges, out ho_RimReduced);
                //Extract subpixel precise edges
                ho_Edges.Dispose();
                HOperatorSet.EdgesSubPix(ho_RimReduced, out ho_Edges, "canny", 4, 20, 40);
                //分割线段
                ho_ContoursSplit.Dispose();
                HOperatorSet.SegmentContoursXld(ho_Edges, out ho_ContoursSplit, "lines_circles", 5, 4, 2);
                //Select only the contours with length larger than 30 pixels
                ho_RelEdges.Dispose();
                HOperatorSet.SelectContoursXld(ho_ContoursSplit, out ho_RelEdges, "length", 30, 999999, 0, 0);
                ho_UnionContours.Dispose();
                HOperatorSet.UnionAdjacentContoursXld(ho_RelEdges, out ho_UnionContours, 100, 1, "attr_keep");
                HOperatorSet.CountObj(ho_UnionContours, out hv_Number);
                if ((int)(new HTuple(hv_Number.TupleGreater(1))) != 0)
                {
                    //未找到Mark点
                    return(new PointH());
                }
                HOperatorSet.FitCircleContourXld(ho_UnionContours, "algebraic", -1, 0, 0, 3, 2,
                                                 out hv_Row3, out hv_Column3, out hv_Radius2, out hv_StartPhi2, out hv_EndPhi2, out hv_PointOrder3);
                ho_ContCircle1.Dispose();
                HOperatorSet.GenCircleContourXld(out ho_ContCircle1, hv_Row3, hv_Column3, hv_Radius2, 0, 6.28318, "positive", 1);

                HOperatorSet.SetColor(hv_DispWindown, "red");
                HOperatorSet.DispCircle(hv_DispWindown, hv_Row3, hv_Column3, hv_Radius2);
                //HOperatorSet.SetLineWidth(hv_DispWindown, 3);
                //HOperatorSet.DispObj(ho_ContCircle1, hv_DispWindown);
                return(new PointH(hv_Column3[0], hv_Row3[0]));
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_Regions.Dispose();
                ho_RegionClosing.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_RegionFillUp2.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_ROIOuter.Dispose();
                ho_ROIInner.Dispose();
                ho_ROI.Dispose();
                ho_ROIEdges.Dispose();
                ho_RimReduced.Dispose();
                ho_Edges.Dispose();
                ho_ContoursSplit.Dispose();
                ho_RelEdges.Dispose();
                ho_UnionContours.Dispose();
                ho_ContCircle1.Dispose();
                throw HDevExpDefaultException;
            }
            finally
            {
                ho_Regions.Dispose();
                ho_RegionClosing.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_RegionFillUp2.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_ROIOuter.Dispose();
                ho_ROIInner.Dispose();
                ho_ROI.Dispose();
                ho_ROIEdges.Dispose();
                ho_RimReduced.Dispose();
                ho_Edges.Dispose();
                ho_ContoursSplit.Dispose();
                ho_RelEdges.Dispose();
                ho_UnionContours.Dispose();
                ho_ContCircle1.Dispose();
            }
        }
        private void action()
        {
            // Local iconic variables

            HObject ho_Circle, ho_ImageReduced;
            HObject ho_Border, ho_UnionContours, ho_SelectedXLD, ho_Region;

            // Local control variables

            HTuple  hv_bianc = null, hv_duibianc = null;
            HObject ho_Regions, ho_ObjectSelected;
            HObject ho_ConnectedRegions, ho_SelectedRegions1, ho_RegionClosing;
            HObject ho_RegionFillUp;


            // Local control variables

            HTuple hv_Area, hv_Row, hv_Column;


            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            try
            {
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, zxr, zxc, ra);

                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Circle, out ho_ImageReduced);

                ho_Regions.Dispose();
                HOperatorSet.AutoThreshold(ho_ImageReduced, out ho_Regions, 0.3);
                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_Regions, out ho_ObjectSelected, 1);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_ObjectSelected, out ho_ConnectedRegions);
                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions1, "outer_radius",
                                         "and", 200, 300);
                ho_RegionClosing.Dispose();
                HOperatorSet.ClosingCircle(ho_SelectedRegions1, out ho_RegionClosing, 9.5);
                ho_RegionFillUp.Dispose();
                HOperatorSet.FillUp(ho_RegionClosing, out ho_RegionFillUp);
                HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area, out hv_Row, out hv_Column);
                hv_bianc    = ((((hv_Area * 2) / 3) / ((new HTuple(3)).TupleSqrt()))).TupleSqrt();
                hv_duibianc = hv_bianc * ((new HTuple(3)).TupleSqrt());
                HOperatorSet.Union1(ho_RegionFillUp, out RegionToDisp);


                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("六角边长");
                hv_result = hv_result.TupleConcat(hv_bianc.D * pixeldist);
                hv_result = hv_result.TupleConcat("六角对边长");
                hv_result = hv_result.TupleConcat(hv_duibianc.D * pixeldist);
                result    = hv_result.Clone();


                ho_Circle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Regions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_RegionClosing.Dispose();
                ho_RegionFillUp.Dispose();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("六角边长");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("六角对边长");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();


                ho_Circle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Regions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_RegionClosing.Dispose();
                ho_RegionFillUp.Dispose();
            }
        }