Exemplo n.º 1
0
        public bool Init(string path)
        {
            try
            {
                //throw new NotImplementedException();
                // Local iconic variables

                // Local control variables
                HObject Line = null;
                HTuple  hv_ModelID1 = null, hv_ModelID2 = null;
                HTuple  hv_ModelID3 = null, hv_ModelID4 = null, hv_ModelID = null;
                // Initialize local and output iconic variables
                //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID1", out hv_ModelID1);
                //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID2", out hv_ModelID2);
                //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID3", out hv_ModelID3);
                HOperatorSet.ReadShapeModel(path + "/model/ModelID4", out hv_ModelID4);
                hv_ModelIDOut = hv_ModelID4.Clone();
                HOperatorSet.ReadNccModel(path + "/model/model1test", out hv_ModelID);
                HOperatorSet.ReadNccModel(path + "/model/model1test1", out hv_ModelID1);
                HOperatorSet.ReadNccModel(path + "/model/model1test2", out hv_ModelID2);
                HOperatorSet.ReadNccModel(path + "/model/model1test3", out hv_ModelID3);
                hv_model = new HTuple();
                hv_model = hv_model.TupleConcat(hv_ModelID);
                hv_model = hv_model.TupleConcat(hv_ModelID1);
                hv_model = hv_model.TupleConcat(hv_ModelID2);
                hv_model = hv_model.TupleConcat(hv_ModelID3);
                return(true);
            }
            catch (Exception ee)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>Creates an instance of the fixed window implementation</summary>
 /// <param name="windowID">The window ID of an existing HALCON window</param>
 public HDevOpFixedWindowImpl(HTuple windowID)
 {
     if (windowID.Length != 1)
     {
         HDevEngineException.ThrowGeneric("Please specify exactly one window ID");
     }
     this.activeID = windowID.Clone();
 }
Exemplo n.º 3
0
 /// <summary>
 ///   Create leaf vector of dimension 0 for the specified tuple
 /// </summary>
 public HTupleVector(HTuple tuple)
     : base(0)
 {
     if (tuple == null)
     {
         throw new HVectorAccessException("Null tuple not allowed in vector");
     }
     this.mTuple = tuple.Clone();
 }
Exemplo n.º 4
0
        private void action()
        {
            HObject ho_Rectangle1, ho_ImageReduced1, ho_Border, ho_ContoursSplit, ho_RegionLines;

            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Border);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_RegionLines);
            HTuple hv_RowBeginOut = null, hv_ColBeginOut = null, hv_RowEndOut = null, hv_ColEndOut = null;

            if (hv_ModelID == null)
            {
                HOperatorSet.ReadNccModel(PathHelper.currentProductPath + @"\jdmx.ncm", out hv_ModelID);
            }
            HTuple hv_ColBegin = null, hv_RowEnd = null, hv_ColEnd = null, hv_Angle1 = null, hv_jiaodu = null;
            HTuple hv_Nr = null, hv_Nc = null, hv_Dist = null, hv_RowBegin = null;
            HTuple hv_Angle = null, hv_Score = null, hv_Row1 = null, hv_Column1 = null;

            HOperatorSet.FindNccModel(Image, hv_ModelID, -0.2, 0.39, 0.8, 1, 0.5, "true",
                                      0, out hv_Row1, out hv_Column1, out hv_Angle, out hv_Score);
            ho_Rectangle1.Dispose();
            HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Phi + hv_Angle,
                                       hv_Length1, hv_Length2);
            ho_ImageReduced1.Dispose();
            HOperatorSet.ReduceDomain(Image, ho_Rectangle1, out ho_ImageReduced1);
            ho_Border.Dispose();
            HOperatorSet.ThresholdSubPix(ho_ImageReduced1, out ho_Border, thv);
            ho_ContoursSplit.Dispose();
            HOperatorSet.SegmentContoursXld(ho_Border, out ho_ContoursSplit, "lines_circles",
                                            5, 10, 10);
            HOperatorSet.FitLineContourXld(ho_ContoursSplit, "tukey", -1, 0, 5, 2, out hv_RowBegin,
                                           out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc, out hv_Dist);
            HOperatorSet.SelectLinesLongest(hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd,
                                            2, out hv_RowBeginOut, out hv_ColBeginOut, out hv_RowEndOut, out hv_ColEndOut);
            HOperatorSet.AngleLl(hv_RowBeginOut.TupleSelect(0), hv_ColBeginOut.TupleSelect(0),
                                 hv_RowEndOut.TupleSelect(0), hv_ColEndOut.TupleSelect(0), hv_RowBeginOut.TupleSelect(
                                     1), hv_ColBeginOut.TupleSelect(1), hv_RowEndOut.TupleSelect(1), hv_ColEndOut.TupleSelect(
                                     1), out hv_Angle1);
            ho_RegionLines.Dispose();
            HOperatorSet.GenRegionLine(out ho_RegionLines, hv_RowBeginOut, hv_ColBeginOut,
                                       hv_RowEndOut, hv_ColEndOut);
            HOperatorSet.Union2(ho_RegionLines, ho_RegionLines, out RegionToDisp);
            hv_jiaodu = ((hv_Angle1.TupleDeg())).TupleAbs();
            HTuple hv_result = GetHv_result();

            hv_result = hv_result.TupleConcat("夹角");
            hv_result = hv_result.TupleConcat(hv_jiaodu.D);
            result    = hv_result.Clone();
            ho_Rectangle1.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Border.Dispose();
            ho_ContoursSplit.Dispose();
            ho_RegionLines.Dispose();
        }
Exemplo n.º 5
0
 public void updateRow1(HTuple mRow, HTuple mCol)
 {
     if (mRow.TupleLength() == mCol.TupleLength() && mRow.TupleLength() > 2)
     {
         this.row1 = null;
         this.col1 = null;
         this.row1 = new HTuple();
         this.col1 = new HTuple();
         this.row1 = mRow.Clone();
         this.col1 = mCol.Clone();
         this.updateRow2();
     }
 }
Exemplo n.º 6
0
    // Procedures
    public void PaintGrayOffset(HObject ho_ImageSource, HObject ho_ImageDestination,
                                out HObject ho_MixedImage, HTuple hv_OffsetRow, HTuple hv_OffsetColumn)
    {
        // Local iconic variables

        HObject ho_Images;

        // Local control variables

        HTuple hv_SourceWidth = null, hv_SourceHeight = null;
        HTuple hv_DestinationWidth = null, hv_DestinationHeight = null;
        HTuple hv_OffsetCol = null, hv_Row1 = null, hv_Col1 = null;
        HTuple hv_Row2 = null, hv_Col2 = null;
        HTuple hv_OffsetRow_COPY_INP_TMP = hv_OffsetRow.Clone();

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_MixedImage);
        HOperatorSet.GenEmptyObj(out ho_Images);
        HOperatorSet.GetImageSize(ho_ImageSource, out hv_SourceWidth, out hv_SourceHeight);
        HOperatorSet.GetImageSize(ho_ImageDestination, out hv_DestinationWidth, out hv_DestinationHeight);

        ho_Images.Dispose();
        HOperatorSet.ConcatObj(ho_ImageDestination, ho_ImageSource, out ho_Images);

        hv_OffsetRow_COPY_INP_TMP = (new HTuple(0)).TupleConcat(hv_OffsetRow_COPY_INP_TMP);
        hv_OffsetCol    = new HTuple();
        hv_OffsetCol[0] = 0;
        hv_OffsetCol    = hv_OffsetCol.TupleConcat(hv_OffsetColumn);
        hv_Row1         = new HTuple();
        hv_Row1[0]      = 0;
        hv_Row1[1]      = 0;
        hv_Col1         = new HTuple();
        hv_Col1[0]      = 0;
        hv_Col1[1]      = 0;
        hv_Row2         = new HTuple();
        hv_Row2         = hv_Row2.TupleConcat(hv_DestinationHeight);
        hv_Row2         = hv_Row2.TupleConcat(hv_SourceHeight);
        hv_Col2         = new HTuple();
        hv_Col2         = hv_Col2.TupleConcat(hv_DestinationWidth);
        hv_Col2         = hv_Col2.TupleConcat(hv_SourceWidth);

        ho_MixedImage.Dispose();
        HOperatorSet.TileImagesOffset(ho_Images, out ho_MixedImage, hv_OffsetRow_COPY_INP_TMP,
                                      hv_OffsetCol, hv_Row1, hv_Col1, hv_Row2, hv_Col2, hv_DestinationWidth, hv_DestinationHeight);

        ho_Images.Dispose();

        return;
    }
Exemplo n.º 7
0
    public void abshear_wait_for_mouse_click(HTuple hv_continueAcquisition, HTuple hv_WindowHandle)
    {
        // Local iconic variables

        // Local control variables

        HTuple hv_Button = null, hv_dummy = null;
        HTuple hv_continueAcquisition_COPY_INP_TMP = hv_continueAcquisition.Clone();

        // Initialize local and output iconic variables
        hv_Button = 0;
        HOperatorSet.GetMbutton(hv_WindowHandle, out hv_dummy, out hv_dummy, out hv_Button);
        hv_continueAcquisition_COPY_INP_TMP = 0;

        return;
    }
    // Procedures
    public void ChangeDomainForRectangle(HObject ho_InputImage, out HObject ho_ImageResult,
                                         HTuple hv_LineStartPoint_Row, HTuple hv_LineStartPoint_Column, HTuple hv_LineEndPoint_Row,
                                         HTuple hv_LineEndPoint_Column, HTuple hv_RoiWidthLen, HTuple hv_DilationWidth,
                                         HTuple hv_DilationHeight)
    {
        // Local iconic variables

        HObject ho_Rectangle, ho_RegionDilation;


        // Local control variables

        HTuple hv_TmpCtrl_Row = null, hv_TmpCtrl_Column = null;
        HTuple hv_TmpCtrl_Dr = null, hv_TmpCtrl_Dc = null, hv_TmpCtrl_Phi = null;
        HTuple hv_TmpCtrl_Len1 = null, hv_TmpCtrl_Len2 = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_ImageResult);
        HOperatorSet.GenEmptyObj(out ho_Rectangle);
        HOperatorSet.GenEmptyObj(out ho_RegionDilation);

        //Measure 01: Convert coordinates to rectangle2 type
        hv_TmpCtrl_Row    = 0.5 * (hv_LineStartPoint_Row + hv_LineEndPoint_Row);
        hv_TmpCtrl_Column = 0.5 * (hv_LineStartPoint_Column + hv_LineEndPoint_Column);
        hv_TmpCtrl_Dr     = hv_LineStartPoint_Row - hv_LineEndPoint_Row;
        hv_TmpCtrl_Dc     = hv_LineEndPoint_Column - hv_LineStartPoint_Column;
        hv_TmpCtrl_Phi    = hv_TmpCtrl_Dr.TupleAtan2(hv_TmpCtrl_Dc);
        hv_TmpCtrl_Len1   = 0.5 * ((((hv_TmpCtrl_Dr * hv_TmpCtrl_Dr) + (hv_TmpCtrl_Dc * hv_TmpCtrl_Dc))).TupleSqrt()
                                   );
        hv_TmpCtrl_Len2 = hv_RoiWidthLen.Clone();
        ho_Rectangle.Dispose();
        HOperatorSet.GenRectangle2(out ho_Rectangle, hv_TmpCtrl_Row, hv_TmpCtrl_Column,
                                   hv_TmpCtrl_Phi, hv_TmpCtrl_Len1, hv_TmpCtrl_Len2);

        ho_RegionDilation.Dispose();
        HOperatorSet.DilationRectangle1(ho_Rectangle, out ho_RegionDilation, hv_DilationWidth,
                                        hv_DilationHeight);

        ho_ImageResult.Dispose();
        HOperatorSet.ChangeDomain(ho_InputImage, ho_RegionDilation, out ho_ImageResult
                                  );

        ho_Rectangle.Dispose();
        ho_RegionDilation.Dispose();

        return;
    }
Exemplo n.º 9
0
        public static void dispImage(HWindowControl hWC, HObject HImage)
        {
            HTuple hv_Width = null, hv_Height = null, hv_picWHRatio = null;
            HTuple hv_winWHRatio = null, hv_dispWidth = new HTuple();
            HTuple hv_dispHeight = new HTuple();
            // Initialize local and output iconic variables

            HTuple hv_winWidth = hWC.Width; HTuple hv_winHeight = hWC.Height;

            HOperatorSet.SetSystem("int_zooming", "true");
            HOperatorSet.GetImageSize(HImage, out hv_Width, out hv_Height);
            hv_picWHRatio = (1.0 * hv_Width) / hv_Height;
            hv_winWHRatio = (1.0 * hv_winWidth) / hv_winHeight;
            if (new HTuple(hv_Width.TupleGreater(hv_winWidth)).TupleOr(new HTuple(hv_Height.TupleGreater(
                                                                                      hv_winHeight))) != 0)
            {
                //如果图片宽高比 大于 窗口宽高比
                //则宽度方向顶格
                if (new HTuple(hv_picWHRatio.TupleGreaterEqual(hv_winWHRatio)) != 0)
                {
                    hv_dispWidth  = hv_Width.Clone();
                    hv_dispHeight = hv_Width / hv_winWHRatio;
                    HOperatorSet.SetPart(hWC.HalconWindow, 0, 0, hv_dispHeight, hv_dispWidth);
                    HOperatorSet.DispObj(HImage, hWC.HalconWindow);
                }

                //如果图片宽高比 小于 窗口宽高比
                //则高度方向顶格
                if (new HTuple(hv_picWHRatio.TupleLess(hv_winWHRatio)) == 0)
                {
                    return;
                }
                hv_dispWidth  = hv_Height * hv_winWHRatio;
                hv_dispHeight = hv_Height.Clone();
                HOperatorSet.SetPart(hWC.HalconWindow, 0, 0, hv_dispHeight, hv_dispWidth);
                HOperatorSet.DispObj(HImage, hWC.HalconWindow);
            }
            else
            {
                //如果图片的长和宽都小于窗口,则以图片的原真实尺寸显示
                HOperatorSet.SetPart(hWC.HalconWindow, 0, 0, hv_winWidth, hv_winHeight);
                HOperatorSet.DispObj(HImage, hWC.HalconWindow);
            }

            return;
            ////////////////////////////////////////////////////////////////////////////test-end
        }
Exemplo n.º 10
0
        public bool Init()
        {
            //throw new NotImplementedException();
            // Local iconic variables

            // Local control variables

            HTuple hv_ModelID1 = null, hv_ModelID2 = null;
            HTuple hv_ModelID3 = null, hv_ModelID4 = null;

            // Initialize local and output iconic variables
            //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID1", out hv_ModelID1);
            //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID2", out hv_ModelID2);
            //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID3", out hv_ModelID3);
            HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID4", out hv_ModelID4);
            hv_ModelIDOut = hv_ModelID4.Clone();

            return(true);
        }
        // Main procedure
        private void action()
        {
            // Local iconic variables

            HObject ho_Circle, ho_ImageReduced;
            HObject ho_Region, ho_ConnectedRegions, ho_SelectedRegions;
            HObject ho_Circle1, ho_Circle2, ho_RegionDifference, ho_ImageReduced1;
            HObject ho_Region1, ho_ConnectedRegions1, ho_SelectedRegions1;
            HObject ho_RegionIntersection;

            // Local control variables

            HTuple hv_Row = null, hv_Column = null, hv_Radius = null;
            HTuple hv_Row1 = null, hv_Column1 = null, hv_Radius1 = null;
            HTuple hv_Area = null, hv_Row2 = null, hv_Column2 = null;
            HTuple hv_Number = null, hv_Area1 = null, hv_Row3 = null;
            HTuple hv_Column3 = null, hv_Sorted = null, hv_a = null;
            HTuple hv_b = null, hv_c = null, hv_d = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_Circle2);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.Union1(algorithm.Region, out RegionToDisp);
            try
            {
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, DRow1m, DCol1m, DRadiusm);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Circle, out ho_ImageReduced);
                ho_Region.Dispose();
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 200, 255);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", 30000, 99999000);
                HOperatorSet.SmallestCircle(ho_SelectedRegions, out hv_Row1, out hv_Column1,
                                            out hv_Radius1);
                ho_Circle1.Dispose();
                HOperatorSet.GenCircle(out ho_Circle1, hv_Row1, hv_Column1, hv_Radius1);
                ho_Circle2.Dispose();
                HOperatorSet.GenCircle(out ho_Circle2, hv_Row1, hv_Column1, hv_Radius1 * 0.85);
                ho_RegionDifference.Dispose();
                HOperatorSet.Difference(ho_Circle1, ho_Circle2, out ho_RegionDifference);
                ho_RegionIntersection.Dispose();
                HOperatorSet.Intersection(ho_SelectedRegions, ho_RegionDifference, out ho_RegionIntersection
                                          );
                ho_ConnectedRegions1.Dispose();
                HOperatorSet.Connection(ho_RegionIntersection, out ho_ConnectedRegions1);
                HOperatorSet.AreaCenter(ho_ConnectedRegions1, out hv_Area, out hv_Row2, out hv_Column2);
                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "area",
                                         "and", (hv_Area.TupleMax()) / 3, (hv_Area.TupleMax()) + 1);
                HOperatorSet.CountObj(ho_SelectedRegions1, out hv_Number);
                HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_Area1, out hv_Row3, out hv_Column3);
                HOperatorSet.TupleSort(hv_Area1, out hv_Sorted);
                hv_a = hv_Sorted[0];
                hv_b = hv_Sorted[1];
                hv_c = hv_Sorted[2];
                hv_d = hv_Sorted[3];
                HOperatorSet.Union1(ho_SelectedRegions1, out RegionToDisp);
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("数量");
                hv_result = hv_result.TupleConcat(hv_Number.D);
                hv_result = hv_result.TupleConcat("面积1");
                hv_result = hv_result.TupleConcat(hv_a.D);
                hv_result = hv_result.TupleConcat("面积2");
                hv_result = hv_result.TupleConcat(hv_b.D);
                hv_result = hv_result.TupleConcat("面积3");
                hv_result = hv_result.TupleConcat(hv_c.D);
                hv_result = hv_result.TupleConcat("面积4");
                hv_result = hv_result.TupleConcat(hv_d.D);
                result    = hv_result.Clone();
                ho_Circle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                ho_RegionDifference.Dispose();
                ho_RegionIntersection.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions1.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("面积1");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("面积2");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("面积3");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("面积4");
                hv_result = hv_result.TupleConcat(0);

                result = hv_result.Clone();
                ho_Circle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                ho_RegionDifference.Dispose();
                ho_RegionIntersection.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions1.Dispose();
                algorithm.Region.Dispose();
            }
            finally
            {
                ho_Circle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                ho_RegionDifference.Dispose();
                ho_RegionIntersection.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions1.Dispose();
                algorithm.Region.Dispose();
            }
        }
Exemplo n.º 12
0
    // Chapter: Develop
    // Short Description: Open a new graphics window that preserves the aspect ratio of the given image size.
    public void dev_open_window_fit_size(HTuple hv_Row, HTuple hv_Column, HTuple hv_Width,
                                         HTuple hv_Height, HTuple hv_WidthLimit, HTuple hv_HeightLimit, out HTuple hv_WindowHandle)
    {
        // Local iconic variables

        // Local control variables

        HTuple hv_MinWidth = new HTuple(), hv_MaxWidth = new HTuple();
        HTuple hv_MinHeight = new HTuple(), hv_MaxHeight = new HTuple();
        HTuple hv_ResizeFactor = null, hv_TempWidth = null, hv_TempHeight = null;
        HTuple hv_WindowWidth = new HTuple(), hv_WindowHeight = null;

        // Initialize local and output iconic variables
        hv_WindowHandle = new HTuple();
        //This procedure open a new graphic window
        //such that it fits into the limits specified by WidthLimit
        //and HeightLimit, but also maintains the correct aspect ratio
        //given by Width and Height.
        //
        //If it is impossible to match the minimum and maximum extent requirements
        //at the same time (f.e. if the image is very long but narrow),
        //the maximum value gets a higher priority.
        //
        //Parse input tuple WidthLimit
        if ((int)((new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual(0))).TupleOr(
                      new HTuple(hv_WidthLimit.TupleLess(0)))) != 0)
        {
            hv_MinWidth = 500;
            hv_MaxWidth = 800;
        }
        else if ((int)(new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual(
                                      1))) != 0)
        {
            hv_MinWidth = 0;
            hv_MaxWidth = hv_WidthLimit.Clone();
        }
        else
        {
            hv_MinWidth = hv_WidthLimit[0];
            hv_MaxWidth = hv_WidthLimit[1];
        }
        //Parse input tuple HeightLimit
        if ((int)((new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual(0))).TupleOr(
                      new HTuple(hv_HeightLimit.TupleLess(0)))) != 0)
        {
            hv_MinHeight = 400;
            hv_MaxHeight = 600;
        }
        else if ((int)(new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual(
                                      1))) != 0)
        {
            hv_MinHeight = 0;
            hv_MaxHeight = hv_HeightLimit.Clone();
        }
        else
        {
            hv_MinHeight = hv_HeightLimit[0];
            hv_MaxHeight = hv_HeightLimit[1];
        }
        //
        //Test, if window size has to be changed.
        hv_ResizeFactor = 1;
        //First, expand window to the minimum extents (if necessary).
        if ((int)((new HTuple(hv_MinWidth.TupleGreater(hv_Width))).TupleOr(new HTuple(hv_MinHeight.TupleGreater(
                                                                                          hv_Height)))) != 0)
        {
            hv_ResizeFactor = (((((hv_MinWidth.TupleReal()) / hv_Width)).TupleConcat((hv_MinHeight.TupleReal()
                                                                                      ) / hv_Height))).TupleMax();
        }
        hv_TempWidth  = hv_Width * hv_ResizeFactor;
        hv_TempHeight = hv_Height * hv_ResizeFactor;
        //Then, shrink window to maximum extents (if necessary).
        if ((int)((new HTuple(hv_MaxWidth.TupleLess(hv_TempWidth))).TupleOr(new HTuple(hv_MaxHeight.TupleLess(
                                                                                           hv_TempHeight)))) != 0)
        {
            hv_ResizeFactor = hv_ResizeFactor * ((((((hv_MaxWidth.TupleReal()) / hv_TempWidth)).TupleConcat(
                                                       (hv_MaxHeight.TupleReal()) / hv_TempHeight))).TupleMin());
        }
        hv_WindowWidth  = hv_Width * hv_ResizeFactor;
        hv_WindowHeight = hv_Height * hv_ResizeFactor;
        //Resize window
        //dev_open_window(...);
        HOperatorSet.SetPart(hv_ExpDefaultWinHandle, 0, 0, hv_Height - 1, hv_Width - 1);

        return;
    }
Exemplo n.º 13
0
        public MeasureResult Action()
        {
            #region 輸出結果
            CircleResult mResult = null;
            #endregion

            // Local iconic variables

            HObject ho_R3_Circle = null;
            HObject ho_R3_ROI_Image = null, ho_R3_Region = null, ho_R3_ImageReduced = null;
            HObject ho_R3_Edges = null, ho_R3_ContoursSplit = null, ho_R3_SingleSegment = null;
            HObject ho_R3_ContEllipse = null;

            // Local control variables

            HTuple hv_msgOffsetY, hv_msgOffsetX;
            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol, hv_R3_R;
            HTuple hv_STD_R3_Row = new HTuple(), hv_STD_R3_Col = new HTuple();
            HTuple hv_STD_R3_V_Row = new HTuple(), hv_STD_R3_V_Col = new HTuple();
            HTuple hv_R3_X = new HTuple(), hv_R3_Y = new HTuple(), hv_R3_Pos_Row = new HTuple();
            HTuple hv_R3_Pos_Col = new HTuple(), hv_alpha = new HTuple();
            HTuple hv_R3_low = new HTuple(), hv_R3_high = new HTuple();
            HTuple hv_R3_NumSegments = new HTuple(), hv_NumCircles = new HTuple();
            HTuple hv_Num_Circle_Point = new HTuple(), hv_R3 = new HTuple();
            HTuple hv_i = new HTuple(), hv_Attrib = new HTuple(), hv_R3_Row = new HTuple();
            HTuple hv_R3_Column = new HTuple(), hv_R3_Radius = new HTuple();
            HTuple hv_R3_StartPhi = new HTuple(), hv_R3_EndPhi = new HTuple();
            HTuple hv_R3_PointOrder = new HTuple(), hv_R3_MinDist = new HTuple();
            HTuple hv_R3_MaxDist = new HTuple(), hv_R3_AvgDist = new HTuple();
            HTuple hv_R3_SigmaDist = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_R3_Circle);
            HOperatorSet.GenEmptyObj(out ho_R3_ROI_Image);
            HOperatorSet.GenEmptyObj(out ho_R3_Region);
            HOperatorSet.GenEmptyObj(out ho_R3_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_R3_Edges);
            HOperatorSet.GenEmptyObj(out ho_R3_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_R3_SingleSegment);
            HOperatorSet.GenEmptyObj(out ho_R3_ContEllipse);

            //Measure: SDMS_R3
            //Author: John Hsieh
            //Date: 2012
            //ho_Image.Dispose();
            //HOperatorSet.ReadImage(out ho_Image, "Images/STD.bmp");
            //dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle);
            //// dev_update_off(...); only in hdevelop
            HOperatorSet.SetSystem("border_shape_models", "false");

            //****Message Args
            hv_msgOffsetY = 100;
            hv_msgOffsetX = 100;

            //****Model All
            //HOperatorSet.ReadShapeModel("D:/Projects/Halcon/SDMS/SDMS_Measure/Model/MatchingAll.shm",
            //	out hv_AllModelId);
            //ho_AllModelContours.Dispose();
            //HOperatorSet.GetShapeModelContours(out ho_AllModelContours, hv_AllModelId, 1);
            //HOperatorSet.FindShapeModel(ho_Image, hv_AllModelId, (new HTuple(0)).TupleRad()
            //	, (new HTuple(360)).TupleRad(), 0.5, 1, 0.5, "least_squares", 6, 0.75, out hv_AllModelRow,
            //	out hv_AllModelColumn, out hv_AllModelAngle, out hv_AllModelScore);

            //****Model Args

            //STD 中心點
            hv_STD_Row = 772;
            hv_STD_Col = 1003;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //****Display
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            //*****R3
            hv_R3_R = 29;

            //STD R3_ 位置
            hv_STD_R3_Row = 252;
            hv_STD_R3_Col = 1381;

            //STD 向量 STD_R3_
            hv_STD_R3_V_Row = hv_STD_R3_Row - hv_STD_Row;
            hv_STD_R3_V_Col = hv_STD_R3_Col - hv_STD_Col;

            //R3_X, R3_Y 分量
            hv_R3_X = (hv_STD_R3_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_R3_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                ));
            hv_R3_Y = (hv_STD_R3_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_R3_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                ));

            //目前圖形 R3_ 位置
            hv_R3_Pos_Row = (hv_STD_Row + hv_R3_Y) + hv_OffsetRow;
            hv_R3_Pos_Col = (hv_STD_Col + hv_R3_X) + hv_OffsetCol;

            //** 開始計算
            ho_R3_Circle.Dispose();
            HOperatorSet.GenCircle(out ho_R3_Circle, hv_R3_Pos_Row, hv_R3_Pos_Col, hv_R3_R);
            ho_R3_ROI_Image.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_R3_Circle, out ho_R3_ROI_Image);
            ho_R3_Region.Dispose();
            HOperatorSet.FastThreshold(ho_R3_ROI_Image, out ho_R3_Region, 100, 255, 15);
            ho_R3_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_R3_ROI_Image, ho_R3_Region, out ho_R3_ImageReduced
                );
            //stop ()
            //sobel_fast 具有較寬的選擇範圍,搭配 alpha 參數 (alpha 越大, 容錯範圍大)
            hv_alpha = 0.9;
            hv_R3_low = 20;
            hv_R3_high = 60;
            ho_R3_Edges.Dispose();
            HOperatorSet.EdgesSubPix(ho_R3_ImageReduced, out ho_R3_Edges, "sobel_fast",
                hv_alpha, hv_R3_low, hv_R3_high);
            //stop ()
            //*所有的數值越小,表示容錯範圍大,反之亦然
            ho_R3_ContoursSplit.Dispose();
            HOperatorSet.SegmentContoursXld(ho_R3_Edges, out ho_R3_ContoursSplit, "lines_circles",
                17, 4, 2);
            //Display the results
            //===========================================================
            HOperatorSet.CountObj(ho_R3_ContoursSplit, out hv_R3_NumSegments);
            hv_NumCircles = 0;
            hv_Num_Circle_Point = 0;
            hv_R3 = 999;
            for (hv_i = 1; hv_i.Continue(hv_R3_NumSegments, 1); hv_i = hv_i.TupleAdd(1))
            {
                ho_R3_SingleSegment.Dispose();
                HOperatorSet.SelectObj(ho_R3_ContoursSplit, out ho_R3_SingleSegment, hv_i);
                HOperatorSet.GetContourGlobalAttribXld(ho_R3_SingleSegment, "cont_approx",
                    out hv_Attrib);
                if ((int)(new HTuple(hv_Attrib.TupleEqual(1))) != 0)
                {
                    HOperatorSet.FitCircleContourXld(ho_R3_SingleSegment, "atukey", -1, 2,
                        hv_Num_Circle_Point, 5, 2, out hv_R3_Row, out hv_R3_Column, out hv_R3_Radius,
                        out hv_R3_StartPhi, out hv_R3_EndPhi, out hv_R3_PointOrder);

                    hv_NumCircles = hv_NumCircles + 1;
                    if ((int)(new HTuple(hv_R3.TupleGreater(hv_R3_Radius))) != 0)
                    {
                        hv_R3 = hv_R3_Radius.Clone();
                        mResult = new CircleResult()
                        {
                            Row = new HTuple(hv_R3_Row),
                            Col = new HTuple(hv_R3_Column),
                            Radius = new HTuple(hv_R3_Radius),
                            StartPhi = new HTuple(hv_R3_StartPhi),
                            EndPhi = new HTuple(hv_R3_EndPhi),
                            PointOrder = new HTuple(hv_R3_PointOrder),
                        };
                        //HOperatorSet.SetTposition(hv_WindowHandle, (hv_R3_Pos_Row - hv_msgOffsetY) + 60,
                        //	(hv_R3_Pos_Col + hv_msgOffsetX) - 60);
                        //HOperatorSet.WriteString(hv_WindowHandle, "R3");
                        //stop ()
                    }
                }
            }

            //*****R3 End
            ho_R3_Circle.Dispose();
            ho_R3_ROI_Image.Dispose();
            ho_R3_Region.Dispose();
            ho_R3_ImageReduced.Dispose();
            ho_R3_Edges.Dispose();
            ho_R3_ContoursSplit.Dispose();
            ho_R3_SingleSegment.Dispose();
            ho_R3_ContEllipse.Dispose();

            return mResult;
        }
Exemplo n.º 14
0
    // Chapter: Graphics / Text
    // Short Description: Set font independent of OS
    public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font,
                                 HTuple hv_Bold, HTuple hv_Slant)
    {
        // Local control variables

        HTuple hv_OS, hv_Exception = new HTuple();
        HTuple hv_AllowedFontSizes = new HTuple(), hv_Distances = new HTuple();
        HTuple hv_Indices = new HTuple();

        HTuple hv_Bold_COPY_INP_TMP  = hv_Bold.Clone();
        HTuple hv_Font_COPY_INP_TMP  = hv_Font.Clone();
        HTuple hv_Size_COPY_INP_TMP  = hv_Size.Clone();
        HTuple hv_Slant_COPY_INP_TMP = hv_Slant.Clone();

        // Initialize local and output iconic variables

        //This procedure sets the text font of the current window with
        //the specified attributes.
        //It is assumed that following fonts are installed on the system:
        //Windows: Courier New, Arial Times New Roman
        //Linux: courier, helvetica, times
        //Because fonts are displayed smaller on Linux than on Windows,
        //a scaling factor of 1.25 is used the get comparable results.
        //For Linux, only a limited number of font sizes is supported,
        //to get comparable results, it is recommended to use one of the
        //following sizes: 9, 11, 14, 16, 20, 27
        //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
        //
        //input parameters:
        //WindowHandle: The graphics window for which the font will be set
        //Size: The font size. If Size=-1, the default of 16 is used.
        //Bold: If set to 'true', a bold font is used
        //Slant: If set to 'true', a slanted font is used
        //
        HOperatorSet.GetSystem("operating_system", out hv_OS);
        if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
                      new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0)
        {
            hv_Size_COPY_INP_TMP = 16;
        }
        if ((int)(new HTuple((((hv_OS.TupleStrFirstN(2)).TupleStrLastN(0))).TupleEqual(
                                 "Win"))) != 0)
        {
            //set font on Windows systems
            if ((int)((new HTuple((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(
                                      new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(
                                                                                                                       "courier")))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Courier New";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Arial";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Times New Roman";
            }
            if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = 1;
            }
            else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = 0;
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Bold";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_Slant_COPY_INP_TMP = 1;
            }
            else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Slant_COPY_INP_TMP = 0;
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Slant";
                throw new HalconException(hv_Exception);
            }
            try
            {
                HOperatorSet.SetFont(hv_WindowHandle, ((((((("-" + hv_Font_COPY_INP_TMP) + "-") + hv_Size_COPY_INP_TMP) + "-*-") + hv_Slant_COPY_INP_TMP) + "-*-*-") + hv_Bold_COPY_INP_TMP) + "-");
            }
            // catch (Exception)
            catch (HalconException HDevExpDefaultException1)
            {
                HDevExpDefaultException1.ToHTuple(out hv_Exception);
                throw new HalconException(hv_Exception);
            }
        }
        else
        {
            //set font for UNIX systems
            hv_Size_COPY_INP_TMP   = hv_Size_COPY_INP_TMP * 1.25;
            hv_AllowedFontSizes    = new HTuple();
            hv_AllowedFontSizes[0] = 11;
            hv_AllowedFontSizes[1] = 14;
            hv_AllowedFontSizes[2] = 17;
            hv_AllowedFontSizes[3] = 20;
            hv_AllowedFontSizes[4] = 25;
            hv_AllowedFontSizes[5] = 34;
            if ((int)(new HTuple(((hv_AllowedFontSizes.TupleFind(hv_Size_COPY_INP_TMP))).TupleEqual(
                                     -1))) != 0)
            {
                hv_Distances = ((hv_AllowedFontSizes - hv_Size_COPY_INP_TMP)).TupleAbs();
                HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices);
                hv_Size_COPY_INP_TMP = hv_AllowedFontSizes.TupleSelect(hv_Indices.TupleSelect(
                                                                           0));
            }
            if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(
                                                                                                   "Courier")))) != 0)
            {
                hv_Font_COPY_INP_TMP = "courier";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "helvetica";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "times";
            }
            if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = "bold";
            }
            else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = "medium";
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Bold";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("times"))) != 0)
                {
                    hv_Slant_COPY_INP_TMP = "i";
                }
                else
                {
                    hv_Slant_COPY_INP_TMP = "o";
                }
            }
            else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Slant_COPY_INP_TMP = "r";
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Slant";
                throw new HalconException(hv_Exception);
            }
            try
            {
                HOperatorSet.SetFont(hv_WindowHandle, ((((((("-adobe-" + hv_Font_COPY_INP_TMP) + "-") + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*");
            }
            // catch (Exception)
            catch (HalconException HDevExpDefaultException1)
            {
                HDevExpDefaultException1.ToHTuple(out hv_Exception);
                throw new HalconException(hv_Exception);
            }
        }

        return;
    }
Exemplo n.º 15
0
        private static void scale_image_range(HObject ho_Image, out HObject ho_ImageScaled, HTuple hv_Min,
                                              HTuple hv_Max)
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];

            // Local iconic variables

            HObject ho_SelectedChannel = null, ho_LowerRegion = null;
            HObject ho_UpperRegion = null;

            // Local copy input parameter variables
            HObject ho_Image_COPY_INP_TMP;

            ho_Image_COPY_INP_TMP = ho_Image.CopyObj(1, -1);



            // Local control variables

            HTuple hv_LowerLimit = new HTuple(), hv_UpperLimit = new HTuple();
            HTuple hv_Mult = null, hv_Add = null, hv_Channels = null;
            HTuple hv_Index = null, hv_MinGray = new HTuple(), hv_MaxGray = new HTuple();
            HTuple hv_Range            = new HTuple();
            HTuple hv_Max_COPY_INP_TMP = hv_Max.Clone();
            HTuple hv_Min_COPY_INP_TMP = hv_Min.Clone();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_ImageScaled);
            HOperatorSet.GenEmptyObj(out ho_SelectedChannel);
            HOperatorSet.GenEmptyObj(out ho_LowerRegion);
            HOperatorSet.GenEmptyObj(out ho_UpperRegion);
            //Convenience procedure to scale the gray values of the
            //input image Image from the interval [Min,Max]
            //to the interval [0,255] (default).
            //Gray values < 0 or > 255 (after scaling) are clipped.
            //
            //If the image shall be scaled to an interval different from [0,255],
            //this can be achieved by passing tuples with 2 values [From, To]
            //as Min and Max.
            //Example:
            //scale_image_range(Image:ImageScaled:[100,50],[200,250])
            //maps the gray values of Image from the interval [100,200] to [50,250].
            //All other gray values will be clipped.
            //
            //input parameters:
            //Image: the input image
            //Min: the minimum gray value which will be mapped to 0
            //     If a tuple with two values is given, the first value will
            //     be mapped to the second value.
            //Max: The maximum gray value which will be mapped to 255
            //     If a tuple with two values is given, the first value will
            //     be mapped to the second value.
            //
            //output parameter:
            //ImageScale: the resulting scaled image
            //
            if ((int)(new HTuple((new HTuple(hv_Min_COPY_INP_TMP.TupleLength())).TupleEqual(
                                     2))) != 0)
            {
                hv_LowerLimit       = hv_Min_COPY_INP_TMP[1];
                hv_Min_COPY_INP_TMP = hv_Min_COPY_INP_TMP[0];
            }
            else
            {
                hv_LowerLimit = 0.0;
            }
            if ((int)(new HTuple((new HTuple(hv_Max_COPY_INP_TMP.TupleLength())).TupleEqual(
                                     2))) != 0)
            {
                hv_UpperLimit       = hv_Max_COPY_INP_TMP[1];
                hv_Max_COPY_INP_TMP = hv_Max_COPY_INP_TMP[0];
            }
            else
            {
                hv_UpperLimit = 255.0;
            }
            //
            //Calculate scaling parameters
            hv_Mult = (((hv_UpperLimit - hv_LowerLimit)).TupleReal()) / (hv_Max_COPY_INP_TMP - hv_Min_COPY_INP_TMP);
            hv_Add  = ((-hv_Mult) * hv_Min_COPY_INP_TMP) + hv_LowerLimit;
            //
            //Scale image
            {
                HObject ExpTmpOutVar_0;
                HOperatorSet.ScaleImage(ho_Image_COPY_INP_TMP, out ExpTmpOutVar_0, hv_Mult, hv_Add);
                ho_Image_COPY_INP_TMP.Dispose();
                ho_Image_COPY_INP_TMP = ExpTmpOutVar_0;
            }
            //
            //Clip gray values if necessary
            //This must be done for each channel separately
            HOperatorSet.CountChannels(ho_Image_COPY_INP_TMP, out hv_Channels);
            HTuple end_val48  = hv_Channels;
            HTuple step_val48 = 1;

            for (hv_Index = 1; hv_Index.Continue(end_val48, step_val48); hv_Index = hv_Index.TupleAdd(step_val48))
            {
                ho_SelectedChannel.Dispose();
                HOperatorSet.AccessChannel(ho_Image_COPY_INP_TMP, out ho_SelectedChannel, hv_Index);
                HOperatorSet.MinMaxGray(ho_SelectedChannel, ho_SelectedChannel, 0, out hv_MinGray,
                                        out hv_MaxGray, out hv_Range);
                ho_LowerRegion.Dispose();
                HOperatorSet.Threshold(ho_SelectedChannel, out ho_LowerRegion, ((hv_MinGray.TupleConcat(
                                                                                     hv_LowerLimit))).TupleMin(), hv_LowerLimit);
                ho_UpperRegion.Dispose();
                HOperatorSet.Threshold(ho_SelectedChannel, out ho_UpperRegion, hv_UpperLimit,
                                       ((hv_UpperLimit.TupleConcat(hv_MaxGray))).TupleMax());
                {
                    HObject ExpTmpOutVar_0;
                    HOperatorSet.PaintRegion(ho_LowerRegion, ho_SelectedChannel, out ExpTmpOutVar_0,
                                             hv_LowerLimit, "fill");
                    ho_SelectedChannel.Dispose();
                    ho_SelectedChannel = ExpTmpOutVar_0;
                }
                {
                    HObject ExpTmpOutVar_0;
                    HOperatorSet.PaintRegion(ho_UpperRegion, ho_SelectedChannel, out ExpTmpOutVar_0,
                                             hv_UpperLimit, "fill");
                    ho_SelectedChannel.Dispose();
                    ho_SelectedChannel = ExpTmpOutVar_0;
                }
                if ((int)(new HTuple(hv_Index.TupleEqual(1))) != 0)
                {
                    ho_ImageScaled.Dispose();
                    HOperatorSet.CopyObj(ho_SelectedChannel, out ho_ImageScaled, 1, 1);
                }
                else
                {
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.AppendChannel(ho_ImageScaled, ho_SelectedChannel, out ExpTmpOutVar_0
                                                   );
                        ho_ImageScaled.Dispose();
                        ho_ImageScaled = ExpTmpOutVar_0;
                    }
                }
            }
            ho_Image_COPY_INP_TMP.Dispose();
            ho_SelectedChannel.Dispose();
            ho_LowerRegion.Dispose();
            ho_UpperRegion.Dispose();

            return;
        }
Exemplo n.º 16
0
        public void detectNoWire(HObject ho_GrayImage, out HObject ho_Contours, out HObject ho_SelectedRegions,
                                 HTuple hv_Row, HTuple hv_Column, out HTuple hv_string, out HTuple hv_flag)
        {
            // Local iconic variables

            HObject ho_Rectangle_FoV, ho_ImageReduced_Fov;
            HObject ho_Characters, ho_ConnectedRegions, ho_RegionUnion;

            // Local control variables

            HTuple hv_Row_st = null, hv_Col_st = null;
            HTuple hv_Threshold = null, hv_Area = null, hv_Row3 = null;
            HTuple hv_Column3 = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_Rectangle_FoV);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced_Fov);
            HOperatorSet.GenEmptyObj(out ho_Characters);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            hv_string = "";
            hv_flag   = 0;
            hv_Row_st = hv_Row.Clone();
            hv_Col_st = hv_Column.Clone();
            ho_Rectangle_FoV.Dispose();
            HOperatorSet.GenRectangle1(out ho_Rectangle_FoV, hv_Row_st - 20, hv_Col_st - 20,
                                       hv_Row_st + 90, hv_Col_st + 70);
            ho_ImageReduced_Fov.Dispose();
            HOperatorSet.ReduceDomain(ho_GrayImage, ho_Rectangle_FoV, out ho_ImageReduced_Fov
                                      );
            //detect No Wire
            ho_Characters.Dispose();
            HOperatorSet.CharThreshold(ho_ImageReduced_Fov, ho_Rectangle_FoV, out ho_Characters,
                                       2, 90, out hv_Threshold);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_Characters, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", 50, 99999);
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);

            HOperatorSet.AreaCenter(ho_RegionUnion, out hv_Area, out hv_Row3, out hv_Column3);

            if ((int)(new HTuple(hv_Area.TupleLess(200))) != 0)
            {
                ho_Contours.Dispose();
                HOperatorSet.GenContourRegionXld(ho_Rectangle_FoV, out ho_Contours, "border");
                hv_string = "No Wire";
                hv_flag   = 3;

                //flag=3:NoWire
            }
            else
            {
                hv_flag = 1;
            }


            ho_Rectangle_FoV.Dispose();
            ho_ImageReduced_Fov.Dispose();
            ho_Characters.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_RegionUnion.Dispose();

            return;
        }
Exemplo n.º 17
0
        //}
        public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
                                 HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
        {
            // Local iconic variables

            // Local control variables

            HTuple hv_Red = null, hv_Green = null, hv_Blue = null;
            HTuple hv_Row1Part = null, hv_Column1Part = null, hv_Row2Part = null;
            HTuple hv_Column2Part = null, hv_RowWin = null, hv_ColumnWin = null;
            HTuple hv_WidthWin = null, hv_HeightWin = null, hv_MaxAscent = null;
            HTuple hv_MaxDescent = null, hv_MaxWidth = null, hv_MaxHeight = null;
            HTuple hv_R1 = new HTuple(), hv_C1 = new HTuple(), hv_FactorRow = new HTuple();
            HTuple hv_FactorColumn = new HTuple(), hv_UseShadow = null;
            HTuple hv_ShadowColor = null, hv_Exception = new HTuple();
            HTuple hv_Width = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Ascent = new HTuple(), hv_Descent = new HTuple();
            HTuple hv_W = new HTuple(), hv_H = new HTuple(), hv_FrameHeight = new HTuple();
            HTuple hv_FrameWidth = new HTuple(), hv_R2 = new HTuple();
            HTuple hv_C2 = new HTuple(), hv_DrawMode = new HTuple();
            HTuple hv_CurrentColor        = new HTuple();
            HTuple hv_Box_COPY_INP_TMP    = hv_Box.Clone();
            HTuple hv_Color_COPY_INP_TMP  = hv_Color.Clone();
            HTuple hv_Column_COPY_INP_TMP = hv_Column.Clone();
            HTuple hv_Row_COPY_INP_TMP    = hv_Row.Clone();
            HTuple hv_String_COPY_INP_TMP = hv_String.Clone();

            // Initialize local and output iconic variables
            //This procedure displays text in a graphics window.
            //
            //Input parameters:
            //WindowHandle: The WindowHandle of the graphics window, where
            //   the message should be displayed
            //String: A tuple of strings containing the text message to be displayed
            //CoordSystem: If set to 'window', the text position is given
            //   with respect to the window coordinate system.
            //   If set to 'image', image coordinates are used.
            //   (This may be useful in zoomed images.)
            //Row: The row coordinate of the desired text position
            //   If set to -1, a default value of 12 is used.
            //Column: The column coordinate of the desired text position
            //   If set to -1, a default value of 12 is used.
            //Color: defines the color of the text as string.
            //   If set to [], '' or 'auto' the currently set color is used.
            //   If a tuple of strings is passed, the colors are used cyclically
            //   for each new textline.
            //Box: If Box[0] is set to 'true', the text is written within an orange box.
            //     If set to' false', no box is displayed.
            //     If set to a color string (e.g. 'white', '#FF00CC', etc.),
            //       the text is written in a box of that color.
            //     An optional second value for Box (Box[1]) controls if a shadow is displayed:
            //       'true' -> display a shadow in a default color
            //       'false' -> display no shadow (same as if no second value is given)
            //       otherwise -> use given string as color string for the shadow color
            //
            //Prepare window
            HOperatorSet.GetRgb(hv_WindowHandle, out hv_Red, out hv_Green, out hv_Blue);
            HOperatorSet.GetPart(hv_WindowHandle, out hv_Row1Part, out hv_Column1Part, out hv_Row2Part,
                                 out hv_Column2Part);
            HOperatorSet.GetWindowExtents(hv_WindowHandle, out hv_RowWin, out hv_ColumnWin,
                                          out hv_WidthWin, out hv_HeightWin);
            HOperatorSet.SetPart(hv_WindowHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1);
            //
            //default settings
            if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0)
            {
                hv_Row_COPY_INP_TMP = 12;
            }
            if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0)
            {
                hv_Column_COPY_INP_TMP = 12;
            }
            if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0)
            {
                hv_Color_COPY_INP_TMP = "";
            }
            //
            hv_String_COPY_INP_TMP = ((("" + hv_String_COPY_INP_TMP) + "")).TupleSplit("\n");
            //
            //Estimate extentions of text depending on font size.
            HOperatorSet.GetFontExtents(hv_WindowHandle, out hv_MaxAscent, out hv_MaxDescent,
                                        out hv_MaxWidth, out hv_MaxHeight);
            if ((int)(new HTuple(hv_CoordSystem.TupleEqual("window"))) != 0)
            {
                hv_R1 = hv_Row_COPY_INP_TMP.Clone();
                hv_C1 = hv_Column_COPY_INP_TMP.Clone();
            }
            else
            {
                //Transform image to window coordinates
                hv_FactorRow    = (1.0 * hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1);
                hv_FactorColumn = (1.0 * hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1);
                hv_R1           = ((hv_Row_COPY_INP_TMP - hv_Row1Part) + 0.5) * hv_FactorRow;
                hv_C1           = ((hv_Column_COPY_INP_TMP - hv_Column1Part) + 0.5) * hv_FactorColumn;
            }
            //
            //Display text box depending on text size
            hv_UseShadow   = 1;
            hv_ShadowColor = "gray";
            if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(0))).TupleEqual("true"))) != 0)
            {
                if (hv_Box_COPY_INP_TMP == null)
                {
                    hv_Box_COPY_INP_TMP = new HTuple();
                }
                hv_Box_COPY_INP_TMP[0] = "#fce9d4";
                hv_ShadowColor         = "#f28d26";
            }
            if ((int)(new HTuple((new HTuple(hv_Box_COPY_INP_TMP.TupleLength())).TupleGreater(
                                     1))) != 0)
            {
                if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(1))).TupleEqual("true"))) != 0)
                {
                    //Use default ShadowColor set above
                }
                else if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(1))).TupleEqual(
                                              "false"))) != 0)
                {
                    hv_UseShadow = 0;
                }
                else
                {
                    hv_ShadowColor = hv_Box_COPY_INP_TMP[1];
                    //Valid color?
                    try
                    {
                        HOperatorSet.SetColor(hv_WindowHandle, hv_Box_COPY_INP_TMP.TupleSelect(
                                                  1));
                    }
                    // catch (Exception)
                    catch (HalconException HDevExpDefaultException1)
                    {
                        HDevExpDefaultException1.ToHTuple(out hv_Exception);
                        hv_Exception = "Wrong value of control parameter Box[1] (must be a 'true', 'false', or a valid color string)";
                        throw new HalconException(hv_Exception);
                    }
                }
            }
            if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(0))).TupleNotEqual("false"))) != 0)
            {
                //Valid color?
                try
                {
                    HOperatorSet.SetColor(hv_WindowHandle, hv_Box_COPY_INP_TMP.TupleSelect(0));
                }
                // catch (Exception)
                catch (HalconException HDevExpDefaultException1)
                {
                    HDevExpDefaultException1.ToHTuple(out hv_Exception);
                    hv_Exception = "Wrong value of control parameter Box[0] (must be a 'true', 'false', or a valid color string)";
                    throw new HalconException(hv_Exception);
                }
                //Calculate box extents
                hv_String_COPY_INP_TMP = (" " + hv_String_COPY_INP_TMP) + " ";
                hv_Width = new HTuple();
                for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                                      )) - 1); hv_Index = (int)hv_Index + 1)
                {
                    HOperatorSet.GetStringExtents(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect(
                                                      hv_Index), out hv_Ascent, out hv_Descent, out hv_W, out hv_H);
                    hv_Width = hv_Width.TupleConcat(hv_W);
                }
                hv_FrameHeight = hv_MaxHeight * (new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                            ));
                hv_FrameWidth = (((new HTuple(0)).TupleConcat(hv_Width))).TupleMax();
                hv_R2         = hv_R1 + hv_FrameHeight;
                hv_C2         = hv_C1 + hv_FrameWidth;
                //Display rectangles
                HOperatorSet.GetDraw(hv_WindowHandle, out hv_DrawMode);
                HOperatorSet.SetDraw(hv_WindowHandle, "fill");
                //Set shadow color
                HOperatorSet.SetColor(hv_WindowHandle, hv_ShadowColor);
                if ((int)(hv_UseShadow) != 0)
                {
                    HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1 + 1, hv_C1 + 1, hv_R2 + 1, hv_C2 + 1);
                }
                //Set box color
                HOperatorSet.SetColor(hv_WindowHandle, hv_Box_COPY_INP_TMP.TupleSelect(0));
                HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2);
                HOperatorSet.SetDraw(hv_WindowHandle, hv_DrawMode);
            }
            //Write text.
            for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                                  )) - 1); hv_Index = (int)hv_Index + 1)
            {
                hv_CurrentColor = hv_Color_COPY_INP_TMP.TupleSelect(hv_Index % (new HTuple(hv_Color_COPY_INP_TMP.TupleLength()
                                                                                           )));
                if ((int)((new HTuple(hv_CurrentColor.TupleNotEqual(""))).TupleAnd(new HTuple(hv_CurrentColor.TupleNotEqual(
                                                                                                  "auto")))) != 0)
                {
                    HOperatorSet.SetColor(hv_WindowHandle, hv_CurrentColor);
                }
                else
                {
                    HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
                }
                hv_Row_COPY_INP_TMP = hv_R1 + (hv_MaxHeight * hv_Index);
                HOperatorSet.SetTposition(hv_WindowHandle, hv_Row_COPY_INP_TMP, hv_C1);
                HOperatorSet.WriteString(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect(
                                             hv_Index));
            }
            //Reset changed window settings
            HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
            HOperatorSet.SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part,
                                 hv_Column2Part);

            return;
        }
Exemplo n.º 18
0
        public void FitCicrle(HObject ho_Image, HTuple hv_WindowHandle, HTuple hv_CircleRow,
                              HTuple hv_CircleColumn, HTuple hv_CircleRadius, HTuple hv_RectRow, HTuple hv_RectColumn,
                              HTuple hv_RectPhi, HTuple hv_RectLength1, HTuple hv_RectLength2, HTuple hv_Transition,
                              HTuple hv_Sigma, HTuple hv_Threshold, out HTuple hv_CenterRow, out HTuple hv_CenterColumn,
                              out HTuple hv_CenterRaduis, out HTuple hv_StartPhi, out HTuple hv_EndPhi, out HTuple hv_Circularity)
        {
            // Local iconic variables

            HObject ho_Rectangle, ho_Contour;

            // Local control variables

            HTuple hv_Width = null, hv_Height = null, hv_sr = null;
            HTuple hv_sc = null, hv_lenth1 = null, hv_lenth2 = null;
            HTuple hv_val = null, hv_PointNum = null, hv_mr = null;
            HTuple hv_mc = null, hv_ag = null, hv_i = null, hv_lr = null;
            HTuple hv_lc = null, hv_j = null, hv_MeasureHandle = new HTuple();
            HTuple hv_RowEdge = new HTuple(), hv_ColumnEdge = new HTuple();
            HTuple hv_Amplitude = new HTuple(), hv_Distance = new HTuple();
            HTuple hv_RowEdgeCount = new HTuple(), hv_RowEdgeVal = new HTuple();
            HTuple hv_Indices = new HTuple(), hv_RowEdgeValMin = new HTuple();
            HTuple hv_rc = null, hv_zr = null, hv_zc = null, hv_PointOrder = null;
            HTuple hv_CircleColumn_COPY_INP_TMP = hv_CircleColumn.Clone();
            HTuple hv_CircleRow_COPY_INP_TMP    = hv_CircleRow.Clone();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            hv_CenterRow    = new HTuple();
            hv_CenterColumn = new HTuple();
            hv_CenterRaduis = new HTuple();
            hv_StartPhi     = new HTuple();
            hv_EndPhi       = new HTuple();
            hv_Circularity  = new HTuple();
            try
            {
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
                }
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                }
                HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
                //
                //tuple_deg (RectPhi, Deg)
                //
                //gen_circle_contour_xld (ContCircle, CircleRow, CircleColumn, CircleRadius, 0, 6.28318/2, 'positive', 1)
                //
                hv_sr = hv_CircleRow_COPY_INP_TMP - hv_CircleRadius;
                hv_sc = hv_CircleColumn_COPY_INP_TMP.Clone();
                //
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
                }
                //
                hv_lenth1 = hv_CircleRadius / 2.5;
                hv_lenth2 = hv_CircleRadius / 8;
                //lenth1 := RectLength1
                //lenth2 := RectLength2
                hv_val      = 5;
                hv_PointNum = (6.28318 * hv_CircleRadius) / ((hv_lenth2 + hv_val) * 2);
                //
                hv_mr = hv_sr.Clone();
                hv_mc = hv_sc.Clone();
                //
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_mr, hv_mc, (new HTuple(0 + 90)).TupleRad()
                                           , hv_lenth1, hv_lenth2);
                //
                hv_ag = 10;
                //
                HOperatorSet.DispImage(ho_Image, 3600);
                //tuple_rad (ag, rd)
                //
                HTuple end_val30  = 360 / hv_ag;
                HTuple step_val30 = 1;
                for (hv_i = 0; hv_i.Continue(end_val30, step_val30); hv_i = hv_i.TupleAdd(step_val30))
                {
                    hv_mr = hv_sr + (hv_CircleRadius * (1 - ((((hv_ag.TupleRad()) * hv_i)).TupleCos()
                                                             )));
                    hv_mc = hv_sc - (hv_CircleRadius * ((((hv_ag.TupleRad()) * hv_i)).TupleSin()));
                    ho_Rectangle.Dispose();
                    HOperatorSet.GenRectangle2(out ho_Rectangle, hv_mr, hv_mc, (((hv_ag * hv_i) + 90)).TupleRad()
                                               , hv_lenth1, hv_lenth2);
                }
                //
                //stop ()
                //
                hv_lr = new HTuple();
                hv_lc = new HTuple();
                //
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
                }
                hv_j = 0;
                if (HDevWindowStack.IsOpen())
                {
                    //dev_set_draw ('fill')
                }
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 1);
                }
                //
                HTuple end_val46  = 360 / hv_ag;
                HTuple step_val46 = 1;
                for (hv_i = 0; hv_i.Continue(end_val46, step_val46); hv_i = hv_i.TupleAdd(step_val46))
                {
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                    }
                    //
                    hv_mr = hv_sr + (hv_CircleRadius * (1 - ((((hv_ag.TupleRad()) * hv_i)).TupleCos()
                                                             )));
                    hv_mc = hv_sc - (hv_CircleRadius * ((((hv_ag.TupleRad()) * hv_i)).TupleSin()));
                    //
                    ho_Rectangle.Dispose();
                    HOperatorSet.GenRectangle2(out ho_Rectangle, hv_mr, hv_mc, (((hv_ag * hv_i) + 90)).TupleRad()
                                               , hv_lenth1, hv_lenth2);
                    //
                    HOperatorSet.GenMeasureRectangle2(hv_mr, hv_mc, (((hv_ag * hv_i) + 90)).TupleRad()
                                                      , hv_lenth1, hv_lenth2, hv_Width, hv_Height, "nearest_neighbor", out hv_MeasureHandle);
                    //Transition = 'positive' :dark-to-light;  Transition = 'negative': light-to-dark
                    HOperatorSet.MeasurePos(ho_Image, hv_MeasureHandle, hv_Sigma, hv_Threshold,
                                            hv_Transition, "all", out hv_RowEdge, out hv_ColumnEdge, out hv_Amplitude,
                                            out hv_Distance);
                    //
                    if ((int)(new HTuple((new HTuple(hv_RowEdge.TupleLength())).TupleEqual(0))) != 0)
                    {
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
                        }
                        HOperatorSet.DispCross(hv_WindowHandle, hv_mr, hv_mc, 20, (new HTuple(45)).TupleRad()
                                               );
                        //stop ()
                    }
                    else if ((int)(new HTuple((new HTuple(hv_RowEdge.TupleLength())).TupleEqual(
                                                  1))) != 0)
                    {
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                        }
                        HOperatorSet.DispCross(hv_WindowHandle, hv_RowEdge, hv_ColumnEdge, 20,
                                               (new HTuple(45)).TupleRad());
                        if (hv_lr == null)
                        {
                            hv_lr = new HTuple();
                        }
                        hv_lr[hv_j] = hv_RowEdge.TupleSelect(0);
                        if (hv_lc == null)
                        {
                            hv_lc = new HTuple();
                        }
                        hv_lc[hv_j] = hv_ColumnEdge.TupleSelect(0);
                        hv_j        = hv_j + 1;
                    }
                    else if ((int)(new HTuple((new HTuple(hv_RowEdge.TupleLength())).TupleNotEqual(
                                                  1))) != 0)
                    {
                        //By position near DrawLine
                        hv_RowEdgeCount = new HTuple(hv_RowEdge.TupleLength());
                        hv_RowEdgeVal   = hv_RowEdge - hv_mr;
                        HOperatorSet.TupleAbs(hv_RowEdgeVal, out hv_RowEdgeVal);
                        //tuple_sort_index (RowEdgeVal, Indices)
                        HOperatorSet.TupleMin(hv_RowEdgeVal, out hv_RowEdgeValMin);
                        HOperatorSet.TupleFind(hv_RowEdgeVal, hv_RowEdgeValMin, out hv_Indices);
                        if ((int)(new HTuple((new HTuple(hv_Indices.TupleLength())).TupleEqual(
                                                 1))) != 0)
                        {
                            if (hv_lr == null)
                            {
                                hv_lr = new HTuple();
                            }
                            hv_lr[hv_j] = hv_RowEdge.TupleSelect(hv_Indices);
                            if (hv_lc == null)
                            {
                                hv_lc = new HTuple();
                            }
                            hv_lc[hv_j] = hv_ColumnEdge.TupleSelect(hv_Indices);
                        }
                        else
                        {
                            if (hv_lr == null)
                            {
                                hv_lr = new HTuple();
                            }
                            hv_lr[hv_j] = hv_RowEdge.TupleSelect(hv_Indices.TupleSelect(0));
                            if (hv_lc == null)
                            {
                                hv_lc = new HTuple();
                            }
                            hv_lc[hv_j] = hv_ColumnEdge.TupleSelect(hv_Indices.TupleSelect(0));
                        }
                        hv_j = hv_j + 1;
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
                        }
                        HOperatorSet.DispCross(hv_WindowHandle, hv_RowEdge.TupleSelect(hv_Indices),
                                               hv_ColumnEdge.TupleSelect(hv_Indices), 20, (new HTuple(45)).TupleRad()
                                               );
                        //
                        //By Threshold
                    }
                    HOperatorSet.CloseMeasure(hv_MeasureHandle);
                }
                //
                //stop ()
                //
                hv_rc = new HTuple();
                hv_zr = new HTuple();
                hv_zc = new HTuple();
                //
                hv_CircleRow_COPY_INP_TMP    = hv_lr.Clone();
                hv_CircleColumn_COPY_INP_TMP = hv_lc.Clone();
                //
                //
                if ((int)(new HTuple((new HTuple(hv_CircleRow_COPY_INP_TMP.TupleLength())).TupleLess(
                                         4))) != 0)
                {
                    disp_message(hv_WindowHandle, "FitLine Fail", "image", 10, 10, "black", "true");
                    ho_Rectangle.Dispose();
                    ho_Contour.Dispose();

                    return;
                }
                ho_Contour.Dispose();
                HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_CircleRow_COPY_INP_TMP,
                                                  hv_CircleColumn_COPY_INP_TMP);
                //
                HOperatorSet.FitCircleContourXld(ho_Contour, "algebraic", -1, 0, 0, 3, 2, out hv_CenterRow,
                                                 out hv_CenterColumn, out hv_CenterRaduis, out hv_StartPhi, out hv_EndPhi,
                                                 out hv_PointOrder);
                HOperatorSet.CircularityXld(ho_Contour, out hv_Circularity);
                //
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
                }
                HOperatorSet.DispCircle(hv_WindowHandle, hv_CenterRow, hv_CenterColumn, hv_CenterRaduis);
                //
                ho_Rectangle.Dispose();
                ho_Contour.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_Rectangle.Dispose();
                ho_Contour.Dispose();

                throw HDevExpDefaultException;
            }
        }
        public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font,
                                     HTuple hv_Bold, HTuple hv_Slant)
        {
            // Local iconic variables

            // Local control variables

            HTuple hv_OS = null, hv_Fonts = new HTuple();
            HTuple hv_Style = null, hv_Exception = new HTuple(), hv_AvailableFonts = null;
            HTuple hv_Fdx = null, hv_Indices = new HTuple();
            HTuple hv_Font_COPY_INP_TMP = hv_Font.Clone();
            HTuple hv_Size_COPY_INP_TMP = hv_Size.Clone();

            // Initialize local and output iconic variables
            //This procedure sets the text font of the current window with
            //the specified attributes.
            //
            //Input parameters:
            //WindowHandle: The graphics window for which the font will be set
            //Size: The font size. If Size=-1, the default of 16 is used.
            //Bold: If set to 'true', a bold font is used
            //Slant: If set to 'true', a slanted font is used
            //
            HOperatorSet.GetSystem("operating_system", out hv_OS);
            // dev_get_preferences(...); only in hdevelop
            // dev_set_preferences(...); only in hdevelop
            if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
                          new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0)
            {
                hv_Size_COPY_INP_TMP = 16;
            }
            if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0)
            {
                //Restore previous behaviour
                hv_Size_COPY_INP_TMP = ((1.13677 * hv_Size_COPY_INP_TMP)).TupleInt();
            }
            if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "Courier";
                hv_Fonts[1] = "Courier 10 Pitch";
                hv_Fonts[2] = "Courier New";
                hv_Fonts[3] = "CourierNew";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "Consolas";
                hv_Fonts[1] = "Menlo";
                hv_Fonts[2] = "Courier";
                hv_Fonts[3] = "Courier 10 Pitch";
                hv_Fonts[4] = "FreeMono";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "Luxi Sans";
                hv_Fonts[1] = "DejaVu Sans";
                hv_Fonts[2] = "FreeSans";
                hv_Fonts[3] = "Arial";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "Times New Roman";
                hv_Fonts[1] = "Luxi Serif";
                hv_Fonts[2] = "DejaVu Serif";
                hv_Fonts[3] = "FreeSerif";
                hv_Fonts[4] = "Utopia";
            }
            else
            {
                hv_Fonts = hv_Font_COPY_INP_TMP.Clone();
            }
            hv_Style = "";
            if ((int)(new HTuple(hv_Bold.TupleEqual("true"))) != 0)
            {
                hv_Style = hv_Style + "Bold";
            }
            else if ((int)(new HTuple(hv_Bold.TupleNotEqual("false"))) != 0)
            {
                hv_Exception = "Wrong value of control parameter Bold";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Slant.TupleEqual("true"))) != 0)
            {
                hv_Style = hv_Style + "Italic";
            }
            else if ((int)(new HTuple(hv_Slant.TupleNotEqual("false"))) != 0)
            {
                hv_Exception = "Wrong value of control parameter Slant";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Style.TupleEqual(""))) != 0)
            {
                hv_Style = "Normal";
            }
            HOperatorSet.QueryFont(hv_WindowHandle, out hv_AvailableFonts);
            hv_Font_COPY_INP_TMP = "";
            for (hv_Fdx = 0; (int)hv_Fdx <= (int)((new HTuple(hv_Fonts.TupleLength())) - 1); hv_Fdx = (int)hv_Fdx + 1)
            {
                hv_Indices = hv_AvailableFonts.TupleFind(hv_Fonts.TupleSelect(hv_Fdx));
                if ((int)(new HTuple((new HTuple(hv_Indices.TupleLength())).TupleGreater(0))) != 0)
                {
                    if ((int)(new HTuple(((hv_Indices.TupleSelect(0))).TupleGreaterEqual(0))) != 0)
                    {
                        hv_Font_COPY_INP_TMP = hv_Fonts.TupleSelect(hv_Fdx);
                        break;
                    }
                }
            }
            if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(""))) != 0)
            {
                throw new HalconException("Wrong value of control parameter Font");
            }
            hv_Font_COPY_INP_TMP = (((hv_Font_COPY_INP_TMP + "-") + hv_Style) + "-") + hv_Size_COPY_INP_TMP;
            HOperatorSet.SetFont(hv_WindowHandle, hv_Font_COPY_INP_TMP);
            // dev_set_preferences(...); only in hdevelop

            return;
        }
Exemplo n.º 20
0
    public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
                             HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
    {
        // Local iconic variables

        // Local control variables

        HTuple hv_GenParamName = null, hv_GenParamValue = null;
        HTuple hv_Color_COPY_INP_TMP       = hv_Color.Clone();
        HTuple hv_Column_COPY_INP_TMP      = hv_Column.Clone();
        HTuple hv_CoordSystem_COPY_INP_TMP = hv_CoordSystem.Clone();
        HTuple hv_Row_COPY_INP_TMP         = hv_Row.Clone();

        //Convert the parameters for disp_text.
        if ((int)((new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
                      new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(new HTuple())))) != 0)
        {
            return;
        }
        if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0)
        {
            hv_Row_COPY_INP_TMP = 12;
        }
        if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0)
        {
            hv_Column_COPY_INP_TMP = 12;
        }
        //
        //Convert the parameter Box to generic parameters.
        hv_GenParamName  = new HTuple();
        hv_GenParamValue = new HTuple();
        if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(0))) != 0)
        {
            if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleEqual("false"))) != 0)
            {
                //Display no box
                hv_GenParamName  = hv_GenParamName.TupleConcat("box");
                hv_GenParamValue = hv_GenParamValue.TupleConcat("false");
            }
            else if ((int)(new HTuple(((hv_Box.TupleSelect(0))).TupleNotEqual("true"))) != 0)
            {
                //Set a color other than the default.
                hv_GenParamName  = hv_GenParamName.TupleConcat("box_color");
                hv_GenParamValue = hv_GenParamValue.TupleConcat(hv_Box.TupleSelect(0));
            }
        }
        if ((int)(new HTuple((new HTuple(hv_Box.TupleLength())).TupleGreater(1))) != 0)
        {
            if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleEqual("false"))) != 0)
            {
                //Display no shadow.
                hv_GenParamName  = hv_GenParamName.TupleConcat("shadow");
                hv_GenParamValue = hv_GenParamValue.TupleConcat("false");
            }
            else if ((int)(new HTuple(((hv_Box.TupleSelect(1))).TupleNotEqual("true"))) != 0)
            {
                //Set a shadow color other than the default.
                hv_GenParamName  = hv_GenParamName.TupleConcat("shadow_color");
                hv_GenParamValue = hv_GenParamValue.TupleConcat(hv_Box.TupleSelect(1));
            }
        }
        //Restore default CoordSystem behavior.
        if ((int)(new HTuple(hv_CoordSystem_COPY_INP_TMP.TupleNotEqual("window"))) != 0)
        {
            hv_CoordSystem_COPY_INP_TMP = "image";
        }
        //
        if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(""))) != 0)
        {
            //disp_text does not accept an empty string for Color.
            hv_Color_COPY_INP_TMP = new HTuple();
        }
        //
        HOperatorSet.DispText(3600, hv_String, hv_CoordSystem_COPY_INP_TMP,
                              hv_Row_COPY_INP_TMP, hv_Column_COPY_INP_TMP, hv_Color_COPY_INP_TMP, hv_GenParamName,
                              hv_GenParamValue);

        return;
    }
Exemplo n.º 21
0
    // Chapter: Graphics / Text
    // Short Description: This procedure writes a text message.
    public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
                             HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
    {
        // Local control variables

        HTuple hv_Red, hv_Green, hv_Blue, hv_Row1Part;
        HTuple hv_Column1Part, hv_Row2Part, hv_Column2Part, hv_RowWin;
        HTuple hv_ColumnWin, hv_WidthWin, hv_HeightWin, hv_MaxAscent;
        HTuple hv_MaxDescent, hv_MaxWidth, hv_MaxHeight, hv_R1 = new HTuple();
        HTuple hv_C1 = new HTuple(), hv_FactorRow = new HTuple(), hv_FactorColumn = new HTuple();
        HTuple hv_Width = new HTuple(), hv_Index = new HTuple(), hv_Ascent = new HTuple();
        HTuple hv_Descent = new HTuple(), hv_W = new HTuple(), hv_H = new HTuple();
        HTuple hv_FrameHeight = new HTuple(), hv_FrameWidth = new HTuple();
        HTuple hv_R2 = new HTuple(), hv_C2 = new HTuple(), hv_DrawMode = new HTuple();
        HTuple hv_Exception = new HTuple(), hv_CurrentColor = new HTuple();

        HTuple hv_Color_COPY_INP_TMP  = hv_Color.Clone();
        HTuple hv_Column_COPY_INP_TMP = hv_Column.Clone();
        HTuple hv_Row_COPY_INP_TMP    = hv_Row.Clone();
        HTuple hv_String_COPY_INP_TMP = hv_String.Clone();

        // Initialize local and output iconic variables

        //This procedure displays text in a graphics window.
        //
        //Input parameters:
        //WindowHandle: The WindowHandle of the graphics window, where
        //   the message should be displayed
        //String: A tuple of strings containing the text message to be displayed
        //CoordSystem: If set to 'window', the text position is given
        //   with respect to the window coordinate system.
        //   If set to 'image', image coordinates are used.
        //   (This may be useful in zoomed images.)
        //Row: The row coordinate of the desired text position
        //   If set to -1, a default value of 12 is used.
        //Column: The column coordinate of the desired text position
        //   If set to -1, a default value of 12 is used.
        //Color: defines the color of the text as string.
        //   If set to [], '' or 'auto' the currently set color is used.
        //   If a tuple of strings is passed, the colors are used cyclically
        //   for each new textline.
        //Box: If set to 'true', the text is written within a white box.
        //
        //prepare window
        HOperatorSet.GetRgb(hv_WindowHandle, out hv_Red, out hv_Green, out hv_Blue);
        HOperatorSet.GetPart(hv_WindowHandle, out hv_Row1Part, out hv_Column1Part, out hv_Row2Part,
                             out hv_Column2Part);
        HOperatorSet.GetWindowExtents(hv_WindowHandle, out hv_RowWin, out hv_ColumnWin,
                                      out hv_WidthWin, out hv_HeightWin);
        HOperatorSet.SetPart(hv_WindowHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1);
        //
        //default settings
        if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0)
        {
            hv_Row_COPY_INP_TMP = 12;
        }
        if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0)
        {
            hv_Column_COPY_INP_TMP = 12;
        }
        if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0)
        {
            hv_Color_COPY_INP_TMP = "";
        }
        //
        hv_String_COPY_INP_TMP = ((("" + hv_String_COPY_INP_TMP) + "")).TupleSplit("\n");
        //
        //Estimate extentions of text depending on font size.
        HOperatorSet.GetFontExtents(hv_WindowHandle, out hv_MaxAscent, out hv_MaxDescent,
                                    out hv_MaxWidth, out hv_MaxHeight);
        if ((int)(new HTuple(hv_CoordSystem.TupleEqual("window"))) != 0)
        {
            hv_R1 = hv_Row_COPY_INP_TMP.Clone();
            hv_C1 = hv_Column_COPY_INP_TMP.Clone();
        }
        else
        {
            //transform image to window coordinates
            hv_FactorRow    = (1.0 * hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1);
            hv_FactorColumn = (1.0 * hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1);
            hv_R1           = ((hv_Row_COPY_INP_TMP - hv_Row1Part) + 0.5) * hv_FactorRow;
            hv_C1           = ((hv_Column_COPY_INP_TMP - hv_Column1Part) + 0.5) * hv_FactorColumn;
        }
        //
        //display text box depending on text size
        if ((int)(new HTuple(hv_Box.TupleEqual("true"))) != 0)
        {
            //calculate box extents
            hv_String_COPY_INP_TMP = (" " + hv_String_COPY_INP_TMP) + " ";
            hv_Width = new HTuple();
            for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                                  )) - 1); hv_Index = (int)hv_Index + 1)
            {
                HOperatorSet.GetStringExtents(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect(
                                                  hv_Index), out hv_Ascent, out hv_Descent, out hv_W, out hv_H);
                hv_Width = hv_Width.TupleConcat(hv_W);
            }
            hv_FrameHeight = hv_MaxHeight * (new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                        ));
            hv_FrameWidth = (((new HTuple(0)).TupleConcat(hv_Width))).TupleMax();
            hv_R2         = hv_R1 + hv_FrameHeight;
            hv_C2         = hv_C1 + hv_FrameWidth;
            //display rectangles
            HOperatorSet.GetDraw(hv_WindowHandle, out hv_DrawMode);
            HOperatorSet.SetDraw(hv_WindowHandle, "fill");
            HOperatorSet.SetColor(hv_WindowHandle, "light gray");
            HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1 + 3, hv_C1 + 3, hv_R2 + 3, hv_C2 + 3);
            HOperatorSet.SetColor(hv_WindowHandle, "white");
            HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2);
            HOperatorSet.SetDraw(hv_WindowHandle, hv_DrawMode);
        }
        else if ((int)(new HTuple(hv_Box.TupleNotEqual("false"))) != 0)
        {
            hv_Exception = "Wrong value of control parameter Box";
            throw new HalconException(hv_Exception);
        }
        //Write text.
        for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                              )) - 1); hv_Index = (int)hv_Index + 1)
        {
            hv_CurrentColor = hv_Color_COPY_INP_TMP.TupleSelect(hv_Index % (new HTuple(hv_Color_COPY_INP_TMP.TupleLength()
                                                                                       )));
            if ((int)((new HTuple(hv_CurrentColor.TupleNotEqual(""))).TupleAnd(new HTuple(hv_CurrentColor.TupleNotEqual(
                                                                                              "auto")))) != 0)
            {
                HOperatorSet.SetColor(hv_WindowHandle, hv_CurrentColor);
            }
            else
            {
                HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
            }
            hv_Row_COPY_INP_TMP = hv_R1 + (hv_MaxHeight * hv_Index);
            HOperatorSet.SetTposition(hv_WindowHandle, hv_Row_COPY_INP_TMP, hv_C1);
            HOperatorSet.WriteString(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect(
                                         hv_Index));
        }
        //reset changed window settings
        HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
        HOperatorSet.SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part,
                             hv_Column2Part);

        return;
    }
Exemplo n.º 22
0
        /// <summary>
        /// 初始化後才能叫用 Action
        /// </summary>
        public MeasureResult Action()
        {
            #region 輸出結果, CircleResult or Distance Result
            CircleResult mResult = null;
            #endregion

            // Local iconic variables

            HObject ho_R1_Circle = null;
            HObject ho_R1_ROI_Image = null, ho_R1_Region = null, ho_R1_ImageReduced = null;
            HObject ho_R1_Edges = null, ho_R1_ContoursSplit = null, ho_R1_SingleSegment = null;
            //HObject ho_R1_ContEllipse = null;

            // Local control variables

            HTuple hv_msgOffsetY, hv_msgOffsetX;
            //HTuple hv_AllModelId;
            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol, hv_STD_R1_Row, hv_STD_R1_Col;
            HTuple hv_STD_R1_V_Row, hv_STD_R1_V_Col, hv_R1_X, hv_R1_Y;
            HTuple hv_R1_Pos_Row, hv_R1_Pos_Col, hv_R1_R;
            HTuple hv_alpha = new HTuple(), hv_R1_low = new HTuple(), hv_R1_high = new HTuple();
            HTuple hv_R1_NumSegments = new HTuple(), hv_NumCircles = new HTuple();
            HTuple hv_Num_Circle_Point = new HTuple(), hv_R1 = new HTuple();
            HTuple hv_R1_limit = new HTuple(), hv_i = new HTuple(), hv_Attrib = new HTuple();
            HTuple hv_R1_Row = new HTuple(), hv_R1_Column = new HTuple();
            HTuple hv_R1_Radius = new HTuple(), hv_R1_StartPhi = new HTuple();
            HTuple hv_R1_EndPhi = new HTuple(), hv_R1_PointOrder = new HTuple();
            HTuple hv_R1_MinDist = new HTuple(), hv_R1_MaxDist = new HTuple();
            HTuple hv_R1_AvgDist = new HTuple(), hv_R1_SigmaDist = new HTuple();
            HTuple hv_ResultText = new HTuple(), hv_MeasureReasult;

            // Initialize local and output iconic variables
            //HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_R1_Circle);
            HOperatorSet.GenEmptyObj(out ho_R1_ROI_Image);
            HOperatorSet.GenEmptyObj(out ho_R1_Region);
            HOperatorSet.GenEmptyObj(out ho_R1_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_R1_Edges);
            HOperatorSet.GenEmptyObj(out ho_R1_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_R1_SingleSegment);
            //HOperatorSet.GenEmptyObj(out ho_R1_ContEllipse);

            //Measure: SDMS_R1
            //Author: John Hsieh
            //Date: 2012
            //ho_Image.Dispose();
            //HOperatorSet.ReadImage(out ho_Image, "D:/Projects/Halcon/SDMS/SDMS_Measure/Images/E-1/E1-1.bmp");
            //dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle);
            //dev_update_off ()
            // dev_update_window(...); only in hdevelop
            HOperatorSet.SetSystem("border_shape_models", "false");

            //****Message Args
            hv_msgOffsetY = 100;
            hv_msgOffsetX = 100;

            //****Model All
            //HOperatorSet.ReadShapeModel("D:/Projects/Halcon/SDMS/SDMS_Measure/Model/MatchingAll.shm",
            //	out hv_AllModelId);
            //ho_AllModelContours.Dispose();
            //HOperatorSet.GetShapeModelContours(out ho_AllModelContours, hv_AllModelId, 1);
            //HOperatorSet.FindShapeModel(ho_Image, hv_AllModelId, (new HTuple(0)).TupleRad()
            //	, (new HTuple(360)).TupleRad(), 0.5, 1, 0.5, "least_squares", 6, 0.75, out hv_AllModelRow,
            //	out hv_AllModelColumn, out hv_AllModelAngle, out modelScore);

            //****Model Args

            //STD 中心點
            hv_STD_Row = 772;
            hv_STD_Col = 1003;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //****R1
            //STD R1_ 位置
            hv_STD_R1_Row = 589;
            hv_STD_R1_Col = 705;

            //STD 向量 STD_R1_
            hv_STD_R1_V_Row = hv_STD_R1_Row - hv_STD_Row;
            hv_STD_R1_V_Col = hv_STD_R1_Col - hv_STD_Col;

            //R1_X, R1_Y 分量
            hv_R1_X = (hv_STD_R1_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_R1_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                ));
            hv_R1_Y = (hv_STD_R1_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_R1_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                ));

            //目前圖形 R1_ 位置
            hv_R1_Pos_Row = (hv_STD_Row + hv_R1_Y) + hv_OffsetRow;
            hv_R1_Pos_Col = (hv_STD_Col + hv_R1_X) + hv_OffsetCol;

            hv_R1_R = 20;
            //*ROI
            ho_R1_Circle.Dispose();
            HOperatorSet.GenCircle(out ho_R1_Circle, hv_R1_Pos_Row, hv_R1_Pos_Col, hv_R1_R);
            ho_R1_ROI_Image.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_R1_Circle, out ho_R1_ROI_Image);
            ho_R1_Region.Dispose();
            HOperatorSet.FastThreshold(ho_R1_ROI_Image, out ho_R1_Region, 100, 255, 20);
            ho_R1_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_R1_ROI_Image, ho_R1_Region, out ho_R1_ImageReduced
                );

            //sobel_fast 具有較寬的選擇範圍,搭配 alpha 參數 (alpha 越大, 容錯範圍大)
            hv_alpha = 0.9;
            hv_R1_low = 20;
            hv_R1_high = 40;
            ho_R1_Edges.Dispose();
            HOperatorSet.EdgesSubPix(ho_R1_ImageReduced, out ho_R1_Edges, "sobel_fast",
                hv_alpha, hv_R1_low, hv_R1_high);
            //stop ()
            //*所有的數值越小,表示容錯範圍大,反之亦然
            ho_R1_ContoursSplit.Dispose();
            HOperatorSet.SegmentContoursXld(ho_R1_Edges, out ho_R1_ContoursSplit, "lines_circles",
                17, 1, 1);
            //Display the results
            //===========================================================
            HOperatorSet.CountObj(ho_R1_ContoursSplit, out hv_R1_NumSegments);
            hv_NumCircles = 0;
            hv_Num_Circle_Point = 5;
            hv_R1 = 999;
            hv_R1_limit = 10;
            for (hv_i = 1; hv_i.Continue(hv_R1_NumSegments, 1); hv_i = hv_i.TupleAdd(1))
            {
                ho_R1_SingleSegment.Dispose();
                HOperatorSet.SelectObj(ho_R1_ContoursSplit, out ho_R1_SingleSegment, hv_i);
                HOperatorSet.GetContourGlobalAttribXld(ho_R1_SingleSegment, "cont_approx", out hv_Attrib);

                if ((int)(new HTuple(hv_Attrib.TupleEqual(1))) != 0)
                {
                    HOperatorSet.FitCircleContourXld(ho_R1_SingleSegment, "atukey", -1, 2,
                        hv_Num_Circle_Point, 5, 2, out hv_R1_Row, out hv_R1_Column, out hv_R1_Radius,
                        out hv_R1_StartPhi, out hv_R1_EndPhi, out hv_R1_PointOrder);

                    //ho_R1_ContEllipse.Dispose();
                    //HOperatorSet.GenEllipseContourXld(out ho_R1_ContEllipse, hv_R1_Row, hv_R1_Column,
                    //	0, hv_R1_Radius, hv_R1_Radius, 0, (new HTuple(360)).TupleRad(), "positive",
                    //	1.0);

                    //HOperatorSet.DistEllipseContourXld(ho_R1_SingleSegment, "algebraic", -1,
                    //	0, hv_R1_Row, hv_R1_Column, 0, hv_R1_Radius, hv_R1_Radius, out hv_R1_MinDist,
                    //	out hv_R1_MaxDist, out hv_R1_AvgDist, out hv_R1_SigmaDist);

                    hv_NumCircles = hv_NumCircles + 1;
                    if ((int)(new HTuple(hv_R1.TupleGreater(hv_R1_Radius))) != 0)
                    {
                        hv_R1 = hv_R1_Radius.Clone();
                        //hv_ResultText = (((("C" + hv_NumCircles) + ": Radius = ") + (hv_R1_Radius.TupleString(
                        //	".3"))) + " / MaxDeviation: ") + (hv_R1_MaxDist.TupleString(".3"));
                        //HOperatorSet.SetTposition(hv_WindowHandle, hv_R1_Pos_Row - hv_msgOffsetY,
                        //	hv_R1_Pos_Col - hv_msgOffsetX);
                        //HOperatorSet.WriteString(hv_WindowHandle, "R1");

                        #region 組合結果
                        mResult = new CircleResult(new HTuple(hv_R1_Row)
                                                , new HTuple(hv_R1_Column)
                                                , new HTuple(hv_R1_Radius)
                                                , new HTuple(hv_R1_StartPhi)
                                                , new HTuple(hv_R1_EndPhi)
                                                , new HTuple(hv_R1_PointOrder)) { };
                        #endregion
                    }
                }
            }
            hv_MeasureReasult = hv_R1.Clone();
            //****R1 End
            //ho_Image.Dispose();
            ho_R1_Circle.Dispose();
            ho_R1_ROI_Image.Dispose();
            ho_R1_Region.Dispose();
            ho_R1_ImageReduced.Dispose();
            ho_R1_Edges.Dispose();
            ho_R1_ContoursSplit.Dispose();
            ho_R1_SingleSegment.Dispose();
            //ho_R1_ContEllipse.Dispose();

            return mResult;
        }
Exemplo n.º 23
0
        //DateTime t1, t2, t3, t4,t5,t6,t7;
        private void action()
        {
            // Local iconic variables

            HObject ho_GrayImage, ho_Image1;
            HObject ho_Image2, ho_Image3, ho_ImageResult1, ho_ImageResult2;
            HObject ho_ImageResult3, ho_im, ho_Region, ho_RegionConnection;
            HObject ho_RegionSelected, ho_RegionDilation, ho_RegionFillUp;
            HObject ho_RegionDifference, ho_ConnectedRegions1, ho_SelectedRegions1;
            HObject ho_Contour_JiaoQuanOuter, ho_Circle, ho_Contour_JiaoQuanInner;
            HObject ho_Region_WaiKuang, ho_RegionFillUp_WaiKuang, ho_ConnectedRegions_WaiKuang;
            HObject ho_SelectedRegions_WaiKuang, ho_Contour_WaiKuang;
            HObject ho_Image33;

            // Local control variables

            HTuple hv_Area2 = null, hv_Row = null, hv_Column = null;
            HTuple hv_AreaRegionSelected = null, hv_RowRegionSelected = null;
            HTuple hv_ColumnRegionSelected = null, hv_NumRegion = null;
            HTuple hv_ContourCount_JiaoQuanOuter = null, hv_RowFit_JiaoQuanOuter = null;
            HTuple hv_ColumnFit_JiaoQuanOuter = null, hv_RadiusFit_JiaoQuanOuter = null;
            HTuple hv_StartPhi = null, hv_EndPhi = null, hv_PointOrder = null;
            HTuple hv_RowSmallest_JiaoQuanOuter = null, hv_ColumnSmallest_JiaoQuanOuter = null;
            HTuple hv_RadiusSmallest_JiaoQuanOuter = null, hv_RowInner_JiaoQuanOuter = null;
            HTuple hv_ColumnInner_JiaoQuanOuter = null, hv_RadiusInner_JiaoQuanOuter = null;
            HTuple hv_RadiusRatio_JiaoQuanOuter = null, hv_Row_JiaoQuanOuter = null;
            HTuple hv_Col_JiaoQuanOuter = null, hv_GapAbsAll_JiaoQuanOuter = null;
            HTuple hv_i = null, hv_Distance1 = new HTuple(), hv_GapAbs = new HTuple();
            HTuple hv_Sorted = new HTuple(), hv_MaxGap_JiaoQuanOuter = null;
            HTuple hv_ContourCount_JiaoQuanInner = null, hv_RowFit_JiaoQuanInner = null;
            HTuple hv_ColumnFit_JiaoQuanInner = null, hv_RadiusFit_JiaoQuanInner = null;
            HTuple hv_RowSmallest_JiaoQuanInner = null, hv_ColumnSmallest_JiaoQuanInner = null;
            HTuple hv_RadiusSmallest_JiaoQuanInner = null, hv_RowInner_JiaoQuanInner = null;
            HTuple hv_ColumnInner_JiaoQuanInner = null, hv_RadiusInner_JiaoQuanInner = null;
            HTuple hv_RadiusRatio_JiaoQuanInner = null, hv_Row_JiaoQuanInner = null;
            HTuple hv_Col_JiaoQuanInner = null, hv_GapAbsAll_JiaoQuanInner = null;
            HTuple hv_MaxGap_JiaoQuanInner = null, hv_ContourCount_WaiKuang = null;
            HTuple hv_RowFit_WaiKuang = null, hv_ColumnFit_WaiKuang = null;
            HTuple hv_RadiusFit_WaiKuang = null, hv_RowSmallest_WaiKuang = null;
            HTuple hv_ColumnSmallest_WaiKuang = null, hv_RadiusSmallest_WaiKuang = null;
            HTuple hv_RowInner_WaiKuang = null, hv_ColumnInner_WaiKuang = null;
            HTuple hv_RadiusInner_WaiKuang = null, hv_RadiusRatio_WaiKuang = null;
            HTuple hv_Row_WaiKuang = null, hv_Col_WaiKuang = null;
            HTuple hv_GapAbsAll_WaiKuang = null, hv_MaxGap_WaiKuang = null;
            HTuple hv_NumConnected = null, hv_NumHoles = null, hv_Area_JiaoQuan = null;
            HTuple hv_Row_JiaoQuan = null, hv_Column_JiaoQuan = null;
            HTuple hv_Area_JiaoQuanOuter = null, hv_Column_JiaoQuanOuter = null;
            HTuple hv_Area_JiaoQuanInner = null, hv_Column_JiaoQuanInner = null;
            HTuple hv_a = null, hv_hd = null, hv_Deviation = null;

            //HTuple hv_result = new HTuple();
            // Initialize local and output iconic variables
            //HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_GrayImage);
            HOperatorSet.GenEmptyObj(out ho_Image1);
            HOperatorSet.GenEmptyObj(out ho_Image2);
            HOperatorSet.GenEmptyObj(out ho_Image3);
            HOperatorSet.GenEmptyObj(out ho_ImageResult1);
            HOperatorSet.GenEmptyObj(out ho_ImageResult2);
            HOperatorSet.GenEmptyObj(out ho_ImageResult3);
            HOperatorSet.GenEmptyObj(out ho_im);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionConnection);
            HOperatorSet.GenEmptyObj(out ho_RegionSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Contour_JiaoQuanOuter);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_Contour_JiaoQuanInner);
            HOperatorSet.GenEmptyObj(out ho_Region_WaiKuang);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp_WaiKuang);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions_WaiKuang);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions_WaiKuang);
            HOperatorSet.GenEmptyObj(out ho_Contour_WaiKuang);
            HOperatorSet.GenEmptyObj(out ho_Image33);

            //t3 = DateTime.Now;
            try
            {
                ho_Image1.Dispose(); ho_Image2.Dispose(); ho_Image3.Dispose();
                HOperatorSet.Decompose3(Image, out ho_Image1, out ho_Image2, out ho_Image3);
                ho_ImageResult1.Dispose(); ho_ImageResult2.Dispose(); ho_ImageResult3.Dispose();
                HOperatorSet.TransFromRgb(ho_Image1, ho_Image2, ho_Image3, out ho_ImageResult1, out ho_ImageResult2, out ho_ImageResult3, "hls");
                ho_ImageResult1.Dispose();
                HOperatorSet.SubImage(ho_Image1, ho_Image2, out ho_ImageResult1, 1, 0);
                ho_im.Dispose();
                HOperatorSet.MeanImage(ho_ImageResult1, out ho_im, 9, 9);
                ho_Region.Dispose();
                HOperatorSet.Threshold(ho_ImageResult1, out ho_Region, 40, 255);
                //closing_circle (Region, Region, 3.5)
                ho_RegionConnection.Dispose();
                HOperatorSet.Connection(ho_Region, out ho_RegionConnection);
                //select_shape (RegionConnection, RegionSelected, 'area', 'and', 10000, 9999999)
                ho_RegionSelected.Dispose();
                HOperatorSet.SelectShapeStd(ho_RegionConnection, out ho_RegionSelected, "max_area", 70);
                ho_RegionDilation.Dispose();
                HOperatorSet.DilationCircle(ho_RegionSelected, out ho_RegionDilation, 1.5);
                HOperatorSet.AreaCenter(ho_RegionDilation, out hv_Area2, out hv_Row, out hv_Column);
                ho_RegionFillUp.Dispose();
                HOperatorSet.FillUp(ho_RegionDilation, out ho_RegionFillUp);
                ho_RegionDifference.Dispose();
                HOperatorSet.Difference(ho_RegionFillUp, ho_RegionDilation, out ho_RegionDifference);
                ho_ConnectedRegions1.Dispose();
                HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1);
                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShapeStd(ho_ConnectedRegions1, out ho_SelectedRegions1, "max_area", 70);

                //JiaoQuanOuter胶圈外圆:圆度、直径
                HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_AreaRegionSelected, out hv_RowRegionSelected, out hv_ColumnRegionSelected);
                hv_NumRegion = new HTuple(hv_AreaRegionSelected.TupleLength());

                ho_Contour_JiaoQuanOuter.Dispose();
                HOperatorSet.GenContourRegionXld(ho_RegionFillUp, out ho_Contour_JiaoQuanOuter, "border");
                HOperatorSet.ContourPointNumXld(ho_Contour_JiaoQuanOuter, out hv_ContourCount_JiaoQuanOuter);

                HOperatorSet.FitCircleContourXld(ho_Contour_JiaoQuanOuter, "atukey", -1, 2, 0,
                                                 10, 1, out hv_RowFit_JiaoQuanOuter, out hv_ColumnFit_JiaoQuanOuter, out hv_RadiusFit_JiaoQuanOuter,
                                                 out hv_StartPhi, out hv_EndPhi, out hv_PointOrder);

                HOperatorSet.SmallestCircleXld(ho_Contour_JiaoQuanOuter, out hv_RowSmallest_JiaoQuanOuter,
                                               out hv_ColumnSmallest_JiaoQuanOuter, out hv_RadiusSmallest_JiaoQuanOuter);

                HOperatorSet.InnerCircle(ho_RegionFillUp, out hv_RowInner_JiaoQuanOuter, out hv_ColumnInner_JiaoQuanOuter,
                                         out hv_RadiusInner_JiaoQuanOuter);
                //*半径比值 of 外接圆和内切圆
                hv_RadiusRatio_JiaoQuanOuter = hv_RadiusInner_JiaoQuanOuter / hv_RadiusSmallest_JiaoQuanOuter;

                //**Contour Point
                HOperatorSet.GetContourXld(ho_Contour_JiaoQuanOuter, out hv_Row_JiaoQuanOuter, out hv_Col_JiaoQuanOuter);
                hv_GapAbsAll_JiaoQuanOuter = new HTuple();
                HTuple end_val51  = hv_ContourCount_JiaoQuanOuter - 1;
                HTuple step_val51 = 3;
                for (hv_i = 0; hv_i.Continue(end_val51, step_val51); hv_i = hv_i.TupleAdd(step_val51))
                {
                    HOperatorSet.DistancePp(hv_Row_JiaoQuanOuter.TupleSelect(hv_i), hv_Col_JiaoQuanOuter.TupleSelect(
                                                hv_i), hv_RowFit_JiaoQuanOuter, hv_ColumnFit_JiaoQuanOuter, out hv_Distance1);
                    HOperatorSet.TupleAbs(hv_Distance1 - hv_RadiusFit_JiaoQuanOuter, out hv_GapAbs);
                    hv_GapAbsAll_JiaoQuanOuter = hv_GapAbsAll_JiaoQuanOuter.TupleConcat(hv_GapAbs);
                    HOperatorSet.TupleSort(hv_GapAbsAll_JiaoQuanOuter, out hv_Sorted);
                }

                hv_MaxGap_JiaoQuanOuter = hv_Sorted.TupleSelect(hv_ContourCount_JiaoQuanOuter - 1);

                //JiaoQuanInner胶圈内圆:圆度、直径
                HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_AreaRegionSelected, out hv_RowRegionSelected, out hv_ColumnRegionSelected);
                hv_NumRegion = new HTuple(hv_AreaRegionSelected.TupleLength());

                ho_Contour_JiaoQuanInner.Dispose();
                HOperatorSet.GenContourRegionXld(ho_SelectedRegions1, out ho_Contour_JiaoQuanInner, "border");
                HOperatorSet.ContourPointNumXld(ho_Contour_JiaoQuanInner, out hv_ContourCount_JiaoQuanInner);

                HOperatorSet.FitCircleContourXld(ho_Contour_JiaoQuanInner, "atukey", -1, 2, 0,
                                                 10, 1, out hv_RowFit_JiaoQuanInner, out hv_ColumnFit_JiaoQuanInner, out hv_RadiusFit_JiaoQuanInner,
                                                 out hv_StartPhi, out hv_EndPhi, out hv_PointOrder);

                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_RowFit_JiaoQuanInner, hv_ColumnFit_JiaoQuanInner,
                                       hv_RadiusFit_JiaoQuanInner);

                HOperatorSet.SmallestCircleXld(ho_Contour_JiaoQuanInner, out hv_RowSmallest_JiaoQuanInner, out hv_ColumnSmallest_JiaoQuanInner, out hv_RadiusSmallest_JiaoQuanInner);
                //gen_circle (Circle1, RowSmallest_JiaoQuanInner, ColumnSmallest_JiaoQuanInner, RadiusSmallest_JiaoQuanInner)

                HOperatorSet.InnerCircle(ho_SelectedRegions1, out hv_RowInner_JiaoQuanInner, out hv_ColumnInner_JiaoQuanInner, out hv_RadiusInner_JiaoQuanInner);
                //gen_circle (Circle2, RowInner_JiaoQuanInner, ColumnInner_JiaoQuanInner, RadiusInner_JiaoQuanInner)
                //*半径比值 of 外接圆和内切圆
                hv_RadiusRatio_JiaoQuanInner = hv_RadiusInner_JiaoQuanInner / hv_RadiusSmallest_JiaoQuanInner;

                //**Contour Point
                HOperatorSet.GetContourXld(ho_Contour_JiaoQuanInner, out hv_Row_JiaoQuanInner, out hv_Col_JiaoQuanInner);
                hv_GapAbsAll_JiaoQuanInner = new HTuple();
                HTuple end_val89  = hv_ContourCount_JiaoQuanInner - 1;
                HTuple step_val89 = 3;
                for (hv_i = 0; hv_i.Continue(end_val89, step_val89); hv_i = hv_i.TupleAdd(step_val89))
                {
                    HOperatorSet.DistancePp(hv_Row_JiaoQuanInner.TupleSelect(hv_i), hv_Col_JiaoQuanInner.TupleSelect(
                                                hv_i), hv_RowFit_JiaoQuanInner, hv_ColumnFit_JiaoQuanInner, out hv_Distance1);
                    HOperatorSet.TupleAbs(hv_Distance1 - hv_RadiusFit_JiaoQuanInner, out hv_GapAbs);
                    hv_GapAbsAll_JiaoQuanInner = hv_GapAbsAll_JiaoQuanInner.TupleConcat(hv_GapAbs);
                    HOperatorSet.TupleSort(hv_GapAbsAll_JiaoQuanInner, out hv_Sorted);
                }

                hv_MaxGap_JiaoQuanInner = hv_Sorted.TupleSelect(hv_ContourCount_JiaoQuanInner - 1);


                //外框外圆:圆度、直径
                ho_GrayImage.Dispose();
                HOperatorSet.Rgb1ToGray(Image, out ho_GrayImage);
                ho_Region_WaiKuang.Dispose();
                HOperatorSet.Threshold(ho_GrayImage, out ho_Region_WaiKuang, 90, 255);
                ho_RegionFillUp_WaiKuang.Dispose();
                HOperatorSet.FillUp(ho_Region_WaiKuang, out ho_RegionFillUp_WaiKuang);
                ho_ConnectedRegions_WaiKuang.Dispose();
                HOperatorSet.Connection(ho_RegionFillUp_WaiKuang, out ho_ConnectedRegions_WaiKuang);
                ho_SelectedRegions_WaiKuang.Dispose();
                HOperatorSet.SelectShapeStd(ho_ConnectedRegions_WaiKuang, out ho_SelectedRegions_WaiKuang, "max_area", 70);
                //smallest_circle (RegionFillUp_WaiKuang, Row2, Column2, Radius)
                //inner_circle (RegionFillUp_WaiKuang, Row3, Column3, Radius1)

                HOperatorSet.AreaCenter(ho_SelectedRegions_WaiKuang, out hv_AreaRegionSelected, out hv_RowRegionSelected, out hv_ColumnRegionSelected);
                hv_NumRegion = new HTuple(hv_AreaRegionSelected.TupleLength());

                ho_Contour_WaiKuang.Dispose();
                HOperatorSet.GenContourRegionXld(ho_SelectedRegions_WaiKuang, out ho_Contour_WaiKuang, "border");
                HOperatorSet.ContourPointNumXld(ho_Contour_WaiKuang, out hv_ContourCount_WaiKuang);

                HOperatorSet.FitCircleContourXld(ho_Contour_WaiKuang, "atukey", -1, 2, 0, 10,
                                                 1, out hv_RowFit_WaiKuang, out hv_ColumnFit_WaiKuang, out hv_RadiusFit_WaiKuang,
                                                 out hv_StartPhi, out hv_EndPhi, out hv_PointOrder);

                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_RowFit_WaiKuang, hv_ColumnFit_WaiKuang,
                                       hv_RadiusFit_WaiKuang);

                HOperatorSet.SmallestCircleXld(ho_Contour_WaiKuang, out hv_RowSmallest_WaiKuang, out hv_ColumnSmallest_WaiKuang, out hv_RadiusSmallest_WaiKuang);
                //gen_circle (Circle1, RowSmallest_WaiKuang, ColumnSmallest_WaiKuang, RadiusSmallest_WaiKuang)

                HOperatorSet.InnerCircle(ho_SelectedRegions_WaiKuang, out hv_RowInner_WaiKuang, out hv_ColumnInner_WaiKuang, out hv_RadiusInner_WaiKuang);
                //gen_circle (Circle2, RowInner_WaiKuang, ColumnInner_WaiKuang, RadiusInner_WaiKuang)
                //*半径比值 of 外接圆和内切圆
                hv_RadiusRatio_WaiKuang = hv_RadiusInner_WaiKuang / hv_RadiusSmallest_WaiKuang;

                //**Contour Point
                HOperatorSet.GetContourXld(ho_Contour_WaiKuang, out hv_Row_WaiKuang, out hv_Col_WaiKuang);
                hv_GapAbsAll_WaiKuang = new HTuple();
                HTuple end_val135  = hv_ContourCount_WaiKuang - 1;
                HTuple step_val135 = 3;
                for (hv_i = 0; hv_i.Continue(end_val135, step_val135); hv_i = hv_i.TupleAdd(step_val135))
                {
                    HOperatorSet.DistancePp(hv_Row_WaiKuang.TupleSelect(hv_i), hv_Col_WaiKuang.TupleSelect(
                                                hv_i), hv_RowFit_WaiKuang, hv_ColumnFit_WaiKuang, out hv_Distance1);
                    HOperatorSet.TupleAbs(hv_Distance1 - hv_RadiusFit_WaiKuang, out hv_GapAbs);
                    hv_GapAbsAll_WaiKuang = hv_GapAbsAll_WaiKuang.TupleConcat(hv_GapAbs);
                    HOperatorSet.TupleSort(hv_GapAbsAll_WaiKuang, out hv_Sorted);
                }

                hv_MaxGap_WaiKuang = hv_Sorted.TupleSelect(hv_ContourCount_WaiKuang - 1);


                //脏污
                HOperatorSet.ConnectAndHoles(ho_RegionSelected, out hv_NumConnected, out hv_NumHoles);

                HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area_JiaoQuan, out hv_Row_JiaoQuan, out hv_Column_JiaoQuan);
                HOperatorSet.AreaCenter(ho_RegionSelected, out hv_Area_JiaoQuanOuter, out hv_Row_JiaoQuanOuter, out hv_Column_JiaoQuanOuter);
                HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_Area_JiaoQuanInner, out hv_Row_JiaoQuanInner, out hv_Column_JiaoQuanInner);
                hv_a = (hv_Area_JiaoQuan - hv_Area_JiaoQuanOuter) - hv_Area_JiaoQuanInner;

                ho_Image33.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_SelectedRegions1, out ho_Image33);
                HOperatorSet.Intensity(ho_SelectedRegions1, ho_Image33, out hv_hd, out hv_Deviation);

                HOperatorSet.Union1(ho_RegionDilation, out RegionToDisp);

                //Result
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("橡皮圆度-半径比");
                hv_result = hv_result.TupleConcat(hv_RadiusRatio_JiaoQuanOuter.D);
                hv_result = hv_result.TupleConcat("橡皮圆度-最大值");
                hv_result = hv_result.TupleConcat(hv_MaxGap_JiaoQuanOuter.D);

                hv_result = hv_result.TupleConcat("橡皮内孔圆度-半径比");
                hv_result = hv_result.TupleConcat(hv_RadiusRatio_JiaoQuanInner.D);
                hv_result = hv_result.TupleConcat("橡皮内孔圆度-最大值");
                hv_result = hv_result.TupleConcat(hv_MaxGap_JiaoQuanInner.D);
                hv_result = hv_result.TupleConcat("橡皮内孔面积");
                hv_result = hv_result.TupleConcat(hv_Area_JiaoQuanInner.D);

                hv_result = hv_result.TupleConcat("橡皮面积");
                hv_result = hv_result.TupleConcat(hv_Area_JiaoQuanOuter.D);

                hv_result = hv_result.TupleConcat("橡皮灰尘");
                hv_result = hv_result.TupleConcat(hv_a.D);

                hv_result = hv_result.TupleConcat("外圆圆度-半径比");
                hv_result = hv_result.TupleConcat(hv_RadiusRatio_WaiKuang.D);
                hv_result = hv_result.TupleConcat("外圆圆度-最大值");
                hv_result = hv_result.TupleConcat(hv_MaxGap_WaiKuang.D);
                hv_result = hv_result.TupleConcat("外圆内圆直径");
                hv_result = hv_result.TupleConcat(hv_RadiusInner_WaiKuang.D * pixeldist * 2);
                hv_result = hv_result.TupleConcat("外圆外圆直径");
                hv_result = hv_result.TupleConcat(hv_RadiusSmallest_WaiKuang.D * pixeldist * 2);

                hv_result = hv_result.TupleConcat("内孔灰度");
                hv_result = hv_result.TupleConcat(hv_hd.D);
                result    = hv_result.Clone();

                //t4 = DateTime.Now;
            }
            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("橡皮内孔圆度-最大值");
                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("橡皮灰尘");
                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("外圆内圆直径");
                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);
                result    = hv_result.Clone();
            }
            finally
            {
                //ho_Image.Dispose();
                ho_GrayImage.Dispose();
                ho_Image1.Dispose();
                ho_Image2.Dispose();
                ho_Image3.Dispose();
                ho_ImageResult1.Dispose();
                ho_ImageResult2.Dispose();
                ho_ImageResult3.Dispose();
                ho_im.Dispose();
                ho_Region.Dispose();
                ho_RegionConnection.Dispose();
                ho_RegionSelected.Dispose();
                ho_RegionDilation.Dispose();
                ho_RegionFillUp.Dispose();
                ho_RegionDifference.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_Contour_JiaoQuanOuter.Dispose();
                ho_Circle.Dispose();
                ho_Contour_JiaoQuanInner.Dispose();
                ho_Region_WaiKuang.Dispose();
                ho_RegionFillUp_WaiKuang.Dispose();
                ho_ConnectedRegions_WaiKuang.Dispose();
                ho_SelectedRegions_WaiKuang.Dispose();
                ho_Contour_WaiKuang.Dispose();
                ho_Image33.Dispose();
                algorithm.Region.Dispose();
            }
        }
Exemplo n.º 24
0
        private void action()
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];
            long      SP_O  = 0;
            // Local iconic variables
            HObject ho_Circle, region;
            HObject ho_SelectedRegions, ho_outCircle;
            // Local control variables

            //HTuple hv_blackOrwhite, hv_threshold_value;
            //HTuple hv_method, hv_andOror, hv_method_min_value, hv_method_max_value;
            HTuple hv_outer_Row, hv_outer_Column;
            HTuple hv_outer_Radius, hv_Circularity;
            HTuple hv_Number = new HTuple(), hv_result = new HTuple();

            // Initialize local and output iconic variables
            //HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_outCircle);
            HOperatorSet.GenEmptyObj(out region);
            try
            {
                //HOperatorSet.SetColor(this.LWindowHandle, "green");
                //    out hv_Radius);
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, DCenterRow, DCenterColumn, DRadius);
                HOperatorSet.Intersection(ho_Circle, algorithm.Region, out region);
                region_outer_circle(region, out ho_outCircle, out hv_outer_Row,
                                    out hv_outer_Column, out hv_outer_Radius, out hv_Circularity);

                //HOperatorSet.DispObj(ho_outCircle, this.LWindowHandle);
                RegionToDisp.Dispose();
                if (!RegionToDisp.IsInitialized())
                {
                    HOperatorSet.CopyObj(ho_outCircle, out RegionToDisp, 1, 1);
                }
                else
                {
                    HOperatorSet.ConcatObj(ho_outCircle, RegionToDisp, out RegionToDisp);
                }
                //RegionToDisp
                HOperatorSet.CountObj(ho_outCircle, out hv_Number);
                if ((int)(new HTuple(hv_Number.TupleEqual(1))) != 0)
                {
                    hv_result = hv_result.TupleConcat("center_row");
                    hv_result = hv_result.TupleConcat(hv_outer_Row * pixeldist);
                    hv_result = hv_result.TupleConcat("center_column");
                    hv_result = hv_result.TupleConcat(hv_outer_Column * pixeldist);
                    hv_result = hv_result.TupleConcat("diameter");
                    hv_result = hv_result.TupleConcat(2 * hv_outer_Radius * pixeldist);
                    hv_result = hv_result.TupleConcat("circularity");
                    hv_result = hv_result.TupleConcat(hv_Circularity);
                    result    = hv_result.Clone();
                }
                else
                {
                    hv_result = hv_result.TupleConcat("center_row");
                    hv_result = hv_result.TupleConcat(0);
                    hv_result = hv_result.TupleConcat("center_column");
                    hv_result = hv_result.TupleConcat(0);
                    hv_result = hv_result.TupleConcat("diameter");
                    hv_result = hv_result.TupleConcat(0);
                    hv_result = hv_result.TupleConcat("circularity");
                    hv_result = hv_result.TupleConcat(0);
                    result    = hv_result.Clone();
                }
            }
            catch (HalconException HDevExpDefaultException)
            {
                this.Result = new HTuple();
                MyDebug.ShowMessage("CircleToolsError:=" + HDevExpDefaultException);
                hv_result = hv_result.TupleConcat("center_row");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("center_column");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("diameter");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("circularity");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();
            }
            finally
            {
                ho_Circle.Dispose();
                region.Dispose();
                ho_SelectedRegions.Dispose();
                ho_outCircle.Dispose();
                algorithm.Region.Dispose();
            }
        }
Exemplo n.º 25
0
        private void action()
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];

            // Local iconic variables

            HObject ho_Region, ho_Region1, ho_ConnectedRegions;
            HObject ho_SelectedRegions, ho_ObjectSelected = null, ho_ObjectSelected1 = null;
            HObject ho_Circle1 = null, ho_Circle2 = null;

            // Local control variables

            HTuple hv_Area = null, hv_Row = null, hv_Column = null;
            HTuple hv_Number = null, hv_m = null, hv_r1 = null, hv_r2 = null;
            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Radius1 = new HTuple(), hv_Row2 = new HTuple();
            HTuple hv_Column2 = new HTuple(), hv_Radius2 = new HTuple();
            HTuple hv_Transition = new HTuple(), hv_Sigma = new HTuple();
            HTuple hv_Threashold = new HTuple(), hv_CenterRowc1 = new HTuple();
            HTuple hv_CenterColumnc1 = new HTuple(), hv_CenterRaduisc1 = new HTuple();
            HTuple hv_StartPhic1 = new HTuple(), hv_EndPhic1 = new HTuple();
            HTuple hv_Circularityc1 = new HTuple(), hv_CenterRowc2 = new HTuple();
            HTuple hv_CenterColumnc2 = new HTuple(), hv_CenterRaduisc2 = new HTuple();
            HTuple hv_StartPhic2 = new HTuple(), hv_EndPhic2 = new HTuple();
            HTuple hv_Circularityc2 = new HTuple(), hv_Distance = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_Circle2);
            HOperatorSet.Union1(algorithm.Region, out RegionToDisp);
            try
            {
                ho_Region.Dispose();
                HOperatorSet.Threshold(Image, out ho_Region, this.mj, 255);
                HOperatorSet.AreaCenter(ho_Region, out hv_Area, out hv_Row, out hv_Column);
                ho_Region1.Dispose();
                HOperatorSet.GenRegionPoints(out ho_Region1, hv_Row, hv_Column);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, ((new HTuple("circularity")).TupleConcat(
                                                                                           "area")).TupleConcat("outer_radius"), "and", ((new HTuple(0.8)).TupleConcat(
                                                                                                                                             500)).TupleConcat(50), ((new HTuple(1)).TupleConcat(9999999)).TupleConcat(
                                             800));
                HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number);


                hv_m  = 0;
                hv_r1 = 0;
                hv_r2 = 0;
                if ((int)(new HTuple(hv_Number.TupleEqual(2))) != 0)
                {
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected, 1);
                    HOperatorSet.SmallestCircle(ho_ObjectSelected, out hv_Row1, out hv_Column1,
                                                out hv_Radius1);
                    ho_ObjectSelected1.Dispose();
                    HOperatorSet.SelectObj(ho_SelectedRegions, out ho_ObjectSelected1, 2);
                    HOperatorSet.SmallestCircle(ho_ObjectSelected1, out hv_Row2, out hv_Column2,
                                                out hv_Radius2);
                    //Transition = 'positive' :dark-to-light;  Transition = 'negative': light-to-dark
                    hv_Transition = "negative";
                    hv_Sigma      = 0.6;
                    hv_Threashold = this.cd;


                    FitCicrle(Image, 3600, hv_Row1, hv_Column1, hv_Radius1 + 5, hv_Row1, (hv_Column1 + (hv_Radius1 / 2)) + 5,
                              0, (hv_Radius1 / 2) + 10, 2, hv_Transition, hv_Sigma, hv_Threashold, out hv_CenterRowc1,
                              out hv_CenterColumnc1, out hv_CenterRaduisc1, out hv_StartPhic1, out hv_EndPhic1,
                              out hv_Circularityc1);
                    ho_Circle1.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle1, hv_CenterRowc1, hv_CenterColumnc1,
                                           hv_CenterRaduisc1);


                    FitCicrle(Image, 3600, hv_Row2, hv_Column2, hv_Radius2 + 5, hv_Row2, (hv_Column2 + (hv_Radius2 / 2)) + 5,
                              0, (hv_Radius2 / 2) + 10, 2, hv_Transition, hv_Sigma, hv_Threashold, out hv_CenterRowc2,
                              out hv_CenterColumnc2, out hv_CenterRaduisc2, out hv_StartPhic2, out hv_EndPhic2,
                              out hv_Circularityc2);
                    ho_Circle2.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle2, hv_CenterRowc2, hv_CenterColumnc2,
                                           hv_CenterRaduisc2);
                    HOperatorSet.DistancePp(hv_CenterRowc2, hv_CenterColumnc2, hv_CenterRowc1,
                                            hv_CenterColumnc1, out hv_Distance);
                    hv_m  = hv_Distance.Clone();
                    hv_r1 = hv_CenterRaduisc1.Clone();
                    hv_r2 = hv_CenterRaduisc2.Clone();

                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.Union2(ho_Region1, ho_Circle2, out ExpTmpOutVar_0);
                        ho_Region1.Dispose();
                        ho_Region1 = ExpTmpOutVar_0;
                    }
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.Union2(ho_Region1, ho_Circle1, out ExpTmpOutVar_0);
                        ho_Region1.Dispose();
                        ho_Region1 = ExpTmpOutVar_0;
                    }
                }

                //HOperatorSet.ClearShapeModel(hv_ModelID);
                HOperatorSet.Union1(ho_Region1, out RegionToDisp);

                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("孔心距");
                hv_result = hv_result.TupleConcat(hv_m.D * pixeldist);
                result    = hv_result.Clone();
                ho_Region.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ObjectSelected1.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                algorithm.Region.Dispose();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("孔心距");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();
                ho_Region.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ObjectSelected1.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                algorithm.Region.Dispose();
            }
            finally
            {
                ho_Region.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ObjectSelected1.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                algorithm.Region.Dispose();
            }
        }
    // Procedures
    // Local procedures
    public void DistanceOfLineToLine(HTuple hv_FirstLineStartPoint_Row, HTuple hv_FirstLineStartPoint_Column,
                                     HTuple hv_FirstLineEndPoint_Row, HTuple hv_FirstLineEndPoint_Column, HTuple hv_SecondLineStartPoint_Row,
                                     HTuple hv_SecondLineStartPoint_Column, HTuple hv_SecondLineEndPoint_Row, HTuple hv_SecondLineEndPoint_Column,
                                     out HTuple hv_LineToLine_Distance, out HTuple hv_DistanceStartPoint_Row, out HTuple hv_DistanceStartPoint_Column,
                                     out HTuple hv_DistanceEndPoint_Row, out HTuple hv_DistanceEndPoint_Column, out HTuple hv_DottedLinePoint_Row,
                                     out HTuple hv_DottedLinePoint_Column, out HTuple hv_LineToLineAngle)
    {
        // Local control variables

        HTuple hv_FirstLineCenterPoint_Row = null;
        HTuple hv_FirstLineCenterPoint_Column = null, hv_MiddleOfFirstLineToSecondLineRowProj = null;
        HTuple hv_MiddleOfFirstLineToSecondLineColProj = null;
        HTuple hv_Max_Column = new HTuple(), hv_Max_Column_Row = new HTuple();
        HTuple hv_Min_Column = new HTuple(), hv_Min_Column_Row = new HTuple();

        // Initialize local and output iconic variables

        hv_DottedLinePoint_Row    = new HTuple();
        hv_DottedLinePoint_Column = new HTuple();
        //center point
        hv_FirstLineCenterPoint_Row = 0.5 * ((hv_FirstLineStartPoint_Row.TupleSelect(0)) + (hv_FirstLineEndPoint_Row.TupleSelect(
                                                                                                0)));
        hv_FirstLineCenterPoint_Column = 0.5 * ((hv_FirstLineStartPoint_Column.TupleSelect(
                                                     0)) + (hv_FirstLineEndPoint_Column.TupleSelect(0)));
        //
        HOperatorSet.ProjectionPl(hv_FirstLineCenterPoint_Row.TupleSelect(0), hv_FirstLineCenterPoint_Column.TupleSelect(
                                      0), hv_SecondLineStartPoint_Row.TupleSelect(0), hv_SecondLineStartPoint_Column.TupleSelect(
                                      0), hv_SecondLineEndPoint_Row.TupleSelect(0), hv_SecondLineEndPoint_Column.TupleSelect(
                                      0), out hv_MiddleOfFirstLineToSecondLineRowProj, out hv_MiddleOfFirstLineToSecondLineColProj);
        //
        HOperatorSet.DistancePp(hv_FirstLineCenterPoint_Row.TupleSelect(0), hv_FirstLineCenterPoint_Column.TupleSelect(
                                    0), hv_MiddleOfFirstLineToSecondLineRowProj, hv_MiddleOfFirstLineToSecondLineColProj,
                                out hv_LineToLine_Distance);
        HOperatorSet.AngleLl(hv_FirstLineStartPoint_Row.TupleSelect(0), hv_FirstLineStartPoint_Column.TupleSelect(
                                 0), hv_FirstLineEndPoint_Row.TupleSelect(0), hv_FirstLineEndPoint_Column.TupleSelect(
                                 0), hv_SecondLineStartPoint_Row.TupleSelect(0), hv_SecondLineStartPoint_Column.TupleSelect(
                                 0), hv_SecondLineEndPoint_Row.TupleSelect(0), hv_SecondLineEndPoint_Column.TupleSelect(
                                 0), out hv_LineToLineAngle);
        hv_DistanceStartPoint_Row    = hv_FirstLineCenterPoint_Row.Clone();
        hv_DistanceStartPoint_Column = hv_FirstLineCenterPoint_Column.Clone();
        hv_DistanceEndPoint_Row      = hv_MiddleOfFirstLineToSecondLineRowProj.Clone();
        hv_DistanceEndPoint_Column   = hv_MiddleOfFirstLineToSecondLineColProj.Clone();
        //
        if ((int)(new HTuple(hv_SecondLineStartPoint_Column.TupleEqual(hv_SecondLineEndPoint_Column))) != 0)
        {
            if ((int)(new HTuple(hv_SecondLineStartPoint_Row.TupleLess(hv_SecondLineEndPoint_Row))) != 0)
            {
                hv_Max_Column     = hv_SecondLineEndPoint_Column.Clone();
                hv_Max_Column_Row = hv_SecondLineEndPoint_Row.Clone();
                hv_Min_Column     = hv_SecondLineStartPoint_Column.Clone();
                hv_Min_Column_Row = hv_SecondLineStartPoint_Row.Clone();
            }
            else
            {
                hv_Max_Column     = hv_SecondLineStartPoint_Column.Clone();
                hv_Max_Column_Row = hv_SecondLineStartPoint_Row.Clone();
                hv_Min_Column     = hv_SecondLineEndPoint_Column.Clone();
                hv_Min_Column_Row = hv_SecondLineEndPoint_Row.Clone();
            }
            if ((int)(new HTuple(hv_MiddleOfFirstLineToSecondLineRowProj.TupleLess(hv_Min_Column_Row))) != 0)
            {
                hv_DottedLinePoint_Row    = hv_Min_Column_Row.Clone();
                hv_DottedLinePoint_Column = hv_Min_Column.Clone();
            }
            else if ((int)(new HTuple(hv_MiddleOfFirstLineToSecondLineRowProj.TupleGreater(
                                          hv_Max_Column_Row))) != 0)
            {
                hv_DottedLinePoint_Row    = hv_Max_Column_Row.Clone();
                hv_DottedLinePoint_Column = hv_Max_Column.Clone();
            }
            else
            {
                hv_DottedLinePoint_Row    = hv_MiddleOfFirstLineToSecondLineRowProj.Clone();
                hv_DottedLinePoint_Column = hv_MiddleOfFirstLineToSecondLineColProj.Clone();
            }
        }
        else
        {
            if ((int)(new HTuple(hv_SecondLineStartPoint_Column.TupleLess(hv_SecondLineEndPoint_Column))) != 0)
            {
                hv_Max_Column     = hv_SecondLineEndPoint_Column.Clone();
                hv_Max_Column_Row = hv_SecondLineEndPoint_Row.Clone();
                hv_Min_Column     = hv_SecondLineStartPoint_Column.Clone();
                hv_Min_Column_Row = hv_SecondLineStartPoint_Row.Clone();
            }
            else
            {
                hv_Max_Column     = hv_SecondLineStartPoint_Column.Clone();
                hv_Max_Column_Row = hv_SecondLineStartPoint_Row.Clone();
                hv_Min_Column     = hv_SecondLineEndPoint_Column.Clone();
                hv_Min_Column_Row = hv_SecondLineEndPoint_Row.Clone();
            }
            if ((int)(new HTuple(hv_MiddleOfFirstLineToSecondLineColProj.TupleLess(hv_Min_Column))) != 0)
            {
                hv_DottedLinePoint_Row    = hv_Min_Column_Row.Clone();
                hv_DottedLinePoint_Column = hv_Min_Column.Clone();
            }
            else if ((int)(new HTuple(hv_MiddleOfFirstLineToSecondLineColProj.TupleGreater(
                                          hv_Max_Column))) != 0)
            {
                hv_DottedLinePoint_Row    = hv_Max_Column_Row.Clone();
                hv_DottedLinePoint_Column = hv_Max_Column.Clone();
            }
            else
            {
                hv_DottedLinePoint_Row    = hv_MiddleOfFirstLineToSecondLineRowProj.Clone();
                hv_DottedLinePoint_Column = hv_MiddleOfFirstLineToSecondLineColProj.Clone();
            }
        }

        return;
    }
Exemplo n.º 27
0
        public MeasureResult Action()
        {
            #region 輸出結果
            CircleResult mResult = null;
            #endregion

            // Local iconic variables

            HObject ho_R17_Circle = null;
            HObject ho_R17_ROI_Image = null, ho_R17_Region = null, ho_R17_ImageReduced = null;
            HObject ho_R17_Edges = null, ho_R17_ContoursSplit = null, ho_R17_SingleSegment = null;
            HObject ho_R17_ContEllipse = null;

            // Local control variables

            HTuple hv_msgOffsetY, hv_msgOffsetX;
            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol, hv_STD_R17_Row, hv_STD_R17_Col;
            HTuple hv_STD_R17_V_Row, hv_STD_R17_V_Col, hv_R17_X, hv_R17_Y;
            HTuple hv_R17_Pos_Row, hv_R17_Pos_Col, hv_R17_R;
            HTuple hv_alpha = new HTuple(), hv_R17_low = new HTuple();
            HTuple hv_R17_high = new HTuple(), hv_R17_NumSegments = new HTuple();
            HTuple hv_NumCircles = new HTuple(), hv_Num_Circle_Point = new HTuple();
            HTuple hv_R17 = new HTuple(), hv_i = new HTuple(), hv_Attrib = new HTuple();
            HTuple hv_R17_Row = new HTuple(), hv_R17_Column = new HTuple();
            HTuple hv_R17_Radius = new HTuple(), hv_R17_StartPhi = new HTuple();
            HTuple hv_R17_EndPhi = new HTuple(), hv_R17_PointOrder = new HTuple();
            HTuple hv_R17_MinDist = new HTuple(), hv_R17_MaxDist = new HTuple();
            HTuple hv_R17_AvgDist = new HTuple(), hv_R17_SigmaDist = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_R17_Circle);
            HOperatorSet.GenEmptyObj(out ho_R17_ROI_Image);
            HOperatorSet.GenEmptyObj(out ho_R17_Region);
            HOperatorSet.GenEmptyObj(out ho_R17_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_R17_Edges);
            HOperatorSet.GenEmptyObj(out ho_R17_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_R17_SingleSegment);
            HOperatorSet.GenEmptyObj(out ho_R17_ContEllipse);

            //Measure: SDMS_R17
            //Author: John Hsieh
            //Date: 2012
            // dev_update_off(...); only in hdevelop
            HOperatorSet.SetSystem("border_shape_models", "false");

            //****Message Args
            hv_msgOffsetY = 100;
            hv_msgOffsetX = 100;

            //****Model Args

            //STD 中心點
            hv_STD_Row = 772;
            hv_STD_Col = 1003;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //****Display
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            //*****R17
            //STD R17_ 位置
            hv_STD_R17_Row = 802;
            hv_STD_R17_Col = 660;

            //STD 向量 STD_R17_
            hv_STD_R17_V_Row = hv_STD_R17_Row - hv_STD_Row;
            hv_STD_R17_V_Col = hv_STD_R17_Col - hv_STD_Col;

            //R17_X, R17_Y 分量
            hv_R17_X = (hv_STD_R17_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_R17_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                ));
            hv_R17_Y = (hv_STD_R17_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_R17_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                ));

            //目前圖形 R17_ 位置
            hv_R17_Pos_Row = (hv_STD_Row + hv_R17_Y) + hv_OffsetRow;
            hv_R17_Pos_Col = (hv_STD_Col + hv_R17_X) + hv_OffsetCol;

            hv_R17_R = 17;

            ho_R17_Circle.Dispose();
            HOperatorSet.GenCircle(out ho_R17_Circle, hv_R17_Pos_Row, hv_R17_Pos_Col, hv_R17_R);
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (R17_Circle)
            }
            //stop ()

            ho_R17_ROI_Image.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_R17_Circle, out ho_R17_ROI_Image);
            ho_R17_Region.Dispose();
            HOperatorSet.FastThreshold(ho_R17_ROI_Image, out ho_R17_Region, 100, 255, 15);
            ho_R17_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_R17_ROI_Image, ho_R17_Region, out ho_R17_ImageReduced
                );
            //stop ()
            //sobel_fast 具有較寬的選擇範圍,搭配 alpha 參數 (alpha 越大, 容錯範圍大)
            hv_alpha = 0.9;
            hv_R17_low = 10;
            hv_R17_high = 60;
            ho_R17_Edges.Dispose();
            HOperatorSet.EdgesSubPix(ho_R17_ImageReduced, out ho_R17_Edges, "sobel_fast",
                hv_alpha, hv_R17_low, hv_R17_high);
            //stop ()
            //*所有的數值越小,表示容錯範圍大,反之亦然
            ho_R17_ContoursSplit.Dispose();
            HOperatorSet.SegmentContoursXld(ho_R17_Edges, out ho_R17_ContoursSplit, "lines_circles",
                17, 1, 1);
            //Display the results
            //===========================================================
            HOperatorSet.CountObj(ho_R17_ContoursSplit, out hv_R17_NumSegments);
            hv_NumCircles = 0;
            hv_Num_Circle_Point = 0;
            hv_R17 = 999;
            for (hv_i = 1; hv_i.Continue(hv_R17_NumSegments, 1); hv_i = hv_i.TupleAdd(1))
            {
                ho_R17_SingleSegment.Dispose();
                HOperatorSet.SelectObj(ho_R17_ContoursSplit, out ho_R17_SingleSegment, hv_i);
                HOperatorSet.GetContourGlobalAttribXld(ho_R17_SingleSegment, "cont_approx",
                    out hv_Attrib);
                if ((int)(new HTuple(hv_Attrib.TupleEqual(1))) != 0)
                {
                    HOperatorSet.FitCircleContourXld(ho_R17_SingleSegment, "atukey", -1, 2,
                        hv_Num_Circle_Point, 5, 2, out hv_R17_Row, out hv_R17_Column, out hv_R17_Radius,
                        out hv_R17_StartPhi, out hv_R17_EndPhi, out hv_R17_PointOrder);
                    ho_R17_ContEllipse.Dispose();
                    HOperatorSet.GenEllipseContourXld(out ho_R17_ContEllipse, hv_R17_Row, hv_R17_Column,
                        0, hv_R17_Radius, hv_R17_Radius, 0, (new HTuple(360)).TupleRad(), "positive",
                        1.0);
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.DispObj(ho_R17_ContEllipse, HDevWindowStack.GetActive());
                    }
                    HOperatorSet.DistEllipseContourXld(ho_R17_SingleSegment, "algebraic", -1,
                        0, hv_R17_Row, hv_R17_Column, 0, hv_R17_Radius, hv_R17_Radius, out hv_R17_MinDist,
                        out hv_R17_MaxDist, out hv_R17_AvgDist, out hv_R17_SigmaDist);
                    hv_NumCircles = hv_NumCircles + 1;
                    if ((int)(new HTuple(hv_R17.TupleGreater(hv_R17_Radius))) != 0)
                    {
                        hv_R17 = hv_R17_Radius.Clone();
                        mResult = new CircleResult()
                        {
                            Row = new HTuple(hv_R17_Row),
                            Col = new HTuple(hv_R17_Column),
                            Radius = new HTuple(hv_R17_Radius),
                            StartPhi = new HTuple(hv_R17_StartPhi),
                            EndPhi = new HTuple(hv_R17_EndPhi),
                            PointOrder = new HTuple(hv_R17_PointOrder),
                        };
                    }
                    //stop ()
                }
            }

            ho_R17_Circle.Dispose();
            ho_R17_ROI_Image.Dispose();
            ho_R17_Region.Dispose();
            ho_R17_ImageReduced.Dispose();
            ho_R17_Edges.Dispose();
            ho_R17_ContoursSplit.Dispose();
            ho_R17_SingleSegment.Dispose();
            ho_R17_ContEllipse.Dispose();

            return mResult;
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// disp_message函数
        /// </summary>
        /// <param name="hv_WindowHandle"></param>
        /// <param name="hv_String"></param>
        /// <param name="hv_CoordSystem"></param>
        /// <param name="hv_Row"></param>
        /// <param name="hv_Column"></param>
        /// <param name="hv_Color"></param>
        /// <param name="hv_Box"></param>m
        public static void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
                                        HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
        {
            HTuple hv_Red = null, hv_Green = null, hv_Blue = null;
            HTuple hv_Row1Part = null, hv_Column1Part = null, hv_Row2Part = null;
            HTuple hv_Column2Part = null, hv_RowWin = null, hv_ColumnWin = null;
            HTuple hv_WidthWin = null, hv_HeightWin = null, hv_MaxAscent = null;
            HTuple hv_MaxDescent = null, hv_MaxWidth = null, hv_MaxHeight = null;
            HTuple hv_R1 = new HTuple(), hv_C1 = new HTuple(), hv_FactorRow = new HTuple();
            HTuple hv_FactorColumn = new HTuple(), hv_UseShadow = null;
            HTuple hv_ShadowColor = null, hv_Exception = new HTuple();
            HTuple hv_Width = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Ascent = new HTuple(), hv_Descent = new HTuple();
            HTuple hv_W = new HTuple(), hv_H = new HTuple(), hv_FrameHeight = new HTuple();
            HTuple hv_FrameWidth = new HTuple(), hv_R2 = new HTuple();
            HTuple hv_C2 = new HTuple(), hv_DrawMode = new HTuple();
            HTuple hv_CurrentColor        = new HTuple();
            HTuple hv_Box_COPY_INP_TMP    = hv_Box.Clone();
            HTuple hv_Color_COPY_INP_TMP  = hv_Color.Clone();
            HTuple hv_Column_COPY_INP_TMP = hv_Column.Clone();
            HTuple hv_Row_COPY_INP_TMP    = hv_Row.Clone();
            HTuple hv_String_COPY_INP_TMP = hv_String.Clone();

            // Initialize local and output iconic variables


            //Prepare window
            HOperatorSet.GetRgb(hv_WindowHandle, out hv_Red, out hv_Green, out hv_Blue);
            HOperatorSet.GetPart(hv_WindowHandle, out hv_Row1Part, out hv_Column1Part, out hv_Row2Part,
                                 out hv_Column2Part);
            HOperatorSet.GetWindowExtents(hv_WindowHandle, out hv_RowWin, out hv_ColumnWin,
                                          out hv_WidthWin, out hv_HeightWin);
            HOperatorSet.SetPart(hv_WindowHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1);
            //
            //default settings
            if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0)
            {
                hv_Row_COPY_INP_TMP = 12;
            }
            if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0)
            {
                hv_Column_COPY_INP_TMP = 12;
            }
            if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0)
            {
                hv_Color_COPY_INP_TMP = "";
            }
            //
            hv_String_COPY_INP_TMP = ((("" + hv_String_COPY_INP_TMP) + "")).TupleSplit("\n");
            //
            //Estimate extentions of text depending on font size.
            HOperatorSet.GetFontExtents(hv_WindowHandle, out hv_MaxAscent, out hv_MaxDescent,
                                        out hv_MaxWidth, out hv_MaxHeight);
            if ((int)(new HTuple(hv_CoordSystem.TupleEqual("window"))) != 0)
            {
                hv_R1 = hv_Row_COPY_INP_TMP.Clone();
                hv_C1 = hv_Column_COPY_INP_TMP.Clone();
            }
            else
            {
                //Transform image to window coordinates
                hv_FactorRow    = (1.0 * hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1);
                hv_FactorColumn = (1.0 * hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1);
                hv_R1           = ((hv_Row_COPY_INP_TMP - hv_Row1Part) + 0.5) * hv_FactorRow;
                hv_C1           = ((hv_Column_COPY_INP_TMP - hv_Column1Part) + 0.5) * hv_FactorColumn;
            }
            //
            //Display text box depending on text size
            hv_UseShadow   = 1;
            hv_ShadowColor = "gray";
            if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(0))).TupleEqual("true"))) != 0)
            {
                if (hv_Box_COPY_INP_TMP == null)
                {
                    hv_Box_COPY_INP_TMP = new HTuple();
                }
                hv_Box_COPY_INP_TMP[0] = "#fce9d4";
                hv_ShadowColor         = "#f28d26";
            }
            if ((int)(new HTuple((new HTuple(hv_Box_COPY_INP_TMP.TupleLength())).TupleGreater(
                                     1))) != 0)
            {
                if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(1))).TupleEqual("true"))) != 0)
                {
                    //Use default ShadowColor set above
                }
                else if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(1))).TupleEqual(
                                              "false"))) != 0)
                {
                    hv_UseShadow = 0;
                }
                else
                {
                    hv_ShadowColor = hv_Box_COPY_INP_TMP[1];
                    //Valid color?
                    try
                    {
                        HOperatorSet.SetColor(hv_WindowHandle, hv_Box_COPY_INP_TMP.TupleSelect(
                                                  1));
                    }
                    // catch (Exception)
                    catch (HalconException HDevExpDefaultException1)
                    {
                        HDevExpDefaultException1.ToHTuple(out hv_Exception);
                        hv_Exception = "Wrong value of control parameter Box[1] (must be a 'true', 'false', or a valid color string)";
                        throw new HalconException(hv_Exception);
                    }
                }
            }
            if ((int)(new HTuple(((hv_Box_COPY_INP_TMP.TupleSelect(0))).TupleNotEqual("false"))) != 0)
            {
                //Valid color?
                try
                {
                    HOperatorSet.SetColor(hv_WindowHandle, hv_Box_COPY_INP_TMP.TupleSelect(0));
                }
                // catch (Exception)
                catch (HalconException HDevExpDefaultException1)
                {
                    HDevExpDefaultException1.ToHTuple(out hv_Exception);
                    hv_Exception = "Wrong value of control parameter Box[0] (must be a 'true', 'false', or a valid color string)";
                    throw new HalconException(hv_Exception);
                }
                //Calculate box extents
                hv_String_COPY_INP_TMP = (" " + hv_String_COPY_INP_TMP) + " ";
                hv_Width = new HTuple();
                for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                                      )) - 1); hv_Index = (int)hv_Index + 1)
                {
                    HOperatorSet.GetStringExtents(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect(
                                                      hv_Index), out hv_Ascent, out hv_Descent, out hv_W, out hv_H);
                    hv_Width = hv_Width.TupleConcat(hv_W);
                }
                hv_FrameHeight = hv_MaxHeight * (new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                            ));
                hv_FrameWidth = (((new HTuple(0)).TupleConcat(hv_Width))).TupleMax();
                hv_R2         = hv_R1 + hv_FrameHeight;
                hv_C2         = hv_C1 + hv_FrameWidth;
                //Display rectangles
                HOperatorSet.GetDraw(hv_WindowHandle, out hv_DrawMode);
                HOperatorSet.SetDraw(hv_WindowHandle, "fill");
                //Set shadow color
                HOperatorSet.SetColor(hv_WindowHandle, hv_ShadowColor);
                if ((int)(hv_UseShadow) != 0)
                {
                    HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1 + 1, hv_C1 + 1, hv_R2 + 1, hv_C2 + 1);
                }
                //Set box color
                HOperatorSet.SetColor(hv_WindowHandle, hv_Box_COPY_INP_TMP.TupleSelect(0));
                HOperatorSet.DispRectangle1(hv_WindowHandle, hv_R1, hv_C1, hv_R2, hv_C2);
                HOperatorSet.SetDraw(hv_WindowHandle, hv_DrawMode);
            }
            //Write text.
            for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
                                                                  )) - 1); hv_Index = (int)hv_Index + 1)
            {
                hv_CurrentColor = hv_Color_COPY_INP_TMP.TupleSelect(hv_Index % (new HTuple(hv_Color_COPY_INP_TMP.TupleLength()
                                                                                           )));
                if ((int)((new HTuple(hv_CurrentColor.TupleNotEqual(""))).TupleAnd(new HTuple(hv_CurrentColor.TupleNotEqual(
                                                                                                  "auto")))) != 0)
                {
                    HOperatorSet.SetColor(hv_WindowHandle, hv_CurrentColor);
                }
                else
                {
                    HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
                }
                hv_Row_COPY_INP_TMP = hv_R1 + (hv_MaxHeight * hv_Index);
                HOperatorSet.SetTposition(hv_WindowHandle, hv_Row_COPY_INP_TMP, hv_C1);
                HOperatorSet.WriteString(hv_WindowHandle, hv_String_COPY_INP_TMP.TupleSelect(
                                             hv_Index));
            }
            //Reset changed window settings
            HOperatorSet.SetRgb(hv_WindowHandle, hv_Red, hv_Green, hv_Blue);
            HOperatorSet.SetPart(hv_WindowHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part,
                                 hv_Column2Part);

            return;
        }
Exemplo n.º 29
0
        public void ForeignMaterial(HObject ho_GrayImage, out HObject ho_Contours, HTuple hv_Row,
                                    HTuple hv_Column, out HTuple hv_string, out HTuple hv_flag)
        {
            // Local iconic variables

            HObject ho_Rectangle_cut, ho_ImageReduced_cut;
            HObject ho_Region, ho_RegionErosion1, ho_ConnectedRegions1;
            HObject ho_RegionFillUp2, ho_SelectedRegions, ho_RegionDilation1;
            HObject ho_RegionFillUp, ho_RegionErosion, ho_ConnectedRegions;
            HObject ho_SelectedRegions1, ho_RegionUnion, ho_ImageReduced1;
            HObject ho_Region1;

            // Local control variables

            HTuple hv_Row_st = null, hv_Col_st = null;
            HTuple hv_UsedThreshold = null, hv_Area = null, hv_Row1 = null;
            HTuple hv_Column1 = null, hv_area = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_Rectangle_cut);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced_cut);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionErosion1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation1);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_RegionErosion);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            hv_string = "";
            hv_flag   = 0;
            hv_Row_st = hv_Row.Clone();
            hv_Col_st = hv_Column.Clone();
            ho_Rectangle_cut.Dispose();
            HOperatorSet.GenRectangle1(out ho_Rectangle_cut, hv_Row_st - 150, hv_Col_st - 200,
                                       hv_Row_st + 180, hv_Col_st + 230);
            ho_ImageReduced_cut.Dispose();
            HOperatorSet.ReduceDomain(ho_GrayImage, ho_Rectangle_cut, out ho_ImageReduced_cut
                                      );
            ho_Region.Dispose();
            HOperatorSet.BinaryThreshold(ho_ImageReduced_cut, out ho_Region, "max_separability",
                                         "light", out hv_UsedThreshold);
            ho_RegionErosion1.Dispose();
            HOperatorSet.ErosionRectangle1(ho_Region, out ho_RegionErosion1, 5, 1);
            ho_ConnectedRegions1.Dispose();
            HOperatorSet.Connection(ho_RegionErosion1, out ho_ConnectedRegions1);
            ho_RegionFillUp2.Dispose();
            HOperatorSet.FillUp(ho_ConnectedRegions1, out ho_RegionFillUp2);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_RegionFillUp2, out ho_SelectedRegions, (new HTuple("width")).TupleConcat(
                                         "area"), "and", (new HTuple(100)).TupleConcat(2000), (new HTuple(400)).TupleConcat(
                                         999999));
            ho_RegionDilation1.Dispose();
            HOperatorSet.DilationCircle(ho_SelectedRegions, out ho_RegionDilation1, 3);
            ho_RegionFillUp.Dispose();
            HOperatorSet.FillUp(ho_RegionDilation1, out ho_RegionFillUp);
            ho_RegionErosion.Dispose();
            HOperatorSet.ErosionCircle(ho_RegionFillUp, out ho_RegionErosion, 7);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_RegionErosion, out ho_ConnectedRegions);
            ho_SelectedRegions1.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions1, (new HTuple("width")).TupleConcat(
                                         "area"), "and", (new HTuple(100)).TupleConcat(2000), (new HTuple(400)).TupleConcat(
                                         999999));
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions1, out ho_RegionUnion);
            ho_ImageReduced1.Dispose();
            HOperatorSet.ReduceDomain(ho_GrayImage, ho_RegionUnion, out ho_ImageReduced1);
            ho_Region1.Dispose();
            HOperatorSet.Threshold(ho_ImageReduced1, out ho_Region1, 0, 40);
            HOperatorSet.AreaCenter(ho_Region1, out hv_Area, out hv_Row1, out hv_Column1);
            ho_Contours.Dispose();
            HOperatorSet.GenContourRegionXld(ho_Region1, out ho_Contours, "border");
            hv_area = hv_Area.TupleSum();
            if ((int)(new HTuple(hv_area.TupleGreater(100))) != 0)
            {
                hv_string = "Foreign material";
                hv_flag   = 2;

                //错误2:外来物检测
            }
            else
            {
                hv_flag = 1;
            }
            ho_Rectangle_cut.Dispose();
            ho_ImageReduced_cut.Dispose();
            ho_Region.Dispose();
            ho_RegionErosion1.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_RegionFillUp2.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionDilation1.Dispose();
            ho_RegionFillUp.Dispose();
            ho_RegionErosion.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_RegionUnion.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Region1.Dispose();

            return;
        }
        private void action()
        {
            // Local iconic variables

            HObject ho_Rectangle, ho_ImageReduced;
            HObject ho_Region, ho_Rectangle2q, ho_ImageReduced2, ho_Region1;
            HObject ho_ConnectedRegions, ho_SelectedRegions, ho_Rectangle2w;

            // Local control variables

            HTuple hv_Ro1 = null, hv_Col1 = null, hv_Ro2 = null;
            HTuple hv_Col2 = null, hv_Rowq1 = null, hv_Columnq1 = null;
            HTuple hv_Phiq2 = null, hv_Length1q2 = null, hv_Length2q2 = null;
            HTuple hv_Roww1 = null, hv_Columnw1 = null, hv_Phiw2 = null;
            HTuple hv_Length1w2 = null, hv_Length2w2 = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2q);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced2);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2w);
            HOperatorSet.Union1(algorithm.Region, out RegionToDisp);
            try
            {
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle1(out ho_Rectangle, hv_centerRowm1, hv_centerColumnm1, hv_centerRowm2, hv_centerColumnm2);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Rectangle, out ho_ImageReduced);
                //*reduce_domain(Image, Rectangle1, ImageReduced1)
                //*reduce_domain(Image, Rectangle2, ImageReduced2)
                //*intensity(Rectangle, ImageReduced, M1, D1)
                ho_Region.Dispose();
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 200, 255);
                HOperatorSet.SmallestRectangle2(ho_Region, out hv_Rowq1, out hv_Columnq1, out hv_Phiq2,
                                                out hv_Length1q2, out hv_Length2q2);
                ho_Rectangle2q.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle2q, hv_Rowq1, hv_Columnq1, hv_Phiq2,
                                           hv_Length1q2, hv_Length2q2);
                ho_ImageReduced2.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Rectangle2q, out ho_ImageReduced2);
                ho_Region1.Dispose();
                HOperatorSet.Threshold(ho_ImageReduced2, out ho_Region1, 0, 60);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions);
                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", 1500, 999990000);

                //*threshold(ImageReduced2, Region1, 0, 128)
                HOperatorSet.SmallestRectangle2(ho_SelectedRegions, out hv_Roww1, out hv_Columnw1,
                                                out hv_Phiw2, out hv_Length1w2, out hv_Length2w2);
                ho_Rectangle2w.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle2w, hv_Roww1, hv_Columnw1, hv_Phiw2,
                                           hv_Length1w2, hv_Length2w2);
                HOperatorSet.Union1(ho_Rectangle2w, out RegionToDisp);
                //}

                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("高度");
                hv_result = hv_result.TupleConcat(hv_Length2w2.D * pixeldist * 2);
                hv_result = hv_result.TupleConcat("高度");
                hv_result = hv_result.TupleConcat(hv_Length1w2.D * pixeldist * 2);
                result    = hv_result.Clone();

                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_Rectangle2q.Dispose();
                ho_ImageReduced2.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_Rectangle2w.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);
                result    = hv_result.Clone();

                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_Rectangle2q.Dispose();
                ho_ImageReduced2.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_Rectangle2w.Dispose();
                algorithm.Region.Dispose();
            }
        }
Exemplo n.º 31
0
        public MeasureResult Action()
        {
            #region 輸出結果
            CircleResult mResult = null;
            #endregion

            // Local iconic variables

            HObject ho_R19_Circle = null;
            HObject ho_R19_ROI_Image = null, ho_R19_Region = null, ho_R19_ImageReduced = null;
            HObject ho_R19_Edges = null, ho_R19_ContoursSplit = null, ho_R19_SingleSegment = null;
            HObject ho_R19_ContEllipse = null;


            // Local control variables

            HTuple hv_msgOffsetY, hv_msgOffsetX;
            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol, hv_STD_R19_Row, hv_STD_R19_Col;
            HTuple hv_STD_R19_V_Row, hv_STD_R19_V_Col, hv_R19_X, hv_R19_Y;
            HTuple hv_R19_Pos_Row, hv_R19_Pos_Col, hv_R19_R;
            HTuple hv_alpha = new HTuple(), hv_R19_low = new HTuple();
            HTuple hv_R19_high = new HTuple(), hv_R19_NumSegments = new HTuple();
            HTuple hv_NumCircles = new HTuple(), hv_Num_Circle_Point = new HTuple();
            HTuple hv_R19 = new HTuple(), hv_i = new HTuple(), hv_Attrib = new HTuple();
            HTuple hv_R19_Row = new HTuple(), hv_R19_Column = new HTuple();
            HTuple hv_R19_Radius = new HTuple(), hv_R19_StartPhi = new HTuple();
            HTuple hv_R19_EndPhi = new HTuple(), hv_R19_PointOrder = new HTuple();
            HTuple hv_R19_MinDist = new HTuple(), hv_R19_MaxDist = new HTuple();
            HTuple hv_R19_AvgDist = new HTuple(), hv_R19_SigmaDist = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_R19_Circle);
            HOperatorSet.GenEmptyObj(out ho_R19_ROI_Image);
            HOperatorSet.GenEmptyObj(out ho_R19_Region);
            HOperatorSet.GenEmptyObj(out ho_R19_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_R19_Edges);
            HOperatorSet.GenEmptyObj(out ho_R19_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_R19_SingleSegment);
            HOperatorSet.GenEmptyObj(out ho_R19_ContEllipse);

            //Measure: SDMS_R19
            //Author: John Hsieh
            //Date: 2012

            HOperatorSet.SetSystem("border_shape_models", "false");

            //****Message Args
            hv_msgOffsetY = 100;
            hv_msgOffsetX = 100;


            //****Model Args

            //STD 中心點
            hv_STD_Row = 772;
            hv_STD_Col = 1003;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //****Display
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }

            //****R19
            //STD R19_ 位置
            hv_STD_R19_Row = 794;
            hv_STD_R19_Col = 620;

            //STD 向量 STD_R19_
            hv_STD_R19_V_Row = hv_STD_R19_Row - hv_STD_Row;
            hv_STD_R19_V_Col = hv_STD_R19_Col - hv_STD_Col;


            //R19_X, R19_Y 分量
            hv_R19_X = (hv_STD_R19_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_R19_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                                                                                                    ));
            hv_R19_Y = (hv_STD_R19_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_R19_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                                                                                                    ));


            //目前圖形 R19_ 位置
            hv_R19_Pos_Row = (hv_STD_Row + hv_R19_Y) + hv_OffsetRow;
            hv_R19_Pos_Col = (hv_STD_Col + hv_R19_X) + hv_OffsetCol;

            hv_R19_R = 15;

            ho_R19_Circle.Dispose();
            HOperatorSet.GenCircle(out ho_R19_Circle, hv_R19_Pos_Row, hv_R19_Pos_Col, hv_R19_R);

            if (HDevWindowStack.IsOpen())
            {
                //dev_display (R19_Circle)
            }
            //stop ()
            ho_R19_ROI_Image.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_R19_Circle, out ho_R19_ROI_Image);
            ho_R19_Region.Dispose();
            HOperatorSet.FastThreshold(ho_R19_ROI_Image, out ho_R19_Region, 100, 255, 15);
            ho_R19_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_R19_ROI_Image, ho_R19_Region, out ho_R19_ImageReduced
                                      );
            //stop ()
            //sobel_fast 具有較寬的選擇範圍,搭配 alpha 參數 (alpha 越大, 容錯範圍大)
            hv_alpha    = 0.9;
            hv_R19_low  = 2;
            hv_R19_high = 60;
            ho_R19_Edges.Dispose();
            HOperatorSet.EdgesSubPix(ho_R19_ImageReduced, out ho_R19_Edges, "sobel_fast",
                                     hv_alpha, hv_R19_low, hv_R19_high);
            //stop ()
            //*所有的數值越小,表示容錯範圍大,反之亦然
            ho_R19_ContoursSplit.Dispose();
            HOperatorSet.SegmentContoursXld(ho_R19_Edges, out ho_R19_ContoursSplit, "lines_circles",
                                            17, 1, 1);
            //Display the results
            //===========================================================
            HOperatorSet.CountObj(ho_R19_ContoursSplit, out hv_R19_NumSegments);
            hv_NumCircles       = 0;
            hv_Num_Circle_Point = 0;
            hv_R19 = 999;
            for (hv_i = 1; hv_i.Continue(hv_R19_NumSegments, 1); hv_i = hv_i.TupleAdd(1))
            {
                ho_R19_SingleSegment.Dispose();
                HOperatorSet.SelectObj(ho_R19_ContoursSplit, out ho_R19_SingleSegment, hv_i);
                HOperatorSet.GetContourGlobalAttribXld(ho_R19_SingleSegment, "cont_approx",
                                                       out hv_Attrib);
                if ((int)(new HTuple(hv_Attrib.TupleEqual(1))) != 0)
                {
                    HOperatorSet.FitCircleContourXld(ho_R19_SingleSegment, "atukey", -1, 2,
                                                     hv_Num_Circle_Point, 5, 2, out hv_R19_Row, out hv_R19_Column, out hv_R19_Radius,
                                                     out hv_R19_StartPhi, out hv_R19_EndPhi, out hv_R19_PointOrder);
                    ho_R19_ContEllipse.Dispose();
                    HOperatorSet.GenEllipseContourXld(out ho_R19_ContEllipse, hv_R19_Row, hv_R19_Column,
                                                      0, hv_R19_Radius, hv_R19_Radius, 0, (new HTuple(360)).TupleRad(), "positive",
                                                      1.0);
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.DispObj(ho_R19_ContEllipse, HDevWindowStack.GetActive());
                    }
                    HOperatorSet.DistEllipseContourXld(ho_R19_SingleSegment, "algebraic", -1,
                                                       0, hv_R19_Row, hv_R19_Column, 0, hv_R19_Radius, hv_R19_Radius, out hv_R19_MinDist,
                                                       out hv_R19_MaxDist, out hv_R19_AvgDist, out hv_R19_SigmaDist);
                    hv_NumCircles = hv_NumCircles + 1;
                    if ((int)(new HTuple(hv_R19.TupleGreater(hv_R19_Radius))) != 0)
                    {
                        hv_R19  = hv_R19_Radius.Clone();
                        mResult = new CircleResult()
                        {
                            Row        = new HTuple(hv_R19_Row),
                            Col        = new HTuple(hv_R19_Column),
                            Radius     = new HTuple(hv_R19_Radius),
                            StartPhi   = new HTuple(hv_R19_StartPhi),
                            EndPhi     = new HTuple(hv_R19_EndPhi),
                            PointOrder = new HTuple(hv_R19_PointOrder),
                        };
                    }
                }
            }
            ho_R19_Circle.Dispose();
            ho_R19_ROI_Image.Dispose();
            ho_R19_Region.Dispose();
            ho_R19_ImageReduced.Dispose();
            ho_R19_Edges.Dispose();
            ho_R19_ContoursSplit.Dispose();
            ho_R19_SingleSegment.Dispose();
            ho_R19_ContEllipse.Dispose();


            return(mResult);
        }
Exemplo n.º 32
0
    // Chapter: Graphics / Text
    // Short Description: Set font independent of OS
    public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font,
                                 HTuple hv_Bold, HTuple hv_Slant)
    {
        // Local iconic variables

        // Local control variables

        HTuple hv_OS = null, hv_BufferWindowHandle = new HTuple();
        HTuple hv_Ascent = new HTuple(), hv_Descent = new HTuple();
        HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
        HTuple hv_Scale = new HTuple(), hv_Exception = new HTuple();
        HTuple hv_SubFamily = new HTuple(), hv_Fonts = new HTuple();
        HTuple hv_SystemFonts = new HTuple(), hv_Guess = new HTuple();
        HTuple hv_I = new HTuple(), hv_Index = new HTuple(), hv_AllowedFontSizes = new HTuple();
        HTuple hv_Distances = new HTuple(), hv_Indices = new HTuple();
        HTuple hv_FontSelRegexp = new HTuple(), hv_FontsCourier = new HTuple();
        HTuple hv_Bold_COPY_INP_TMP  = hv_Bold.Clone();
        HTuple hv_Font_COPY_INP_TMP  = hv_Font.Clone();
        HTuple hv_Size_COPY_INP_TMP  = hv_Size.Clone();
        HTuple hv_Slant_COPY_INP_TMP = hv_Slant.Clone();

        // Initialize local and output iconic variables
        //This procedure sets the text font of the current window with
        //the specified attributes.
        //It is assumed that following fonts are installed on the system:
        //Windows: Courier New, Arial Times New Roman
        //Mac OS X: CourierNewPS, Arial, TimesNewRomanPS
        //Linux: courier, helvetica, times
        //Because fonts are displayed smaller on Linux than on Windows,
        //a scaling factor of 1.25 is used the get comparable results.
        //For Linux, only a limited number of font sizes is supported,
        //to get comparable results, it is recommended to use one of the
        //following sizes: 9, 11, 14, 16, 20, 27
        //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
        //
        //Input parameters:
        //WindowHandle: The graphics window for which the font will be set
        //Size: The font size. If Size=-1, the default of 16 is used.
        //Bold: If set to 'true', a bold font is used
        //Slant: If set to 'true', a slanted font is used
        //
        HOperatorSet.GetSystem("operating_system", out hv_OS);
        // dev_get_preferences(...); only in hdevelop
        // dev_set_preferences(...); only in hdevelop
        if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
                      new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0)
        {
            hv_Size_COPY_INP_TMP = 16;
        }
        if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0)
        {
            //Set font on Windows systems
            try
            {
                //Check, if font scaling is switched on
                //open_window(...);
                HOperatorSet.SetFont(hv_ExpDefaultWinHandle, "-Consolas-16-*-0-*-*-1-");
                HOperatorSet.GetStringExtents(hv_ExpDefaultWinHandle, "test_string", out hv_Ascent,
                                              out hv_Descent, out hv_Width, out hv_Height);
                //Expected width is 110
                hv_Scale             = 110.0 / hv_Width;
                hv_Size_COPY_INP_TMP = ((hv_Size_COPY_INP_TMP * hv_Scale)).TupleInt();
                //close_window(...);
            }
            // catch (Exception)
            catch (HalconException HDevExpDefaultException1)
            {
                HDevExpDefaultException1.ToHTuple(out hv_Exception);
                //throw (Exception)
            }
            if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))).TupleOr(
                          new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Courier New";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Consolas";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Arial";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "Times New Roman";
            }
            if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = 1;
            }
            else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = 0;
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Bold";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_Slant_COPY_INP_TMP = 1;
            }
            else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Slant_COPY_INP_TMP = 0;
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Slant";
                throw new HalconException(hv_Exception);
            }
            try
            {
                HOperatorSet.SetFont(hv_ExpDefaultWinHandle, ((((((("-" + hv_Font_COPY_INP_TMP) + "-") + hv_Size_COPY_INP_TMP) + "-*-") + hv_Slant_COPY_INP_TMP) + "-*-*-") + hv_Bold_COPY_INP_TMP) + "-");
            }
            // catch (Exception)
            catch (HalconException HDevExpDefaultException1)
            {
                HDevExpDefaultException1.ToHTuple(out hv_Exception);
                //throw (Exception)
            }
        }
        else if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Dar"))) != 0)
        {
            //Set font on Mac OS X systems. Since OS X does not have a strict naming
            //scheme for font attributes, we use tables to determine the correct font
            //name.
            hv_SubFamily = 0;
            if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_SubFamily = hv_SubFamily.TupleBor(1);
            }
            else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleNotEqual("false"))) != 0)
            {
                hv_Exception = "Wrong value of control parameter Slant";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_SubFamily = hv_SubFamily.TupleBor(2);
            }
            else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleNotEqual("false"))) != 0)
            {
                hv_Exception = "Wrong value of control parameter Bold";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "Menlo-Regular";
                hv_Fonts[1] = "Menlo-Italic";
                hv_Fonts[2] = "Menlo-Bold";
                hv_Fonts[3] = "Menlo-BoldItalic";
            }
            else if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))).TupleOr(
                               new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "CourierNewPSMT";
                hv_Fonts[1] = "CourierNewPS-ItalicMT";
                hv_Fonts[2] = "CourierNewPS-BoldMT";
                hv_Fonts[3] = "CourierNewPS-BoldItalicMT";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "ArialMT";
                hv_Fonts[1] = "Arial-ItalicMT";
                hv_Fonts[2] = "Arial-BoldMT";
                hv_Fonts[3] = "Arial-BoldItalicMT";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
            {
                hv_Fonts    = new HTuple();
                hv_Fonts[0] = "TimesNewRomanPSMT";
                hv_Fonts[1] = "TimesNewRomanPS-ItalicMT";
                hv_Fonts[2] = "TimesNewRomanPS-BoldMT";
                hv_Fonts[3] = "TimesNewRomanPS-BoldItalicMT";
            }
            else
            {
                //Attempt to figure out which of the fonts installed on the system
                //the user could have meant.
                HOperatorSet.QueryFont(hv_ExpDefaultWinHandle, out hv_SystemFonts);
                hv_Fonts = new HTuple();
                hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP);
                hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP);
                hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP);
                hv_Fonts = hv_Fonts.TupleConcat(hv_Font_COPY_INP_TMP);
                hv_Guess = new HTuple();
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP);
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Regular");
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "MT");
                for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1)
                {
                    HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index);
                    if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0)
                    {
                        if (hv_Fonts == null)
                        {
                            hv_Fonts = new HTuple();
                        }
                        hv_Fonts[0] = hv_Guess.TupleSelect(hv_I);
                        break;
                    }
                }
                //Guess name of slanted font
                hv_Guess = new HTuple();
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Italic");
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-ItalicMT");
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Oblique");
                for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1)
                {
                    HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index);
                    if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0)
                    {
                        if (hv_Fonts == null)
                        {
                            hv_Fonts = new HTuple();
                        }
                        hv_Fonts[1] = hv_Guess.TupleSelect(hv_I);
                        break;
                    }
                }
                //Guess name of bold font
                hv_Guess = new HTuple();
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-Bold");
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldMT");
                for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1)
                {
                    HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index);
                    if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0)
                    {
                        if (hv_Fonts == null)
                        {
                            hv_Fonts = new HTuple();
                        }
                        hv_Fonts[2] = hv_Guess.TupleSelect(hv_I);
                        break;
                    }
                }
                //Guess name of bold slanted font
                hv_Guess = new HTuple();
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldItalic");
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldItalicMT");
                hv_Guess = hv_Guess.TupleConcat(hv_Font_COPY_INP_TMP + "-BoldOblique");
                for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Guess.TupleLength())) - 1); hv_I = (int)hv_I + 1)
                {
                    HOperatorSet.TupleFind(hv_SystemFonts, hv_Guess.TupleSelect(hv_I), out hv_Index);
                    if ((int)(new HTuple(hv_Index.TupleNotEqual(-1))) != 0)
                    {
                        if (hv_Fonts == null)
                        {
                            hv_Fonts = new HTuple();
                        }
                        hv_Fonts[3] = hv_Guess.TupleSelect(hv_I);
                        break;
                    }
                }
            }
            hv_Font_COPY_INP_TMP = hv_Fonts.TupleSelect(hv_SubFamily);
            try
            {
                HOperatorSet.SetFont(hv_ExpDefaultWinHandle, (hv_Font_COPY_INP_TMP + "-") + hv_Size_COPY_INP_TMP);
            }
            // catch (Exception)
            catch (HalconException HDevExpDefaultException1)
            {
                HDevExpDefaultException1.ToHTuple(out hv_Exception);
                //throw (Exception)
            }
        }
        else
        {
            //Set font for UNIX systems
            hv_Size_COPY_INP_TMP   = hv_Size_COPY_INP_TMP * 1.25;
            hv_AllowedFontSizes    = new HTuple();
            hv_AllowedFontSizes[0] = 11;
            hv_AllowedFontSizes[1] = 14;
            hv_AllowedFontSizes[2] = 17;
            hv_AllowedFontSizes[3] = 20;
            hv_AllowedFontSizes[4] = 25;
            hv_AllowedFontSizes[5] = 34;
            if ((int)(new HTuple(((hv_AllowedFontSizes.TupleFind(hv_Size_COPY_INP_TMP))).TupleEqual(
                                     -1))) != 0)
            {
                hv_Distances = ((hv_AllowedFontSizes - hv_Size_COPY_INP_TMP)).TupleAbs();
                HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices);
                hv_Size_COPY_INP_TMP = hv_AllowedFontSizes.TupleSelect(hv_Indices.TupleSelect(
                                                                           0));
            }
            if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(
                                                                                                   "Courier")))) != 0)
            {
                hv_Font_COPY_INP_TMP = "courier";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "helvetica";
            }
            else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
            {
                hv_Font_COPY_INP_TMP = "times";
            }
            if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = "bold";
            }
            else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Bold_COPY_INP_TMP = "medium";
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Bold";
                throw new HalconException(hv_Exception);
            }
            if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
            {
                if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("times"))) != 0)
                {
                    hv_Slant_COPY_INP_TMP = "i";
                }
                else
                {
                    hv_Slant_COPY_INP_TMP = "o";
                }
            }
            else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
            {
                hv_Slant_COPY_INP_TMP = "r";
            }
            else
            {
                hv_Exception = "Wrong value of control parameter Slant";
                throw new HalconException(hv_Exception);
            }
            try
            {
                HOperatorSet.SetFont(hv_ExpDefaultWinHandle, ((((((("-adobe-" + hv_Font_COPY_INP_TMP) + "-") + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*");
            }
            // catch (Exception)
            catch (HalconException HDevExpDefaultException1)
            {
                HDevExpDefaultException1.ToHTuple(out hv_Exception);
                if ((int)((new HTuple(((hv_OS.TupleSubstr(0, 4))).TupleEqual("Linux"))).TupleAnd(
                              new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0)
                {
                    HOperatorSet.QueryFont(hv_ExpDefaultWinHandle, out hv_Fonts);
                    hv_FontSelRegexp = (("^-[^-]*-[^-]*[Cc]ourier[^-]*-" + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP;
                    hv_FontsCourier  = ((hv_Fonts.TupleRegexpSelect(hv_FontSelRegexp))).TupleRegexpMatch(
                        hv_FontSelRegexp);
                    if ((int)(new HTuple((new HTuple(hv_FontsCourier.TupleLength())).TupleEqual(
                                             0))) != 0)
                    {
                        hv_Exception = "Wrong font name";
                        //throw (Exception)
                    }
                    else
                    {
                        try
                        {
                            HOperatorSet.SetFont(hv_ExpDefaultWinHandle, (((hv_FontsCourier.TupleSelect(
                                                                                0)) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*");
                        }
                        // catch (Exception)
                        catch (HalconException HDevExpDefaultException2)
                        {
                            HDevExpDefaultException2.ToHTuple(out hv_Exception);
                            //throw (Exception)
                        }
                    }
                }
                //throw (Exception)
            }
        }
        // dev_set_preferences(...); only in hdevelop

        return;
    }
Exemplo n.º 33
0
    // Procedures
    // External procedures
    // Chapter: Develop
    // Short Description: Open a new graphics window that preserves the aspect ratio of the given image.
    public void dev_open_window_fit_image(HObject ho_Image, HTuple hv_Row, HTuple hv_Column,
                                          HTuple hv_WidthLimit, HTuple hv_HeightLimit, out HTuple hv_WindowHandle)
    {
        // Local control variables

        HTuple hv_MinWidth = new HTuple(), hv_MaxWidth = new HTuple();
        HTuple hv_MinHeight = new HTuple(), hv_MaxHeight = new HTuple();
        HTuple hv_ResizeFactor, hv_ImageWidth, hv_ImageHeight;
        HTuple hv_TempWidth, hv_TempHeight, hv_WindowWidth, hv_WindowHeight;

        // Initialize local and output iconic variables

        //This procedure opens a new graphics window and adjusts the size
        //such that it fits into the limits specified by WidthLimit
        //and HeightLimit, but also maintains the correct image aspect ratio.
        //
        //If it is impossible to match the minimum and maximum extent requirements
        //at the same time (f.e. if the image is very long but narrow),
        //the maximum value gets a higher priority,
        //
        //Parse input tuple WidthLimit
        if ((int)((new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual(0))).TupleOr(
                      new HTuple(hv_WidthLimit.TupleLess(0)))) != 0)
        {
            hv_MinWidth = 500;
            hv_MaxWidth = 800;
        }
        else if ((int)(new HTuple((new HTuple(hv_WidthLimit.TupleLength())).TupleEqual(
                                      1))) != 0)
        {
            hv_MinWidth = 0;
            hv_MaxWidth = hv_WidthLimit.Clone();
        }
        else
        {
            hv_MinWidth = hv_WidthLimit[0];
            hv_MaxWidth = hv_WidthLimit[1];
        }
        //Parse input tuple HeightLimit
        if ((int)((new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual(0))).TupleOr(
                      new HTuple(hv_HeightLimit.TupleLess(0)))) != 0)
        {
            hv_MinHeight = 400;
            hv_MaxHeight = 600;
        }
        else if ((int)(new HTuple((new HTuple(hv_HeightLimit.TupleLength())).TupleEqual(
                                      1))) != 0)
        {
            hv_MinHeight = 0;
            hv_MaxHeight = hv_HeightLimit.Clone();
        }
        else
        {
            hv_MinHeight = hv_HeightLimit[0];
            hv_MaxHeight = hv_HeightLimit[1];
        }
        //
        //Test, if window size has to be changed.
        hv_ResizeFactor = 1;
        HOperatorSet.GetImageSize(ho_Image, out hv_ImageWidth, out hv_ImageHeight);
        //First, expand window to the minimum extents (if necessary).
        if ((int)((new HTuple(hv_MinWidth.TupleGreater(hv_ImageWidth))).TupleOr(new HTuple(hv_MinHeight.TupleGreater(
                                                                                               hv_ImageHeight)))) != 0)
        {
            hv_ResizeFactor = (((((hv_MinWidth.TupleReal()) / hv_ImageWidth)).TupleConcat(
                                    (hv_MinHeight.TupleReal()) / hv_ImageHeight))).TupleMax();
        }
        hv_TempWidth  = hv_ImageWidth * hv_ResizeFactor;
        hv_TempHeight = hv_ImageHeight * hv_ResizeFactor;
        //Then, shrink window to maximum extents (if necessary).
        if ((int)((new HTuple(hv_MaxWidth.TupleLess(hv_TempWidth))).TupleOr(new HTuple(hv_MaxHeight.TupleLess(
                                                                                           hv_TempHeight)))) != 0)
        {
            hv_ResizeFactor = hv_ResizeFactor * ((((((hv_MaxWidth.TupleReal()) / hv_TempWidth)).TupleConcat(
                                                       (hv_MaxHeight.TupleReal()) / hv_TempHeight))).TupleMin());
        }
        hv_WindowWidth  = hv_ImageWidth * hv_ResizeFactor;
        hv_WindowHeight = hv_ImageHeight * hv_ResizeFactor;
        //Resize window
        HOperatorSet.SetWindowAttr("background_color", "black");
        HOperatorSet.OpenWindow(hv_Row, hv_Column, hv_WindowWidth, hv_WindowHeight, 0, "", "", out hv_WindowHandle);
        HDevWindowStack.Push(hv_WindowHandle);
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.SetPart(HDevWindowStack.GetActive(), 0, 0, hv_ImageHeight - 1, hv_ImageWidth - 1);
        }

        return;
    }
Exemplo n.º 34
0
        public MeasureResult Action()
        {
            #region 輸出結果
            CircleResult mResult = null;
            #endregion
            // Local iconic variables

            HObject ho_R6_Circle = null;
            HObject ho_R6_ROI_Image = null, ho_R6_Region = null, ho_R6_RegionBorder = null;
            HObject ho_R6_RegionDilation = null, ho_R6_ImageReduced = null;
            HObject ho_R6_Edges = null, ho_R6_ContoursSplit = null, ho_R6_SingleSegment = null;
            HObject ho_R6_ContEllipse = null;

            // Local control variables

            HTuple hv_msgOffsetY, hv_msgOffsetX;
            HTuple hv_STD_Row;
            HTuple hv_STD_Col, hv_Img_Row, hv_Img_Col, hv_Img_Rotate_Angle;
            HTuple hv_OffsetRow, hv_OffsetCol, hv_R6;
            HTuple hv_STD_R6_Row = new HTuple(), hv_STD_R6_Col = new HTuple();
            HTuple hv_STD_R6_V_Row = new HTuple(), hv_STD_R6_V_Col = new HTuple();
            HTuple hv_R6_X = new HTuple(), hv_R6_Y = new HTuple(), hv_R6_Pos_Row = new HTuple();
            HTuple hv_R6_Pos_Col = new HTuple(), hv_R6_R = new HTuple();
            HTuple hv_R6_R_Max = new HTuple(), hv_R6_R_Inc = new HTuple();
            HTuple hv_R6_NumSegments = new HTuple(), hv_NumCircles = new HTuple();
            HTuple hv_Num_Circle_Point = new HTuple(), hv_i = new HTuple();
            HTuple hv_Attrib = new HTuple(), hv_R6_Row = new HTuple();
            HTuple hv_R6_Column = new HTuple(), hv_R6_Radius = new HTuple();
            HTuple hv_R6_StartPhi = new HTuple(), hv_R6_EndPhi = new HTuple();
            HTuple hv_R6_PointOrder = new HTuple(), hv_R6_MinDist = new HTuple();
            HTuple hv_R6_MaxDist = new HTuple(), hv_R6_AvgDist = new HTuple();
            HTuple hv_R6_SigmaDist = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_R6_Circle);
            HOperatorSet.GenEmptyObj(out ho_R6_ROI_Image);
            HOperatorSet.GenEmptyObj(out ho_R6_Region);
            HOperatorSet.GenEmptyObj(out ho_R6_RegionBorder);
            HOperatorSet.GenEmptyObj(out ho_R6_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_R6_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_R6_Edges);
            HOperatorSet.GenEmptyObj(out ho_R6_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_R6_SingleSegment);
            HOperatorSet.GenEmptyObj(out ho_R6_ContEllipse);

            //Measure: SDMS_R6
            //Author: John Hsieh
            //Date: 2012
            // dev_update_off(...); only in hdevelop
            HOperatorSet.SetSystem("border_shape_models", "false");

            //****Message Args
            hv_msgOffsetY = 100;
            hv_msgOffsetX = 100;

            //****Model Args

            //STD 中心點
            hv_STD_Row = 772;
            hv_STD_Col = 1003;

            //目前圖形 中心點
            hv_Img_Row = hv_AllModelRow.Clone();
            hv_Img_Col = hv_AllModelColumn.Clone();

            //目前圖形 Rotate Angle
            hv_Img_Rotate_Angle = hv_AllModelAngle.Clone();

            //目前圖形偏移量
            hv_OffsetRow = hv_Img_Row - hv_STD_Row;
            hv_OffsetCol = hv_Img_Col - hv_STD_Col;

            //****Display
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            //*****R6
            hv_R6 = 999;
            //STD R6_ 位置
            hv_STD_R6_Row = 1292;
            hv_STD_R6_Col = 639;

            //STD 向量 STD_R6_
            hv_STD_R6_V_Row = hv_STD_R6_Row - hv_STD_Row;
            hv_STD_R6_V_Col = hv_STD_R6_Col - hv_STD_Col;

            //R6_X, R6_Y 分量
            hv_R6_X = (hv_STD_R6_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_R6_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                ));
            hv_R6_Y = (hv_STD_R6_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_R6_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                ));

            //目前圖形 R4 位置
            hv_R6_Pos_Row = (hv_STD_Row + hv_R6_Y) + hv_OffsetRow;
            hv_R6_Pos_Col = (hv_STD_Col + hv_R6_X) + hv_OffsetCol;

            //R6_Region 由半徑 29 開始搜尋, 最大搜尋至 41, Inc =2
            hv_R6_R = 29;
            hv_R6_R_Max = 41;
            hv_R6_R_Inc = 2;
            while ((int)((new HTuple(hv_R6.TupleEqual(999))).TupleAnd(new HTuple(hv_R6_R.TupleLess(
                hv_R6_R_Max)))) != 0)
            {
                //*******************************
                ho_R6_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_R6_Circle, hv_R6_Pos_Row, hv_R6_Pos_Col, hv_R6_R);
                ho_R6_ROI_Image.Dispose();
                HOperatorSet.ReduceDomain(ho_Image, ho_R6_Circle, out ho_R6_ROI_Image);
                ho_R6_Region.Dispose();
                HOperatorSet.Threshold(ho_R6_ROI_Image, out ho_R6_Region, 100, 255);
                ho_R6_RegionBorder.Dispose();
                HOperatorSet.Boundary(ho_R6_Region, out ho_R6_RegionBorder, "inner");
                ho_R6_RegionDilation.Dispose();
                HOperatorSet.DilationCircle(ho_R6_RegionBorder, out ho_R6_RegionDilation,
                    1.5);
                ho_R6_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(ho_R6_ROI_Image, ho_R6_RegionDilation, out ho_R6_ImageReduced
                    );
                ho_R6_Edges.Dispose();
                HOperatorSet.EdgesSubPix(ho_R6_ImageReduced, out ho_R6_Edges, "lanser2",
                    0.3, 40, 90);

                //fast_threshold (R6_ROI_Image, R6_Region, 80, 255, 15)
                //reduce_domain (R6_ROI_Image, R6_Region, R6_ImageReduced)
                //sobel_fast 具有較寬的選擇範圍,搭配 alpha 參數 (alpha 越大, 容錯範圍大)
                //alpha := 10
                //R6_low := 10
                //R6_high := 60
                //edges_sub_pix (R6_ImageReduced, R6_Edges, 'sobel_fast', alpha, R6_low, R6_high)
                //stop ()
                //*所有的數值越小,表示容錯範圍大,反之亦然
                ho_R6_ContoursSplit.Dispose();
                HOperatorSet.SegmentContoursXld(ho_R6_Edges, out ho_R6_ContoursSplit, "lines_circles",
                    6, 4, 4);

                //Display the results
                //===========================================================
                HOperatorSet.CountObj(ho_R6_ContoursSplit, out hv_R6_NumSegments);
                hv_NumCircles = 0;
                hv_Num_Circle_Point = 0;
                for (hv_i = 1; hv_i.Continue(hv_R6_NumSegments, 1); hv_i = hv_i.TupleAdd(1))
                {
                    ho_R6_SingleSegment.Dispose();
                    HOperatorSet.SelectObj(ho_R6_ContoursSplit, out ho_R6_SingleSegment, hv_i);
                    HOperatorSet.GetContourGlobalAttribXld(ho_R6_SingleSegment, "cont_approx",
                        out hv_Attrib);
                    if ((int)(new HTuple(hv_Attrib.TupleEqual(1))) != 0)
                    {
                        HOperatorSet.FitCircleContourXld(ho_R6_SingleSegment, "atukey", -1, 2,
                            hv_Num_Circle_Point, 5, 2, out hv_R6_Row, out hv_R6_Column, out hv_R6_Radius,
                            out hv_R6_StartPhi, out hv_R6_EndPhi, out hv_R6_PointOrder);
                        ho_R6_ContEllipse.Dispose();
                        HOperatorSet.GenEllipseContourXld(out ho_R6_ContEllipse, hv_R6_Row, hv_R6_Column,
                            0, hv_R6_Radius, hv_R6_Radius, 0, (new HTuple(360)).TupleRad(), "positive",
                            1.0);
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.DispObj(ho_R6_ContEllipse, HDevWindowStack.GetActive()
                                );
                        }
                        HOperatorSet.DistEllipseContourXld(ho_R6_SingleSegment, "algebraic",
                            -1, 0, hv_R6_Row, hv_R6_Column, 0, hv_R6_Radius, hv_R6_Radius, out hv_R6_MinDist,
                            out hv_R6_MaxDist, out hv_R6_AvgDist, out hv_R6_SigmaDist);
                        hv_NumCircles = hv_NumCircles + 1;
                        if ((int)(new HTuple(hv_R6.TupleGreater(hv_R6_Radius))) != 0)
                        {
                            hv_R6 = hv_R6_Radius.Clone();
                            mResult = new CircleResult()
                            {
                                Row = new HTuple(hv_R6_Row),
                                Col = new HTuple(hv_R6_Column),
                                Radius = new HTuple(hv_R6_Radius),
                                StartPhi = new HTuple(hv_R6_StartPhi),
                                EndPhi = new HTuple(hv_R6_EndPhi),
                                PointOrder = new HTuple(hv_R6_PointOrder),
                            };
                        }
                    }
                }
                hv_R6_R = hv_R6_R + hv_R6_R_Inc;
            }

            ho_R6_Circle.Dispose();
            ho_R6_ROI_Image.Dispose();
            ho_R6_Region.Dispose();
            ho_R6_RegionBorder.Dispose();
            ho_R6_RegionDilation.Dispose();
            ho_R6_ImageReduced.Dispose();
            ho_R6_Edges.Dispose();
            ho_R6_ContoursSplit.Dispose();
            ho_R6_SingleSegment.Dispose();
            ho_R6_ContEllipse.Dispose();

            return mResult;
        }