Esempio n. 1
0
        // private void checkBoxTiao_CheckedChanged(object sender, EventArgs e)
        //  {
        //    if (!checkBoxTiao.Checked) yuZhiCha.Text="";
        // }

        private void btnAddModel_Click(object sender, EventArgs e)
        {
            string word = Interaction.InputBox("请输入密码", "身份验证", "", 100, 100);

            if (word != "123456")
            {
                MessageBox.Show("密码不能为空或错误!"); return;
            }
            string str = Interaction.InputBox("请输入模板名字", "创建模板", "", 100, 100);

            if (str == "")
            {
                MessageBox.Show("名字不能为空!"); return;
            }
            ;
            if (true == Directory.Exists("c:/modelFiles/model-" + str + ".shm"))
            {
                MessageBox.Show("已有重复模板!");
                return;
            }
            HTuple hv_AcqHandle_model;

            HOperatorSet.OpenFramegrabber("MindVision17_X64", 1, 1, 0, 0, 0, 0, "progressive",
                                          8, "Gray", -1, "false", "auto", "oufang", 0, -1, out hv_AcqHandle_model);
            HOperatorSet.SetFramegrabberParam(hv_AcqHandle_model, "color_space", "BGR24");
            // hv_AcqHandle = hv_AcqHandle_model;
            //HOperatorSet.GrabImageStart(hv_AcqHandle_model, -1);
            HObject ho_Circle = null, ho_ImageReduced = null, ho_colorImage = null;
            HTuple  hv_Width = new HTuple(), hv_Height = new HTuple();
            HTuple  hv_WindowHandle = new HTuple(), hv_Row = new HTuple();
            HTuple  hv_Column = new HTuple(), hv_Radius = new HTuple();
            HTuple  hv_ModelID = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            try
            {
                MessageBox.Show("单击鼠标左键并拖动选择模板区域,右键确定!");
                //HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "software_trig", 1);
                HOperatorSet.GrabImage(out ho_colorImage, hv_AcqHandle_model);
                HOperatorSet.WriteImage(ho_colorImage, "png", 0, "c:/modelFiles/" + str);
                //HOperatorSet.Rgb1ToGray(ho_colorImage, out ho_Image_model);
                // hv_Width.Dispose(); hv_Height.Dispose();
                HOperatorSet.GetImageSize(ho_colorImage, out hv_Width, out hv_Height);
                // HOperatorSet.SetWindowAttr("background_color", "red");
                HOperatorSet.OpenWindow(0, 0, hv_Width + 1, hv_Height + 1, 0, "visible", "", out hv_WindowHandle);
                HOperatorSet.DispImage(ho_colorImage, hv_WindowHandle);
                HDevWindowStack.Push(hv_WindowHandle);
                // ho_Image.Dispose();
                // hv_Row.Dispose(); hv_Column.Dispose(); hv_Radius.Dispose();
                HOperatorSet.DrawCircle(hv_WindowHandle, out hv_Row, out hv_Column, out hv_Radius);
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(ho_colorImage, ho_Circle, out ho_ImageReduced);
                // hv_ModelID.Dispose();
                HOperatorSet.CreateShapeModel(ho_ImageReduced, "auto", 0, (new HTuple(360)).TupleRad()
                                              , "auto", "auto", "use_polarity", "auto", "auto", out hv_ModelID);
                HOperatorSet.WriteShapeModel(hv_ModelID, ("c:/modelFiles/model-" + str + ".shm"));
                HOperatorSet.CloseWindow(hv_WindowHandle);
            }
            catch (Exception)
            {
                MessageBox.Show("操作出错!请重新添加模板。");

                File.Delete("c:/modelFiles/model-" + str + ".shm");
                File.Delete("c:/modelFiles/" + str + ".png");

                HOperatorSet.CloseWindow(hv_WindowHandle);
                return;

                throw;
            }
            finally {
                HOperatorSet.CloseFramegrabber(hv_AcqHandle_model);
                ho_colorImage.Dispose();
                ho_Circle.Dispose();
                ho_ImageReduced.Dispose();
            }

            MessageBox.Show("模板创建成功!");
            updateList();
        }
Esempio n. 2
0
    // Main procedure
    private void action()
    {
        // Local iconic variables

        HObject ho_Image11515282Cam0;


        // Local control variables

        HTuple hv_WindowHandle, hv_row, hv_col, hv_row1;
        HTuple hv_col1, hv_RowProj, hv_ColProj, hv_Real, hv_Real1;
        HTuple hv_k, hv_b, hv_k1, hv_b1, hv_x, hv_y, hv_x0, hv_y0;
        HTuple hv_TargetRow, hv_TargetCol, hv_k2, hv_b2, hv_kIn;
        HTuple hv_bIn, hv_LineOutRow, hv_LineOutCol, hv_LineOutRow1;
        HTuple hv_LineOutCol1, hv_k3, hv_b3, hv_Sqrt;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image11515282Cam0);

        ho_Image11515282Cam0.Dispose();
        HOperatorSet.ReadImage(out ho_Image11515282Cam0, "C:/项目/李博定位台需求/AssemblyBench/JPT TosaTest/bin/Debug/ImageSaved/ImageSaved/11月5日 15时28分2秒_Cam0.jpg");
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.CloseWindow(HDevWindowStack.Pop());
        }
        dev_open_window_fit_image(ho_Image11515282Cam0, 0, 0, -1, -1, out hv_WindowHandle);
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.DispObj(ho_Image11515282Cam0, HDevWindowStack.GetActive());
        }
        hv_row = 456;
        hv_col = 789;

        hv_row1 = 1000;
        hv_col1 = 1450;
        HOperatorSet.ProjectionPl(200, 200, hv_row, hv_col, hv_row1, hv_col1, out hv_RowProj,
                                  out hv_ColProj);
        HOperatorSet.DispCross(hv_WindowHandle, 200, 200, 26, 0);
        HOperatorSet.DispLine(hv_WindowHandle, hv_row, hv_col, hv_row1, hv_col1);
        HOperatorSet.DispCross(hv_WindowHandle, hv_RowProj, hv_ColProj, 26, 0);
        HOperatorSet.DispLine(hv_WindowHandle, 200, 200, hv_RowProj, hv_ColProj);
        HOperatorSet.TupleReal(hv_col1 - hv_col, out hv_Real);
        HOperatorSet.TupleReal(hv_row1 - hv_row, out hv_Real1);
        hv_k = hv_Real / hv_Real1;
        hv_b = hv_col1 - (hv_k * hv_row1);

        HOperatorSet.DispCross(hv_WindowHandle, 234, (hv_k * 234) + hv_b, 56, 0);

        //根据点画垂线
        hv_k1 = -1 / hv_k;
        hv_b1 = ((234 * hv_k) + hv_b) - ((-1 / hv_k) * 234);



        hv_x = 234;
        hv_y = (234 * hv_k1) + hv_b1;

        hv_x0 = 567;
        hv_y0 = (567 * hv_k1) + hv_b1;
        HOperatorSet.DispCross(hv_WindowHandle, hv_x0, hv_y0, 56, 0);
        HOperatorSet.DispLine(hv_WindowHandle, hv_x, hv_y, hv_x0, hv_y0);

        //画指定长度的垂线
        GetVerticalFromDistance(hv_x, hv_y, hv_row, hv_col, hv_row1, hv_col1, 60, "row",
                                -1, out hv_TargetRow, out hv_TargetCol, out hv_k2, out hv_b2, out hv_kIn,
                                out hv_bIn);

        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
        }
        HOperatorSet.DispCross(hv_WindowHandle, hv_TargetRow, hv_TargetCol, 56, 0);

        GetVerticalFromDistance(hv_x, hv_y, hv_row, hv_col, hv_row1, hv_col1, 60, "row",
                                1, out hv_TargetRow, out hv_TargetCol, out hv_k2, out hv_b2, out hv_kIn,
                                out hv_bIn);

        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
        }
        HOperatorSet.DispCross(hv_WindowHandle, hv_TargetRow, hv_TargetCol, 56, 0);

        GetParallelLineFromDistance(hv_row, hv_col, hv_row1, hv_col1, 350, "row", -1,
                                    out hv_LineOutRow, out hv_LineOutCol, out hv_LineOutRow1, out hv_LineOutCol1,
                                    out hv_k3, out hv_b3);

        HOperatorSet.DispLine(hv_WindowHandle, hv_LineOutRow, hv_LineOutCol, hv_LineOutRow1,
                              hv_LineOutCol1);
        HOperatorSet.DispCross(hv_WindowHandle, hv_LineOutRow, hv_LineOutCol, 106, 0);
        HOperatorSet.DispCross(hv_WindowHandle, hv_LineOutRow1, hv_LineOutCol1, 106,
                               0);

        HOperatorSet.TupleSqrt(((hv_LineOutRow - hv_row) * (hv_LineOutRow - hv_row)) + ((hv_LineOutCol - hv_col) * (hv_LineOutCol - hv_col)),
                               out hv_Sqrt);



        ho_Image11515282Cam0.Dispose();
    }
        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);
        }
Esempio n. 4
0
        private HTuple CreatModel()
        {
            // Local control variables
            HTuple hv_ModelID = null, hv_Seconds1 = new HTuple();
            HTuple hv_num = new HTuple(), hv_a = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_ImageR);
            HOperatorSet.GenEmptyObj(out ho_ImageG);
            HOperatorSet.GenEmptyObj(out ho_ImageB);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_GrayImage);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImageMean);
            HOperatorSet.GenEmptyObj(out ho_RegionDynThresh);
            HOperatorSet.GenEmptyObj(out ho_RegionErosion);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, "acA2500-14gc01.bmp");
            ho_ImageR.Dispose(); ho_ImageG.Dispose(); ho_ImageB.Dispose();
            HOperatorSet.Decompose3(ho_Image, out ho_ImageR, out ho_ImageG, out ho_ImageB
                                    );
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
            }
            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle2(out ho_Rectangle, 1085, 1060, 0, 100, 65);
            ho_GrayImage.Dispose();
            HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_GrayImage, ho_Rectangle, out ho_ImageReduced);
            ho_ImageMean.Dispose();
            HOperatorSet.MeanImage(ho_ImageReduced, out ho_ImageMean, 60, 60);
            ho_RegionDynThresh.Dispose();
            HOperatorSet.DynThreshold(ho_ImageReduced, ho_ImageMean, out ho_RegionDynThresh,
                                      5, "light");
            ho_RegionErosion.Dispose();
            HOperatorSet.ErosionCircle(ho_RegionDynThresh, out ho_RegionErosion, 3.5);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_RegionErosion, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", 150, 99999);
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);
            ho_RegionDilation.Dispose();
            HOperatorSet.DilationCircle(ho_RegionUnion, out ho_RegionDilation, 5);
            ho_ImageReduced1.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_RegionDilation, out ho_ImageReduced1);
            HOperatorSet.CreateShapeModel(ho_ImageReduced, "auto", (new HTuple(0)).TupleRad()
                                          , (new HTuple(360)).TupleRad(), "auto", "auto", "use_polarity", "auto", "auto",
                                          out hv_ModelID);
            ho_Image.Dispose();
            ho_ImageR.Dispose();
            ho_ImageG.Dispose();
            ho_ImageB.Dispose();
            ho_Rectangle.Dispose();
            ho_GrayImage.Dispose();
            ho_ImageReduced.Dispose();
            ho_ImageMean.Dispose();
            ho_RegionDynThresh.Dispose();
            ho_RegionErosion.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionDilation.Dispose();
            ho_ImageReduced1.Dispose();
            return(hv_ModelID);
        }
Esempio n. 5
0
    // 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;
    }
Esempio n. 6
0
        private void action()
        {
            // Local iconic variables

            HObject ho_Image, ho_ImageMean, ho_RegionDynThresh;
            HObject ho_RegionOpening, ho_ConnectedRegions, ho_SelectedRegions;
            HObject ho_Rectangle, ho_RegionDynThresh1, ho_RegionOpening1;
            HObject ho_ConnectedRegions1, ho_SelectedRegions1, ho_Circle;
            HObject ho_SelectedRegions2, ho_Circle2;

            // Local control variables

            HTuple hv_Row1 = null, hv_Column1 = null, hv_Phi = null;
            HTuple hv_Length1 = null, hv_Length2 = null, hv_Row = null;
            HTuple hv_Column = null, hv_Radius = null, hv_Row2 = null;
            HTuple hv_Column2 = null, hv_Radius2 = null, hv_DistanceMin = null;
            HTuple hv_DistanceMax = null, hv_RowArr = null, hv_ColArr = null;
            HTuple hv_RadiusArr = null, hv_Distance1 = null, hv_Distance2 = null;
            HTuple hv_Distance3 = null, hv_Distance4 = null, hv_Distance5 = null;
            HTuple hv_Distance6 = null, hv_DistanceArr = null, hv_Sorted = null;
            HTuple hv_Sorted1 = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_ImageMean);
            HOperatorSet.GenEmptyObj(out ho_RegionDynThresh);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_RegionDynThresh1);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_Circle2);
            try
            {
                ho_ImageMean.Dispose();
                HOperatorSet.MeanImage(Image, out ho_ImageMean, 70, 70);
                ho_RegionDynThresh.Dispose();
                HOperatorSet.DynThreshold(Image, ho_ImageMean, out ho_RegionDynThresh, 10.5,
                                          "dark");
                ho_RegionOpening.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionDynThresh, out ho_RegionOpening, 4);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", 150000, 9999900);
                HOperatorSet.SmallestRectangle2(ho_SelectedRegions, out hv_Row1, out hv_Column1,
                                                out hv_Phi, out hv_Length1, out hv_Length2);
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle, hv_Row1, hv_Column1,
                                                     hv_Phi, hv_Length1, hv_Length2);
                ho_RegionDynThresh1.Dispose();
                HOperatorSet.DynThreshold(Image, ho_ImageMean, out ho_RegionDynThresh1,
                                          10.5, "light");
                ho_RegionOpening1.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionDynThresh1, out ho_RegionOpening1, 9.5);
                ho_ConnectedRegions1.Dispose();
                HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions1);
                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "area",
                                         "and", 35000, 99999);
                HOperatorSet.SmallestCircle(ho_SelectedRegions1, out hv_Row, out hv_Column,
                                            out hv_Radius);
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius);
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
                }
                ho_SelectedRegions2.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions2, "area",
                                         "and", 28000, 99999);
                HOperatorSet.SmallestCircle(ho_SelectedRegions2, out hv_Row2, out hv_Column2,
                                            out hv_Radius2);
                ho_Circle2.Dispose();
                HOperatorSet.GenCircle(out ho_Circle2, hv_Row2, hv_Column2, hv_Radius2);
                HOperatorSet.DistancePc(ho_Rectangle, hv_Row2, hv_Column2, out hv_DistanceMin,
                                        out hv_DistanceMax);
                hv_RowArr    = new HTuple();
                hv_ColArr    = new HTuple();
                hv_RadiusArr = new HTuple();
                hv_RowArr    = hv_RowArr.TupleConcat(hv_Row);
                hv_ColArr    = hv_ColArr.TupleConcat(hv_Column);
                hv_RadiusArr = hv_RadiusArr.TupleConcat(hv_Radius);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(0), hv_ColArr.TupleSelect(0),
                                        hv_RowArr.TupleSelect(1), hv_ColArr.TupleSelect(1), out hv_Distance1);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(0), hv_ColArr.TupleSelect(0),
                                        hv_RowArr.TupleSelect(2), hv_ColArr.TupleSelect(2), out hv_Distance2);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(1), hv_ColArr.TupleSelect(1),
                                        hv_RowArr.TupleSelect(3), hv_ColArr.TupleSelect(3), out hv_Distance3);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(2), hv_ColArr.TupleSelect(2),
                                        hv_RowArr.TupleSelect(3), hv_ColArr.TupleSelect(3), out hv_Distance4);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(1), hv_ColArr.TupleSelect(1),
                                        hv_RowArr.TupleSelect(2), hv_ColArr.TupleSelect(2), out hv_Distance5);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(0), hv_ColArr.TupleSelect(0),
                                        hv_RowArr.TupleSelect(3), hv_ColArr.TupleSelect(3), out hv_Distance6);
                hv_DistanceArr = new HTuple();
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance1);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance2);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance3);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance4);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance5);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance6);
                HOperatorSet.TupleSort(hv_DistanceArr, out hv_Sorted);

                HOperatorSet.TupleSort(hv_RadiusArr, out hv_Sorted1);



                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("孔距L1");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(0)).D * pixeldist);
                hv_result = hv_result.TupleConcat("孔距L2");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(1)).D * pixeldist);
                hv_result = hv_result.TupleConcat("孔距L3");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(2)).D * pixeldist);
                hv_result = hv_result.TupleConcat("孔距L4");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(3)).D * pixeldist);
                hv_result = hv_result.TupleConcat("直径1");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(0)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("直径2");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(1)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("直径3");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(2)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("直径4");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(3)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("长度L");
                hv_result = hv_result.TupleConcat((hv_Length1.D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("宽度W");
                hv_result = hv_result.TupleConcat((hv_Length2.D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("圆心1到边缘1");
                hv_result = hv_result.TupleConcat((hv_DistanceMin.TupleSelect(0)).D * pixeldist);
                hv_result = hv_result.TupleConcat("圆心2到边缘2");
                hv_result = hv_result.TupleConcat((hv_DistanceMin.TupleSelect(1)).D * pixeldist);
                result    = hv_result.Clone();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("孔距L1");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("孔距L2");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("孔距L3");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("孔距L4");
                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);
                hv_result = hv_result.TupleConcat("长度L");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("宽度W");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("圆心1到边缘1");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("圆心2到边缘2");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();
            }
            finally
            {
                //ho_Image.Dispose();
                ho_ImageMean.Dispose();
                ho_RegionDynThresh.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_Rectangle.Dispose();
                ho_RegionDynThresh1.Dispose();
                ho_RegionOpening1.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_Circle.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_Circle2.Dispose();
            }
        }
Esempio n. 7
0
        private void action()
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];

            // Local iconic variables

            HObject ho_Rectangle, ho_ImageReduced;
            HObject ho_Region, ho_RegionLines, ho_RegionUnion1, ho_RegionUnion2;
            HObject ho_RegionUnion3, ho_Region1, ho_ConnectedRegions;
            HObject ho_RegionFillUp, ho_SelectedRegions, ho_SortedRegions;
            HObject ho_ObjectSelected = null, ho_Rectangle1 = null, ho_ImageReduced1 = null;
            HObject ho_Circle1 = null, ho_Circle2 = null, ho_Circle3 = null;
            HObject ho_Circle4 = null, ho_RegionUnionc1 = null, ho_RegionUnionc2 = null;
            HObject ho_RegionUnionc3 = null, ho_ConnectedRegionsc = null;
            HObject ho_SortedRegions1 = null, ho_ContoursL = null, ho_RegionLinesL = null;
            HObject ho_RegionLinesL1 = null, ho_RegionUnionL = null, ho_ConnectedRegionsL = null;
            HObject ho_SelectedRegionsL = null, ho_RegionFillUpL = null;
            HObject ho_ContoursSplitL = null, ho_SelectedContoursL = null;
            HObject ho_UnionContoursL = null, ho_RegionL = null, ho_RegionDifferenceL = null;
            HObject ho_ContoursR = null, ho_RegionLinesR = null, ho_RegionLinesR1 = null;
            HObject ho_RegionUnionR = null, ho_ConnectedRegionsR = null;
            HObject ho_SelectedRegionsR = null, ho_RegionFillUpR = null;
            HObject ho_ContoursSplitR = null, ho_SelectedContoursR = null;
            HObject ho_UnionContoursR = null, ho_RegionR = null, ho_RegionDifferenceR = null;
            HObject ho_ConnectedRegions1, ho_ObjectSelected1 = null;

            // Local control variables

            HTuple hv_Width = null, hv_Height = null, hv_Row11 = null;
            HTuple hv_Column11 = null, hv_Row21 = null, hv_Column21 = null;
            HTuple hv_Row12 = null, hv_Column12 = null, hv_Row22 = null;
            HTuple hv_Column22 = null, hv_Number = null, hv_h = null;
            HTuple hv_w = null, hv_i = null, hv_Row = new HTuple();
            HTuple hv_Column = new HTuple(), hv_Phi = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_Length2 = new HTuple();
            HTuple hv_Cos = new HTuple(), hv_Sin = new HTuple(), hv_RT_X = new HTuple();
            HTuple hv_RT_Y = new HTuple(), hv_AX = new HTuple(), hv_AY = new HTuple();
            HTuple hv_RB_X = new HTuple(), hv_RB_Y = new HTuple();
            HTuple hv_BX = new HTuple(), hv_BY = new HTuple(), hv_LB_X = new HTuple();
            HTuple hv_LB_Y = new HTuple(), hv_CX = new HTuple(), hv_CY = new HTuple();
            HTuple hv_LT_X = new HTuple(), hv_LT_Y = new HTuple();
            HTuple hv_DX = new HTuple(), hv_DY = new HTuple(), hv_Number1 = new HTuple();
            HTuple hv_Area = new HTuple(), hv_Row1 = new HTuple();
            HTuple hv_Column1 = new HTuple(), hv_Distance = new HTuple();
            HTuple hv_Distance1 = new HTuple(), hv_shapeParam = new HTuple();
            HTuple hv_MetrologyHandleL = new HTuple(), hv_Index = new HTuple();
            HTuple hv_RowL = new HTuple(), hv_ColumnL = new HTuple();
            HTuple hv_l = new HTuple(), hv_NumberL = new HTuple();
            HTuple hv_MetrologyHandleR = new HTuple(), hv_RowR = new HTuple();
            HTuple hv_ColumnR = new HTuple(), hv_r = new HTuple();
            HTuple hv_NumberR = new HTuple(), hv_AreaL = new HTuple();
            HTuple hv_AreaR = new HTuple(), hv_Area1 = null, hv_Row2 = null;
            HTuple hv_Column2 = null, hv_Area2 = null, hv_Row3 = null;
            HTuple hv_Column3 = null, hv_hm = null, hv_wm = null, hv_Row13 = null;
            HTuple hv_Column13 = null, hv_Row23 = null, hv_Column23 = null;
            HTuple hv_zh = null, hv_w1 = new HTuple(), hv_Row4 = new HTuple(), hv_Column4 = new HTuple();
            HTuple hv_Phi1 = new HTuple(), hv_Length11 = new HTuple(), hv_Length21 = new HTuple(), hv_Concat = new HTuple();

            // 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_RegionLines);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion1);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion2);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion3);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SortedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_Circle2);
            HOperatorSet.GenEmptyObj(out ho_Circle3);
            HOperatorSet.GenEmptyObj(out ho_Circle4);
            HOperatorSet.GenEmptyObj(out ho_RegionUnionc1);
            HOperatorSet.GenEmptyObj(out ho_RegionUnionc2);
            HOperatorSet.GenEmptyObj(out ho_RegionUnionc3);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsc);
            HOperatorSet.GenEmptyObj(out ho_SortedRegions1);
            HOperatorSet.GenEmptyObj(out ho_ContoursL);
            HOperatorSet.GenEmptyObj(out ho_RegionLinesL);
            HOperatorSet.GenEmptyObj(out ho_RegionLinesL1);
            HOperatorSet.GenEmptyObj(out ho_RegionUnionL);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsL);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegionsL);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUpL);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplitL);
            HOperatorSet.GenEmptyObj(out ho_SelectedContoursL);
            HOperatorSet.GenEmptyObj(out ho_UnionContoursL);
            HOperatorSet.GenEmptyObj(out ho_RegionL);
            HOperatorSet.GenEmptyObj(out ho_RegionDifferenceL);
            HOperatorSet.GenEmptyObj(out ho_ContoursR);
            HOperatorSet.GenEmptyObj(out ho_RegionLinesR);
            HOperatorSet.GenEmptyObj(out ho_RegionLinesR1);
            HOperatorSet.GenEmptyObj(out ho_RegionUnionR);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegionsR);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegionsR);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUpR);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplitR);
            HOperatorSet.GenEmptyObj(out ho_SelectedContoursR);
            HOperatorSet.GenEmptyObj(out ho_UnionContoursR);
            HOperatorSet.GenEmptyObj(out ho_RegionR);
            HOperatorSet.GenEmptyObj(out ho_RegionDifferenceR);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);

            HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);


            HOperatorSet.Union1(algorithm.Region, out RegionToDisp);
            try
            {
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle1(out ho_Rectangle, DRow1m, DCol1m, DRow2m, DCol2m);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(Image, ho_Rectangle, out ho_ImageReduced);
                ho_Region.Dispose();
                HOperatorSet.GetImageSize(Image, out hv_Width, out hv_Height);
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, 128, 255);
                HOperatorSet.SmallestRectangle1(ho_Region, out hv_Row12, out hv_Column12, out hv_Row22,
                                                out hv_Column22);

                ho_RegionLines.Dispose();
                HOperatorSet.GenRegionLine(out ho_RegionLines, (hv_Row12 + hv_Row22) / 2, hv_Column12,
                                           ((hv_Row12 + hv_Row22) / 2) + 1, hv_Column12);

                ho_RegionUnion1.Dispose();
                HOperatorSet.Union1(ho_RegionLines, out ho_RegionUnion1);

                ho_RegionUnion2.Dispose();
                HOperatorSet.Union1(ho_RegionLines, out ho_RegionUnion2);

                ho_RegionUnion3.Dispose();
                HOperatorSet.Union1(ho_RegionLines, out ho_RegionUnion3);


                ho_Region1.Dispose();
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, 128, 255);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions);

                ho_RegionFillUp.Dispose();
                HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp);

                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions, "area", "and",
                                         500, 99999000);

                ho_SortedRegions.Dispose();
                HOperatorSet.SortRegion(ho_SelectedRegions, out ho_SortedRegions, "upper_left",
                                        "true", "column");

                HOperatorSet.CountObj(ho_SortedRegions, out hv_Number);

                // stop(); only in hdevelop
                // stop(); only in hdevelop
                hv_h  = new HTuple();
                hv_w  = new HTuple();
                hv_w1 = new HTuple();
                ho_ObjectSelected1.Dispose();
                HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected1, 1);
                HOperatorSet.SmallestRectangle2(ho_ObjectSelected1, out hv_Row4, out hv_Column4,
                                                out hv_Phi1, out hv_Length11, out hv_Length21);
                hv_w1 = hv_w1.TupleConcat(hv_Length21 * 2);
                HTuple end_val40  = hv_Number - 1;
                HTuple step_val40 = 1;
                for (hv_i = 2; hv_i.Continue(end_val40, step_val40); hv_i = hv_i.TupleAdd(step_val40))
                {
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected, hv_i);
                    HOperatorSet.SmallestRectangle2(ho_ObjectSelected, out hv_Row, out hv_Column,
                                                    out hv_Phi, out hv_Length1, out hv_Length2);
                    //if (Length1>(Row22-Row12)*0.25)
                    ho_Rectangle1.Dispose();
                    HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row, hv_Column, hv_Phi,
                                               hv_Length1 * 0.85, hv_Length2);
                    ho_ImageReduced1.Dispose();
                    HOperatorSet.ReduceDomain(ho_ImageReduced, ho_Rectangle1, out ho_ImageReduced1
                                              );
                    //*矩形4个角点
                    HOperatorSet.TupleCos(hv_Phi, out hv_Cos);
                    HOperatorSet.TupleSin(hv_Phi, out hv_Sin);
                    //*dev_set_color('green')
                    hv_RT_X = (((-hv_Length1) * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin);
                    hv_RT_Y = (((-hv_Length1) * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos);
                    ho_Circle1.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle1, hv_Row - hv_RT_Y, hv_Column + hv_RT_X,
                                           0.5);
                    //*最小矩形的顶点A
                    hv_AX = (((-hv_Length1) * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin);
                    hv_AY = (((-hv_Length1) * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos);
                    //*dev_set_color('red')
                    hv_RB_X = ((hv_Length1 * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin);
                    hv_RB_Y = ((hv_Length1 * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos);
                    ho_Circle2.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle2, hv_Row - hv_RB_Y, hv_Column + hv_RB_X,
                                           0.5);
                    //*最小矩形的顶点B
                    hv_BX = ((hv_Length1 * 0.85) * hv_Cos) - (hv_Length2 * hv_Sin);
                    hv_BY = ((hv_Length1 * 0.85) * hv_Sin) + (hv_Length2 * hv_Cos);

                    //*dev_set_color('yellow')
                    hv_LB_X = ((hv_Length1 * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin);
                    hv_LB_Y = ((hv_Length1 * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos);
                    ho_Circle3.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle3, hv_Row - hv_LB_Y, hv_Column + hv_LB_X,
                                           0.5);
                    //*最小矩形的顶点C
                    hv_CX = ((hv_Length1 * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin);
                    hv_CY = ((hv_Length1 * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos);

                    //*dev_set_color('pink')
                    hv_LT_X = (((-hv_Length1) * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin);
                    hv_LT_Y = (((-hv_Length1) * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos);
                    ho_Circle4.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle4, hv_Row - hv_LT_Y, hv_Column + hv_LT_X,
                                           0.5);
                    //*最小矩形的顶点D
                    hv_DX = (((-hv_Length1) * 0.85) * hv_Cos) + (hv_Length2 * hv_Sin);
                    hv_DY = (((-hv_Length1) * 0.85) * hv_Sin) - (hv_Length2 * hv_Cos);

                    //stop ()

                    ho_RegionUnionc1.Dispose();
                    HOperatorSet.Union2(ho_Circle1, ho_Circle2, out ho_RegionUnionc1);
                    ho_RegionUnionc2.Dispose();
                    HOperatorSet.Union2(ho_RegionUnionc1, ho_Circle3, out ho_RegionUnionc2);
                    ho_RegionUnionc3.Dispose();
                    HOperatorSet.Union2(ho_RegionUnionc2, ho_Circle4, out ho_RegionUnionc3);
                    ho_ConnectedRegionsc.Dispose();
                    HOperatorSet.Connection(ho_RegionUnionc3, out ho_ConnectedRegionsc);
                    //count_obj (RegionUnionc3, Number1)
                    ho_SortedRegions1.Dispose();
                    HOperatorSet.SortRegion(ho_ConnectedRegionsc, out ho_SortedRegions1, "upper_left",
                                            "true", "row");

                    HOperatorSet.AreaCenter(ho_SortedRegions1, out hv_Area, out hv_Row1, out hv_Column1);
                    HOperatorSet.DistancePp(hv_Row1.TupleSelect(0), hv_Column1.TupleSelect(
                                                0), hv_Row1.TupleSelect(1), hv_Column1.TupleSelect(1), out hv_Distance);
                    HOperatorSet.DistancePl(hv_Row1.TupleSelect(0), hv_Column1.TupleSelect(
                                                0), hv_Row1.TupleSelect(2), hv_Column1.TupleSelect(2), hv_Row1.TupleSelect(
                                                3), hv_Column1.TupleSelect(3), out hv_Distance1);
                    //if (i>1)
                    hv_h = hv_h.TupleConcat((hv_Distance1 * 4) / 3);
                    //endif
                    hv_w = hv_w.TupleConcat(hv_Distance);

                    //gen_region_line (RegionLines2, (Row1[0]+Row1[1])/2, (Column1[0]+Column1[1])/2, (Row1[2]+Row1[3])/2, (Column1[2]+Column1[3])/2)
                    hv_shapeParam = new HTuple();
                    hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Row1.TupleSelect(
                                                                    0)) + (hv_Row1.TupleSelect(1))) / 2);
                    hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Column1.TupleSelect(
                                                                    0)) + (hv_Column1.TupleSelect(1))) / 2);
                    hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Row1.TupleSelect(
                                                                    2)) + (hv_Row1.TupleSelect(3))) / 2);
                    hv_shapeParam = hv_shapeParam.TupleConcat(((hv_Column1.TupleSelect(
                                                                    2)) + (hv_Column1.TupleSelect(3))) / 2);

                    //shapeParam := [Row12,(Column22+Column12)/2,Row22,(Column22+Column12)/2]
                    //找左侧点
                    HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandleL);
                    HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandleL, hv_Width,
                                                            hv_Height);
                    HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandleL, "line", hv_shapeParam,
                                                           hv_Distance / 2, 1, 1, 60, new HTuple(), new HTuple(), out hv_Index);
                    //设置参数
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "measure_transition",
                                                         "negative");
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "num_measures",
                                                         150);
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "num_instances",
                                                         1);
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleL, "all", "measure_select",
                                                         "last");

                    //开始找边缘
                    HOperatorSet.ApplyMetrologyModel(ho_ImageReduced1, hv_MetrologyHandleL);
                    ho_ContoursL.Dispose();
                    HOperatorSet.GetMetrologyObjectMeasures(out ho_ContoursL, hv_MetrologyHandleL,
                                                            "all", "all", out hv_RowL, out hv_ColumnL);

                    if (HDevWindowStack.IsOpen())
                    {
                        //dev_set_color ('red')
                    }
                    //disp_cross (3600, RowL, ColumnL, 6, Phi)

                    //左侧点,用一Row,只取最左边点
                    //gen_cross_contour_xld (CrossL, RowL, ColumnL, 6, 0)
                    ///释放测量句柄
                    HOperatorSet.ClearMetrologyModel(hv_MetrologyHandleL);
                    //gen_region_line (RegionLines, Row11, Column11, Row11+1, Column11)
                    //union1 (RegionLines, RegionUnion1)

                    for (hv_l = 0; (int)hv_l <= (int)((new HTuple(hv_RowL.TupleLength())) - 2); hv_l = (int)hv_l + 1)
                    {
                        ho_RegionLinesL.Dispose();
                        HOperatorSet.GenRegionLine(out ho_RegionLinesL, hv_RowL.TupleSelect(hv_l),
                                                   hv_ColumnL.TupleSelect(hv_l), hv_RowL.TupleSelect(hv_l + 1), hv_ColumnL.TupleSelect(
                                                       hv_l + 1));
                        {
                            HObject ExpTmpOutVar_0;
                            HOperatorSet.Union2(ho_RegionUnion1, ho_RegionLinesL, out ExpTmpOutVar_0
                                                );
                            ho_RegionUnion1.Dispose();
                            ho_RegionUnion1 = ExpTmpOutVar_0;
                        }
                    }

                    ho_RegionLinesL1.Dispose();
                    HOperatorSet.GenRegionLine(out ho_RegionLinesL1, hv_RowL.TupleSelect(0),
                                               hv_ColumnL.TupleSelect(0), hv_RowL.TupleSelect((new HTuple(hv_RowL.TupleLength()
                                                                                                          )) - 1), hv_ColumnL.TupleSelect((new HTuple(hv_RowL.TupleLength())) - 1));
                    ho_RegionUnionL.Dispose();
                    HOperatorSet.Union2(ho_RegionUnion1, ho_RegionLinesL1, out ho_RegionUnionL
                                        );
                    ho_ConnectedRegionsL.Dispose();
                    HOperatorSet.Connection(ho_RegionUnionL, out ho_ConnectedRegionsL);
                    ho_SelectedRegionsL.Dispose();
                    HOperatorSet.SelectShapeStd(ho_ConnectedRegionsL, out ho_SelectedRegionsL,
                                                "max_area", 70);
                    ho_RegionFillUpL.Dispose();
                    HOperatorSet.FillUp(ho_SelectedRegionsL, out ho_RegionFillUpL);
                    ho_ContoursL.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_RegionFillUpL, out ho_ContoursL, "border");
                    ho_ContoursSplitL.Dispose();
                    HOperatorSet.SegmentContoursXld(ho_ContoursL, out ho_ContoursSplitL, "lines_circles",
                                                    5, 8, 3.5);
                    ho_SelectedContoursL.Dispose();
                    HOperatorSet.SelectContoursXld(ho_ContoursSplitL, out ho_SelectedContoursL,
                                                   "contour_length", 70, 2000, -0.5, 0.5);
                    //***
                    ho_UnionContoursL.Dispose();
                    HOperatorSet.UnionAdjacentContoursXld(ho_SelectedContoursL, out ho_UnionContoursL,
                                                          10, 1, "attr_keep");
                    ho_RegionL.Dispose();
                    HOperatorSet.GenRegionContourXld(ho_UnionContoursL, out ho_RegionL, "filled");

                    ho_RegionDifferenceL.Dispose();
                    HOperatorSet.Difference(ho_RegionFillUpL, ho_RegionL, out ho_RegionDifferenceL
                                            );
                    HOperatorSet.CountObj(ho_RegionDifferenceL, out hv_NumberL);

                    //*
                    //找右侧点
                    HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandleR);
                    HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandleR, hv_Width,
                                                            hv_Height);
                    HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandleR, "line", hv_shapeParam,
                                                           hv_Distance / 2, 1, 1, 60, new HTuple(), new HTuple(), out hv_Index);
                    //设置参数
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "measure_transition",
                                                         "positive");
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "num_measures",
                                                         100);
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "num_instances",
                                                         1);
                    HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandleR, "all", "measure_select",
                                                         "first");

                    //开始找边缘
                    HOperatorSet.ApplyMetrologyModel(ho_ImageReduced1, hv_MetrologyHandleR);
                    ho_ContoursR.Dispose();
                    HOperatorSet.GetMetrologyObjectMeasures(out ho_ContoursR, hv_MetrologyHandleR,
                                                            "all", "all", out hv_RowR, out hv_ColumnR);

                    //disp_obj (Image, 3600)
                    if (HDevWindowStack.IsOpen())
                    {
                        //dev_set_color ('red')
                    }
                    //disp_cross (3600, RowR, ColumnR, 6, Phi)
                    //*右侧点,用一Row,只取最右边点
                    //gen_cross_contour_xld (CrossR, RowR, ColumnR, 6, 0)

                    ///释放测量句柄
                    HOperatorSet.ClearMetrologyModel(hv_MetrologyHandleR);
                    //close_measure (MeasureHandle1)
                    //stop ()

                    //gen_region_line (RegionLines, Row11, Column11, Row11+1, Column11)
                    //union1 (RegionLines, RegionUnion1)

                    for (hv_r = 0; (int)hv_r <= (int)((new HTuple(hv_RowR.TupleLength())) - 2); hv_r = (int)hv_r + 1)
                    {
                        ho_RegionLinesR.Dispose();
                        HOperatorSet.GenRegionLine(out ho_RegionLinesR, hv_RowR.TupleSelect(hv_r),
                                                   hv_ColumnR.TupleSelect(hv_r), hv_RowR.TupleSelect(hv_r + 1), hv_ColumnR.TupleSelect(
                                                       hv_r + 1));
                        {
                            HObject ExpTmpOutVar_0;
                            HOperatorSet.Union2(ho_RegionUnion2, ho_RegionLinesR, out ExpTmpOutVar_0
                                                );
                            ho_RegionUnion2.Dispose();
                            ho_RegionUnion2 = ExpTmpOutVar_0;
                        }
                    }

                    ho_RegionLinesR1.Dispose();
                    HOperatorSet.GenRegionLine(out ho_RegionLinesR1, hv_RowR.TupleSelect(0),
                                               hv_ColumnR.TupleSelect(0), hv_RowR.TupleSelect((new HTuple(hv_RowR.TupleLength()
                                                                                                          )) - 1), hv_ColumnR.TupleSelect((new HTuple(hv_RowR.TupleLength())) - 1));
                    ho_RegionUnionR.Dispose();
                    HOperatorSet.Union2(ho_RegionUnion2, ho_RegionLinesR1, out ho_RegionUnionR
                                        );
                    ho_ConnectedRegionsR.Dispose();
                    HOperatorSet.Connection(ho_RegionUnionR, out ho_ConnectedRegionsR);
                    ho_SelectedRegionsR.Dispose();
                    HOperatorSet.SelectShapeStd(ho_ConnectedRegionsR, out ho_SelectedRegionsR,
                                                "max_area", 70);
                    ho_RegionFillUpR.Dispose();
                    HOperatorSet.FillUp(ho_SelectedRegionsR, out ho_RegionFillUpR);
                    ho_ContoursR.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_RegionFillUpR, out ho_ContoursR, "border");
                    ho_ContoursSplitR.Dispose();
                    HOperatorSet.SegmentContoursXld(ho_ContoursR, out ho_ContoursSplitR, "lines_circles",
                                                    5, 8, 3.5);
                    ho_SelectedContoursR.Dispose();
                    HOperatorSet.SelectContoursXld(ho_ContoursSplitR, out ho_SelectedContoursR,
                                                   "contour_length", 70, 2000, -0.5, 0.5);
                    ho_UnionContoursR.Dispose();
                    HOperatorSet.UnionAdjacentContoursXld(ho_SelectedContoursR, out ho_UnionContoursR,
                                                          10, 1, "attr_keep");
                    ho_RegionR.Dispose();
                    HOperatorSet.GenRegionContourXld(ho_UnionContoursR, out ho_RegionR, "filled");

                    ho_RegionDifferenceR.Dispose();
                    HOperatorSet.Difference(ho_RegionFillUpR, ho_RegionR, out ho_RegionDifferenceR
                                            );
                    HOperatorSet.CountObj(ho_RegionDifferenceR, out hv_NumberR);

                    //stop ()

                    if ((int)(new HTuple(hv_NumberL.TupleGreater(0))) != 0)
                    {
                        HOperatorSet.AreaCenter(ho_RegionDifferenceL, out hv_AreaL, out hv_RowL,
                                                out hv_ColumnL);
                        {
                            HObject ExpTmpOutVar_0;
                            HOperatorSet.Union2(ho_RegionUnion3, ho_RegionDifferenceL, out ExpTmpOutVar_0
                                                );
                            ho_RegionUnion3.Dispose();
                            ho_RegionUnion3 = ExpTmpOutVar_0;
                        }
                    }
                    if ((int)(new HTuple(hv_NumberR.TupleGreater(0))) != 0)
                    {
                        HOperatorSet.AreaCenter(ho_RegionDifferenceR, out hv_AreaR, out hv_RowR,
                                                out hv_ColumnR);
                        {
                            HObject ExpTmpOutVar_0;
                            HOperatorSet.Union2(ho_RegionUnion3, ho_RegionDifferenceR, out ExpTmpOutVar_0
                                                );
                            ho_RegionUnion3.Dispose();
                            ho_RegionUnion3 = ExpTmpOutVar_0;
                        }
                    }
                    //union2 (RegionDifferenceL, RegionDifferenceR, RegionUnionLR)
                    //union2 (RegionUnion3, RegionUnionLR, RegionUnion3)
                    // stop(); only in hdevelop
                    //endif
                }

                HOperatorSet.AreaCenter(ho_RegionUnion3, out hv_Area1, out hv_Row2, out hv_Column2);
                ho_ConnectedRegions1.Dispose();
                HOperatorSet.Connection(ho_RegionUnion3, out ho_ConnectedRegions1);
                HOperatorSet.AreaCenter(ho_ConnectedRegions1, out hv_Area2, out hv_Row3, out hv_Column3);
                HOperatorSet.TupleConcat(hv_w1, hv_w, out hv_Concat);
                hv_hm = (hv_h.TupleMin()) / (hv_h.TupleMean());
                hv_wm = (hv_Concat.TupleMax()) / (hv_Concat.TupleMean());
                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected, hv_Number);
                HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row13, out hv_Column13,
                                                out hv_Row23, out hv_Column23);
                hv_zh = hv_Column23 - hv_Column13;
                HOperatorSet.Union1(ho_ConnectedRegions1, out RegionToDisp);

                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("最短比值");
                hv_result = hv_result.TupleConcat(hv_hm.D);
                hv_result = hv_result.TupleConcat("最宽比值");
                hv_result = hv_result.TupleConcat(hv_wm.D);
                hv_result = hv_result.TupleConcat("缺陷总面积");
                hv_result = hv_result.TupleConcat(hv_Area1.D);
                hv_result = hv_result.TupleConcat("最大缺陷面积");
                hv_result = hv_result.TupleConcat(hv_Area2.D);
                hv_result = hv_result.TupleConcat("宽度");
                hv_result = hv_result.TupleConcat(hv_zh.D);


                result = hv_result.Clone();
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_RegionLines.Dispose();
                ho_RegionUnion1.Dispose();
                ho_RegionUnion2.Dispose();
                ho_RegionUnion3.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_RegionFillUp.Dispose();
                ho_SelectedRegions.Dispose();
                ho_SortedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_Rectangle1.Dispose();
                ho_ImageReduced1.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                ho_Circle3.Dispose();
                ho_Circle4.Dispose();
                ho_RegionUnionc1.Dispose();
                ho_RegionUnionc2.Dispose();
                ho_RegionUnionc3.Dispose();
                ho_ConnectedRegionsc.Dispose();
                ho_SortedRegions1.Dispose();
                ho_ContoursL.Dispose();
                ho_RegionLinesL.Dispose();
                ho_RegionLinesL1.Dispose();
                ho_RegionUnionL.Dispose();
                ho_ConnectedRegionsL.Dispose();
                ho_SelectedRegionsL.Dispose();
                ho_RegionFillUpL.Dispose();
                ho_ContoursSplitL.Dispose();
                ho_SelectedContoursL.Dispose();
                ho_UnionContoursL.Dispose();
                ho_RegionL.Dispose();
                ho_RegionDifferenceL.Dispose();
                ho_ContoursR.Dispose();
                ho_RegionLinesR.Dispose();
                ho_RegionLinesR1.Dispose();
                ho_RegionUnionR.Dispose();
                ho_ConnectedRegionsR.Dispose();
                ho_SelectedRegionsR.Dispose();
                ho_RegionFillUpR.Dispose();
                ho_ContoursSplitR.Dispose();
                ho_SelectedContoursR.Dispose();
                ho_UnionContoursR.Dispose();
                ho_RegionR.Dispose();
                ho_RegionDifferenceR.Dispose();
                ho_ConnectedRegions1.Dispose();

                ho_ObjectSelected1.Dispose();
                algorithm.Region.Dispose();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("最短比值");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("最宽比值");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("缺陷总面积");
                hv_result = hv_result.TupleConcat(999999);
                hv_result = hv_result.TupleConcat("最大缺陷面积");
                hv_result = hv_result.TupleConcat(999999);
                hv_result = hv_result.TupleConcat("宽度");
                hv_result = hv_result.TupleConcat(999999);
                result    = hv_result.Clone();
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_RegionLines.Dispose();
                ho_RegionUnion1.Dispose();
                ho_RegionUnion2.Dispose();
                ho_RegionUnion3.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_RegionFillUp.Dispose();
                ho_SelectedRegions.Dispose();
                ho_SortedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_Rectangle1.Dispose();
                ho_ImageReduced1.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                ho_Circle3.Dispose();
                ho_Circle4.Dispose();
                ho_RegionUnionc1.Dispose();
                ho_RegionUnionc2.Dispose();
                ho_RegionUnionc3.Dispose();
                ho_ConnectedRegionsc.Dispose();
                ho_SortedRegions1.Dispose();
                ho_ContoursL.Dispose();
                ho_RegionLinesL.Dispose();
                ho_RegionLinesL1.Dispose();
                ho_RegionUnionL.Dispose();
                ho_ConnectedRegionsL.Dispose();
                ho_SelectedRegionsL.Dispose();
                ho_RegionFillUpL.Dispose();
                ho_ContoursSplitL.Dispose();
                ho_SelectedContoursL.Dispose();
                ho_UnionContoursL.Dispose();
                ho_RegionL.Dispose();
                ho_RegionDifferenceL.Dispose();
                ho_ContoursR.Dispose();
                ho_RegionLinesR.Dispose();
                ho_RegionLinesR1.Dispose();
                ho_RegionUnionR.Dispose();
                ho_ConnectedRegionsR.Dispose();
                ho_SelectedRegionsR.Dispose();
                ho_RegionFillUpR.Dispose();
                ho_ContoursSplitR.Dispose();
                ho_SelectedContoursR.Dispose();
                ho_UnionContoursR.Dispose();
                ho_RegionR.Dispose();
                ho_RegionDifferenceR.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_ObjectSelected1.Dispose();
                algorithm.Region.Dispose();
            }
            finally
            {
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Region.Dispose();
                ho_RegionLines.Dispose();
                ho_RegionUnion1.Dispose();
                ho_RegionUnion2.Dispose();
                ho_RegionUnion3.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_RegionFillUp.Dispose();
                ho_SelectedRegions.Dispose();
                ho_SortedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                ho_Rectangle1.Dispose();
                ho_ImageReduced1.Dispose();
                ho_Circle1.Dispose();
                ho_Circle2.Dispose();
                ho_Circle3.Dispose();
                ho_Circle4.Dispose();
                ho_RegionUnionc1.Dispose();
                ho_RegionUnionc2.Dispose();
                ho_RegionUnionc3.Dispose();
                ho_ConnectedRegionsc.Dispose();
                ho_SortedRegions1.Dispose();
                ho_ContoursL.Dispose();
                ho_RegionLinesL.Dispose();
                ho_RegionLinesL1.Dispose();
                ho_RegionUnionL.Dispose();
                ho_ConnectedRegionsL.Dispose();
                ho_SelectedRegionsL.Dispose();
                ho_RegionFillUpL.Dispose();
                ho_ContoursSplitL.Dispose();
                ho_SelectedContoursL.Dispose();
                ho_UnionContoursL.Dispose();
                ho_RegionL.Dispose();
                ho_RegionDifferenceL.Dispose();
                ho_ContoursR.Dispose();
                ho_RegionLinesR.Dispose();
                ho_RegionLinesR1.Dispose();
                ho_RegionUnionR.Dispose();
                ho_ConnectedRegionsR.Dispose();
                ho_SelectedRegionsR.Dispose();
                ho_RegionFillUpR.Dispose();
                ho_ContoursSplitR.Dispose();
                ho_SelectedContoursR.Dispose();
                ho_UnionContoursR.Dispose();
                ho_RegionR.Dispose();
                ho_RegionDifferenceR.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_ObjectSelected1.Dispose();
                algorithm.Region.Dispose();
            }
        }
Esempio n. 8
0
 public void ProcessImage(HTuple HDWindow_, string ImageFile_)
 {
     HDevWindowStack.Push(HDWindow_);
     ImageFile = ImageFile_;
     action();
 }
Esempio n. 9
0
        private void action()
        {
            // Local iconic variables

            HObject ho_Image, ho_DotImage, ho_Region, ho_RegionDilation;
            HObject ho_RegionClosing, ho_ConnectedRegions, ho_SelectedRegions;
            HObject ho_RegionUnion, ho_RegionClosing2, ho_ConnectedRegions2;
            HObject ho_SelectedRegions5, ho_RegionIntersection, ho_RegionAffineTrans1;
            HObject ho_RegionDilation1, ho_RegionClosing1, ho_RegionOpening;
            HObject ho_ConnectedRegions1, ho_SelectedRegions1, ho_RegionTrans;
            HObject ho_Partitioned, ho_SelectedRegions2, ho_RegionIntersection1;
            HObject ho_SortedRegions1, ho_SelectedRegions3, ho_RegionTrans1;
            HObject ho_Partitioned1, ho_SelectedRegions4, ho_RegionIntersection2;
            HObject ho_SortedRegions2;


            // Local control variables

            HTuple hv_Row, hv_Column, hv_Phi, hv_Length1;
            HTuple hv_Length2, hv_HomMat2DIdentity, hv_HomMat2DRotate;
            HTuple hv_Area, hv_Row1, hv_Column1, hv_Area11, hv_Row11;
            HTuple hv_Column11, hv_Area12, hv_Row12, hv_Column12;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_DotImage);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing2);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions5);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection);
            HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans1);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation1);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing1);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_RegionTrans);
            HOperatorSet.GenEmptyObj(out ho_Partitioned);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection1);
            HOperatorSet.GenEmptyObj(out ho_SortedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions3);
            HOperatorSet.GenEmptyObj(out ho_RegionTrans1);
            HOperatorSet.GenEmptyObj(out ho_Partitioned1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions4);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection2);
            HOperatorSet.GenEmptyObj(out ho_SortedRegions2);

            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, ImageFile);
            ho_DotImage.Dispose();
            HOperatorSet.DotsImage(ho_Image, out ho_DotImage, 5, "dark", 2);
            ho_Region.Dispose();
            HOperatorSet.Threshold(ho_DotImage, out ho_Region, 110, 255);
            ho_RegionDilation.Dispose();
            HOperatorSet.DilationCircle(ho_Region, out ho_RegionDilation, 2.5);
            ho_RegionClosing.Dispose();
            HOperatorSet.ClosingRectangle1(ho_RegionDilation, out ho_RegionClosing, 3, 3);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_RegionClosing, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, (new HTuple("width")).TupleConcat(
                                         "height"), "and", (new HTuple(15)).TupleConcat(15), (new HTuple(80)).TupleConcat(
                                         80));
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);
            ho_RegionClosing2.Dispose();
            HOperatorSet.ClosingRectangle1(ho_RegionUnion, out ho_RegionClosing2, 30, 20);
            ho_ConnectedRegions2.Dispose();
            HOperatorSet.Connection(ho_RegionClosing2, out ho_ConnectedRegions2);
            ho_SelectedRegions5.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions5, "area",
                                     "and", 10000, 20000);

            ho_RegionIntersection.Dispose();
            HOperatorSet.Intersection(ho_Region, ho_SelectedRegions5, out ho_RegionIntersection
                                      );
            HOperatorSet.SmallestRectangle2(ho_RegionIntersection, out hv_Row, out hv_Column,
                                            out hv_Phi, out hv_Length1, out hv_Length2);
            HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity);
            HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity, -hv_Phi, hv_Column, hv_Row,
                                        out hv_HomMat2DRotate);
            ho_RegionAffineTrans1.Dispose();
            HOperatorSet.AffineTransRegion(ho_RegionIntersection, out ho_RegionAffineTrans1,
                                           hv_HomMat2DRotate, "true");
            ho_RegionDilation1.Dispose();
            HOperatorSet.DilationCircle(ho_RegionAffineTrans1, out ho_RegionDilation1, 2.5);
            ho_RegionClosing1.Dispose();
            HOperatorSet.ClosingRectangle1(ho_RegionDilation1, out ho_RegionClosing1, 3,
                                           3);
            ho_RegionOpening.Dispose();
            HOperatorSet.OpeningCircle(ho_RegionClosing1, out ho_RegionOpening, 2.5);
            ho_ConnectedRegions1.Dispose();
            HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions1);
            HOperatorSet.AreaCenter(ho_RegionAffineTrans1, out hv_Area, out hv_Row1, out hv_Column1);

            ho_SelectedRegions1.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions1, "row",
                                     "and", hv_Row1 - 30, hv_Row1);
            ho_RegionTrans.Dispose();
            HOperatorSet.ShapeTrans(ho_SelectedRegions1, out ho_RegionTrans, "rectangle1");
            ho_Partitioned.Dispose();
            HOperatorSet.PartitionDynamic(ho_RegionTrans, out ho_Partitioned, 20, 20);
            ho_SelectedRegions2.Dispose();
            HOperatorSet.SelectShape(ho_Partitioned, out ho_SelectedRegions2, "height", "and",
                                     25, 48);
            ho_RegionIntersection1.Dispose();
            HOperatorSet.Intersection(ho_SelectedRegions2, ho_RegionAffineTrans1, out ho_RegionIntersection1
                                      );
            ho_SortedRegions1.Dispose();
            HOperatorSet.SortRegion(ho_RegionIntersection1, out ho_SortedRegions1, "first_point",
                                    "true", "column");
            HOperatorSet.AreaCenter(ho_SortedRegions1, out hv_Area11, out hv_Row11, out hv_Column11);

            ho_SelectedRegions3.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions3, "row",
                                     "and", hv_Row1, hv_Row1 + 40);
            ho_RegionTrans1.Dispose();
            HOperatorSet.ShapeTrans(ho_SelectedRegions3, out ho_RegionTrans1, "rectangle1");
            ho_Partitioned1.Dispose();
            HOperatorSet.PartitionDynamic(ho_RegionTrans1, out ho_Partitioned1, 20, 1);
            ho_SelectedRegions4.Dispose();
            HOperatorSet.SelectShape(ho_Partitioned1, out ho_SelectedRegions4, "height",
                                     "and", 25, 48);
            ho_RegionIntersection2.Dispose();
            HOperatorSet.Intersection(ho_SelectedRegions4, ho_RegionAffineTrans1, out ho_RegionIntersection2
                                      );
            ho_SortedRegions2.Dispose();
            HOperatorSet.SortRegion(ho_RegionIntersection2, out ho_SortedRegions2, "first_point",
                                    "true", "column");
            HOperatorSet.AreaCenter(ho_SortedRegions2, out hv_Area12, out hv_Row12, out hv_Column12);

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_SortedRegions1, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_SortedRegions2, HDevWindowStack.GetActive());
            }

            ho_Image.Dispose();
            ho_DotImage.Dispose();
            ho_Region.Dispose();
            ho_RegionDilation.Dispose();
            ho_RegionClosing.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionClosing2.Dispose();
            ho_ConnectedRegions2.Dispose();
            ho_SelectedRegions5.Dispose();
            ho_RegionIntersection.Dispose();
            ho_RegionAffineTrans1.Dispose();
            ho_RegionDilation1.Dispose();
            ho_RegionClosing1.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_RegionTrans.Dispose();
            ho_Partitioned.Dispose();
            ho_SelectedRegions2.Dispose();
            ho_RegionIntersection1.Dispose();
            ho_SortedRegions1.Dispose();
            ho_SelectedRegions3.Dispose();
            ho_RegionTrans1.Dispose();
            ho_Partitioned1.Dispose();
            ho_SelectedRegions4.Dispose();
            ho_RegionIntersection2.Dispose();
            ho_SortedRegions2.Dispose();

            Area = new HTuple();
            Area = Area.TupleConcat(hv_Area11);
            Area = Area.TupleConcat(hv_Area12);
        }
Esempio n. 10
0
    // Main procedure
    private void action()
    {
        // Local iconic variables

        HObject ho_Image, ho_EnhancedImage, ho_EnhancedEdge;

        // Local control variables

        HTuple hv_Width = null, hv_Height = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_EnhancedImage);
        HOperatorSet.GenEmptyObj(out ho_EnhancedEdge);
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
        }


        ho_Image.Dispose();
        HOperatorSet.ReadImage(out ho_Image, "_EnhanceEdgeArea_B2_Ori2.jpg");
        HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
        ho_EnhancedImage.Dispose(); ho_EnhancedEdge.Dispose();
        EnhanceEdgeArea4(ho_Image, out ho_EnhancedImage, out ho_EnhancedEdge, 33, 1,
                         10, 90, "true", 55, 5, 20, 0, 15);

        ho_Image.Dispose();
        HOperatorSet.ReadImage(out ho_Image, "_EnhanceEdgeArea_B1_Ori2.jpg");
        HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
        ho_EnhancedImage.Dispose(); ho_EnhancedEdge.Dispose();
        EnhanceEdgeArea4(ho_Image, out ho_EnhancedImage, out ho_EnhancedEdge, 33, 1,
                         10, 90, "true", 33, 7, 15, 0, 15);

        ho_Image.Dispose();
        HOperatorSet.ReadImage(out ho_Image, "_EnhanceEdgeArea_B1_Ori.jpg");
        HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
        ho_EnhancedImage.Dispose(); ho_EnhancedEdge.Dispose();
        EnhanceEdgeArea4(ho_Image, out ho_EnhancedImage, out ho_EnhancedEdge, 33, 1,
                         10, 90, "true", 33, 7, 15, 0, 10);


        ho_Image.Dispose();
        HOperatorSet.ReadImage(out ho_Image, "_EnhanceEdgeArea_T2_Ori.jpg");
        HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
        ho_EnhancedImage.Dispose(); ho_EnhancedEdge.Dispose();
        EnhanceEdgeArea4(ho_Image, out ho_EnhancedImage, out ho_EnhancedEdge, 33, 1,
                         10, 90, "true", 33, 7, 15, 0, 10);


        ho_Image.Dispose();
        HOperatorSet.ReadImage(out ho_Image, "_EnhanceEdgeArea_L3_Ori.jpg");
        HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
        ho_EnhancedImage.Dispose(); ho_EnhancedEdge.Dispose();
        EnhanceEdgeArea4(ho_Image, out ho_EnhancedImage, out ho_EnhancedEdge, 1, 33,
                         40, 85, "true", 3, 33, 15, 0, 10);


        // stop(); only in hdevelop


        ho_Image.Dispose();
        ho_EnhancedImage.Dispose();
        ho_EnhancedEdge.Dispose();
    }
Esempio n. 11
0
    // Main procedure
    public void action()
    {
        // Local iconic variables

        HObject ho_Image, ho_ImageMean, ho_DarkPixels;
        HObject ho_ConnectedRegions, ho_SelectedRegions, ho_RegionUnion;
        HObject ho_RegionDilation, ho_Skeleton, ho_Errors, ho_Scratches;
        HObject ho_Dots;

        // Local control variables

        HTuple hv_Width = null, hv_Height = null, hv_WindowID = null;
        HTuple hv_Message = null, hv_WindowHandleZoom = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_ImageMean);
        HOperatorSet.GenEmptyObj(out ho_DarkPixels);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_RegionUnion);
        HOperatorSet.GenEmptyObj(out ho_RegionDilation);
        HOperatorSet.GenEmptyObj(out ho_Skeleton);
        HOperatorSet.GenEmptyObj(out ho_Errors);
        HOperatorSet.GenEmptyObj(out ho_Scratches);
        HOperatorSet.GenEmptyObj(out ho_Dots);
        try
        {
            //This programm shows the extraction of surface scratches via
            //local thresholding and morphological post-processing
            //
            dev_update_off();
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.CloseWindow(HDevWindowStack.Pop());
            }
            //
            //Step 1: Acquire image
            //
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, "surface_scratch");
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
            dev_open_window_fit_image(ho_Image, 0, 0, hv_Width, hv_Width, out hv_WindowID);
            set_display_font(hv_WindowID, 16, "mono", "true", "false");
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 4);
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            hv_Message = "This program shows the extraction of";
            if (hv_Message == null)
            {
                hv_Message = new HTuple();
            }
            hv_Message[1] = "surface scratches via local thresholding";
            if (hv_Message == null)
            {
                hv_Message = new HTuple();
            }
            hv_Message[2] = "and morphological post-processing";
            disp_message(hv_WindowID, hv_Message, "window", 12, 12, "black", "true");
            disp_continue_message(hv_WindowID, "black", "true");
            // stop(...); only in hdevelop
            //
            //Step 2: Segment image
            //
            //Using a local threshold
            ho_ImageMean.Dispose();
            HOperatorSet.MeanImage(ho_Image, out ho_ImageMean, 7, 7);
            ho_DarkPixels.Dispose();
            HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_DarkPixels, 5, "dark");
            //
            //Extract connected components
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_DarkPixels, out ho_ConnectedRegions);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColored(HDevWindowStack.GetActive(), 12);
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_ConnectedRegions, HDevWindowStack.GetActive());
            }
            hv_Message = "Connected components after image segmentation";
            if (hv_Message == null)
            {
                hv_Message = new HTuple();
            }
            hv_Message[1] = "using a local threshold.";
            disp_message(hv_WindowID, hv_Message, "window", 12, 12, "black", "true");
            disp_continue_message(hv_WindowID, "black", "true");
            // stop(...); only in hdevelop
            //
            //Step 3: Process regions
            //
            //Select large regions
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", 10, 1000);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_SelectedRegions, HDevWindowStack.GetActive());
            }
            disp_message(hv_WindowID, "Large Regions", "window", 12, 12, "black", "true");
            disp_continue_message(hv_WindowID, "black", "true");
            // stop(...); only in hdevelop
            //
            //Visualize fractioned scratch
            open_zoom_window(0, ((hv_Width / 2)).TupleRound(), 2, 303, 137, 496, 3, out hv_WindowHandleZoom);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_SelectedRegions, HDevWindowStack.GetActive());
            }
            set_display_font(hv_WindowHandleZoom, 16, "mono", "true", "false");
            disp_message(hv_WindowHandleZoom, "Fractioned scratches", "window", 12, 12,
                         "black", "true");
            disp_continue_message(hv_WindowHandleZoom, "black", "true");
            // stop(...); only in hdevelop
            //
            //Merge fractioned scratches via morphology
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);
            ho_RegionDilation.Dispose();
            HOperatorSet.DilationCircle(ho_RegionUnion, out ho_RegionDilation, 3.5);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_RegionDilation, HDevWindowStack.GetActive());
            }
            hv_Message = "Region of the scratches after dilation";
            disp_message(hv_WindowHandleZoom, hv_Message, "window", 12, 12, "black", "true");
            disp_continue_message(hv_WindowHandleZoom, "black", "true");
            // stop(...); only in hdevelop
            ho_Skeleton.Dispose();
            HOperatorSet.Skeleton(ho_RegionDilation, out ho_Skeleton);
            ho_Errors.Dispose();
            HOperatorSet.Connection(ho_Skeleton, out ho_Errors);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColored(HDevWindowStack.GetActive(), 12);
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Errors, HDevWindowStack.GetActive());
            }
            hv_Message = "Fractioned scratches merged via morphology";
            disp_message(hv_WindowHandleZoom, hv_Message, "window", 12, 12, "black", "true");
            disp_continue_message(hv_WindowHandleZoom, "black", "true");
            // stop(...); only in hdevelop
            //
            //Distinguish small and large scratches
            close_zoom_window(hv_WindowHandleZoom, hv_Width, hv_Height);
            ho_Scratches.Dispose();
            HOperatorSet.SelectShape(ho_Errors, out ho_Scratches, "area", "and", 50, 10000);
            ho_Dots.Dispose();
            HOperatorSet.SelectShape(ho_Errors, out ho_Dots, "area", "and", 1, 50);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Scratches, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Dots, HDevWindowStack.GetActive());
            }
            hv_Message = "Extracted surface scratches";
            if (hv_Message == null)
            {
                hv_Message = new HTuple();
            }
            hv_Message[1] = "Not categorized as scratches";
            disp_message(hv_WindowID, hv_Message, "window", 440, 310, (new HTuple("red")).TupleConcat(
                             "blue"), "true");
        }
        catch (HalconException HDevExpDefaultException)
        {
            ho_Image.Dispose();
            ho_ImageMean.Dispose();
            ho_DarkPixels.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionDilation.Dispose();
            ho_Skeleton.Dispose();
            ho_Errors.Dispose();
            ho_Scratches.Dispose();
            ho_Dots.Dispose();

            throw HDevExpDefaultException;
        }
        ho_Image.Dispose();
        ho_ImageMean.Dispose();
        ho_DarkPixels.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_RegionUnion.Dispose();
        ho_RegionDilation.Dispose();
        ho_Skeleton.Dispose();
        ho_Errors.Dispose();
        ho_Scratches.Dispose();
        ho_Dots.Dispose();
    }
Esempio n. 12
0
        public MeasureResult Action()
        {
            #region 輸出結果
            LineResult mResult = null;
            #endregion
            // Local iconic variables

            HObject ho_A2_Region = null;
            HObject ho_A2_Reduced = null, ho_A2Region = null, ho_A2_RegionBorder = null;
            HObject ho_A2_RegionDilation = null, ho_A2_Edges = null, ho_A2_Rectangles = null;
            HObject ho_A2Cross = null, ho_A4Cross = 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_A2_Center_X, hv_A2_Center_Y;
            HTuple hv_STD_A2_1_1_Row, hv_STD_A2_1_1_Col, hv_STD_A2_1_1_V_Row;
            HTuple hv_STD_A2_1_1_V_Col, hv_A2_1_1_X, hv_A2_1_1_Y, hv_A2_1_1_Pos_Row;
            HTuple hv_A2_1_1_Pos_Col, hv_A2_ROI_W = new HTuple();
            HTuple hv_A2_ROI_H = new HTuple(), hv_Rec_W = new HTuple();
            HTuple hv_Rec_H = new HTuple(), hv_A2_Alpha = new HTuple();
            HTuple hv_a2low = new HTuple(), hv_a2high = new HTuple(), hv_a2Limit = new HTuple();
            HTuple hv_A2_RecNumber = new HTuple(), hv_A2Row = new HTuple();
            HTuple hv_A2Column = new HTuple(), hv_A2Phi = new HTuple();
            HTuple hv_A2Length1 = new HTuple(), hv_A2Length2 = new HTuple();
            HTuple hv_A2PointOrder = new HTuple(), hv_A2Number = new HTuple();
            HTuple hv_A4_Center_X, hv_A4_Center_Y, hv_STD_A4_Row, hv_STD_A4_Col;
            HTuple hv_STD_A4_V_Row, hv_STD_A4_V_Col, hv_A4_X, hv_A4_Y;
            HTuple hv_A4_Pos_Row, hv_A4_Pos_Col, hv_mini = new HTuple();
            HTuple hv_X1 = new HTuple(), hv_X2 = new HTuple();
            HTuple hv_Y1 = new HTuple(), hv_Y2 = new HTuple(), hv_STD_Mark_A4_C_Row = new HTuple();
            HTuple hv_STD_Mark_A4_C_Col = new HTuple(), hv_STD_Mark_A4_Start_Row = new HTuple();
            HTuple hv_STD_Mark_A4_Start_Col = new HTuple(), hv_STD_Mark_A4_End_Row = new HTuple();
            HTuple hv_STD_Mark_A4_End_Col = new HTuple(), hv_STD_Mark_A4_C_V_Row = new HTuple();
            HTuple hv_STD_Mark_A4_C_V_Col = new HTuple(), hv_Mark_A4_C_X = new HTuple();
            HTuple hv_Mark_A4_C_Y = new HTuple(), hv_Mark_A4_C_Pos_Row = new HTuple();
            HTuple hv_Mark_A4_C_Pos_Col = new HTuple(), hv_STD_Mark_A4_Start_V_Row = new HTuple();
            HTuple hv_STD_Mark_A4_Start_V_Col = new HTuple(), hv_Mark_A4_Start_X = new HTuple();
            HTuple hv_Mark_A4_Start_Y = new HTuple(), hv_Mark_A4_Start_Pos_Row = new HTuple();
            HTuple hv_Mark_A4_Start_Pos_Col = new HTuple(), hv_STD_Mark_A4_End_V_Row = new HTuple();
            HTuple hv_STD_Mark_A4_End_V_Col = new HTuple(), hv_Mark_A4_End_X = new HTuple();
            HTuple hv_Mark_A4_End_Y = new HTuple(), hv_Mark_A4_End_Pos_Row = new HTuple();
            HTuple hv_Mark_A4_End_Pos_Col = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_A2_Region);
            HOperatorSet.GenEmptyObj(out ho_A2_Reduced);
            HOperatorSet.GenEmptyObj(out ho_A2Region);
            HOperatorSet.GenEmptyObj(out ho_A2_RegionBorder);
            HOperatorSet.GenEmptyObj(out ho_A2_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_A2_Edges);
            HOperatorSet.GenEmptyObj(out ho_A2_Rectangles);
            HOperatorSet.GenEmptyObj(out ho_A2Cross);
            HOperatorSet.GenEmptyObj(out ho_A4Cross);

            //Measure: SDMS_A4
            //Author: John Hsieh
            //Date: 2012
            //Note: A4 related to A2
            //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 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;



            //*****A4
            //Step 1
            //找左邊數來第一個金手指的中心點 Finger
            hv_A2_Center_X = 0;
            hv_A2_Center_Y = 0;
            //****A2_1_1
            //STD A2_1_1_ 位置
            hv_STD_A2_1_1_Row = 410;
            hv_STD_A2_1_1_Col = 780;

            //STD 向量 STD_A2_1_1_
            hv_STD_A2_1_1_V_Row = hv_STD_A2_1_1_Row - hv_STD_Row;
            hv_STD_A2_1_1_V_Col = hv_STD_A2_1_1_Col - hv_STD_Col;


            //A2_1_1_X, A2_1_1_Y 分量
            hv_A2_1_1_X = (hv_STD_A2_1_1_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_A2_1_1_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                                                                                                             ));
            hv_A2_1_1_Y = (hv_STD_A2_1_1_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_A2_1_1_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                                                                                                             ));


            //目前圖形 A2_1_1_ 位置
            hv_A2_1_1_Pos_Row = (hv_STD_Row + hv_A2_1_1_Y) + hv_OffsetRow;
            hv_A2_1_1_Pos_Col = (hv_STD_Col + hv_A2_1_1_X) + hv_OffsetCol;


            //A2_ROI
            hv_A2_ROI_W = 40;
            hv_A2_ROI_H = 120;
            ho_A2_Region.Dispose();
            HOperatorSet.GenRectangle2(out ho_A2_Region, hv_A2_1_1_Pos_Row, hv_A2_1_1_Pos_Col,
                                       hv_Img_Rotate_Angle, hv_A2_ROI_W, hv_A2_ROI_H);
            //stop ()
            ho_A2_Reduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_A2_Region, out ho_A2_Reduced);
            //fit_Rectangle
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (Image)
            }
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (A2_Region)
            }
            //stop ()
            //
            ho_A2Region.Dispose();
            HOperatorSet.FastThreshold(ho_A2_Reduced, out ho_A2Region, 50, 150, 20);
            ho_A2_RegionBorder.Dispose();
            HOperatorSet.Boundary(ho_A2Region, out ho_A2_RegionBorder, "inner");
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (A2_RegionBorder)
            }
            hv_Rec_W = 11;
            hv_Rec_H = 11;
            ho_A2_RegionDilation.Dispose();
            HOperatorSet.DilationRectangle1(ho_A2_RegionBorder, out ho_A2_RegionDilation,
                                            hv_Rec_W, hv_Rec_H);
            hv_A2_Alpha = 0.9;
            hv_a2low    = 20;
            hv_a2high   = 110;
            ho_A2_Edges.Dispose();
            HOperatorSet.EdgesSubPix(ho_A2_Reduced, out ho_A2_Edges, "canny", hv_A2_Alpha,
                                     hv_a2low, hv_a2high);
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (A2_Edges)
            }
            //stop ()
            hv_a2Limit = 200;
            ho_A2_Rectangles.Dispose();
            HOperatorSet.SelectShapeXld(ho_A2_Edges, out ho_A2_Rectangles, "contlength",
                                        "and", hv_a2Limit, 99999);
            HOperatorSet.CountObj(ho_A2_Rectangles, out hv_A2_RecNumber);
            while ((int)(new HTuple(hv_A2_RecNumber.TupleGreater(1))) != 0)
            {
                hv_a2Limit = hv_a2Limit + 10;
                ho_A2_Rectangles.Dispose();
                HOperatorSet.SelectShapeXld(ho_A2_Edges, out ho_A2_Rectangles, "contlength",
                                            "and", hv_a2Limit, 99999);
                HOperatorSet.CountObj(ho_A2_Rectangles, out hv_A2_RecNumber);
            }
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (A2_Rectangles)
            }
            //stop ()
            HOperatorSet.FitRectangle2ContourXld(ho_A2_Rectangles, "regression", -1, 0,
                                                 0, 3, 2, out hv_A2Row, out hv_A2Column, out hv_A2Phi, out hv_A2Length1,
                                                 out hv_A2Length2, out hv_A2PointOrder);
            HOperatorSet.CountObj(ho_A2_Rectangles, out hv_A2Number);
            //取A2
            if ((int)(new HTuple(hv_A2Number.TupleGreater(0))) != 0)
            {
                hv_A2_Center_X = hv_A2Column[0];
                hv_A2_Center_Y = hv_A2Row[0];
                ho_A2Cross.Dispose();
                HOperatorSet.GenCrossContourXld(out ho_A2Cross, hv_A2Row, hv_A2Column, 10,
                                                0);

                mResult = new LineResult()
                {
                    Row1 = new HTuple(hv_A2Row),
                    Col1 = new HTuple(hv_A2Column),
                };
            }



            //Step2
            //找左邊數來第二個金手指的中心點 Finger
            hv_A4_Center_X = 0;
            hv_A4_Center_Y = 0;
            //****A4
            //STD A4_ 位置
            hv_STD_A4_Row = 418;
            hv_STD_A4_Col = 773;

            //STD 向量 STD_A4_
            hv_STD_A4_V_Row = hv_STD_A4_Row - hv_STD_Row;
            hv_STD_A4_V_Col = hv_STD_A4_Col - hv_STD_Col;


            //A4_X, A4_Y 分量
            hv_A4_X = (hv_STD_A4_V_Col * (hv_Img_Rotate_Angle.TupleCos())) + (hv_STD_A4_V_Row * (hv_Img_Rotate_Angle.TupleSin()
                                                                                                 ));
            hv_A4_Y = (hv_STD_A4_V_Row * (hv_Img_Rotate_Angle.TupleCos())) - (hv_STD_A4_V_Col * (hv_Img_Rotate_Angle.TupleSin()
                                                                                                 ));


            //目前圖形 A4_ 位置
            hv_A4_Pos_Row = (hv_STD_Row + hv_A4_Y) + hv_OffsetRow;
            hv_A4_Pos_Col = (hv_STD_Col + hv_A4_X) + hv_OffsetCol;


            //A2_ROI
            hv_A2_ROI_W = 160;
            hv_A2_ROI_H = 130;
            ho_A2_Region.Dispose();
            HOperatorSet.GenRectangle2(out ho_A2_Region, hv_A4_Pos_Row, hv_A4_Pos_Col,
                                       hv_Img_Rotate_Angle, hv_A2_ROI_W, hv_A2_ROI_H);
            //stop ()
            ho_A2_Reduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_A2_Region, out ho_A2_Reduced);
            //fit_Rectangle
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (A2_Region)
            }
            //stop ()
            //
            ho_A2Region.Dispose();
            HOperatorSet.FastThreshold(ho_A2_Reduced, out ho_A2Region, 50, 150, 20);
            ho_A2_RegionBorder.Dispose();
            HOperatorSet.Boundary(ho_A2Region, out ho_A2_RegionBorder, "inner");
            if (HDevWindowStack.IsOpen())
            {
                //dev_display (A2_RegionBorder)
            }
            hv_Rec_W = 11;
            hv_Rec_H = 11;
            ho_A2_RegionDilation.Dispose();
            HOperatorSet.DilationRectangle1(ho_A2_RegionBorder, out ho_A2_RegionDilation,
                                            hv_Rec_W, hv_Rec_H);
            hv_A2_Alpha = 4;
            ho_A2_Edges.Dispose();
            HOperatorSet.EdgesSubPix(ho_A2_Reduced, out ho_A2_Edges, "canny", hv_A2_Alpha,
                                     10, 50);
            hv_mini = 350;
            ho_A2_Rectangles.Dispose();
            HOperatorSet.SelectShapeXld(ho_A2_Edges, out ho_A2_Rectangles, "contlength",
                                        "and", hv_mini, 99999);
            HOperatorSet.CountObj(ho_A2_Rectangles, out hv_A2_RecNumber);
            while ((int)(new HTuple(hv_A2_RecNumber.TupleGreater(2))) != 0)
            {
                hv_mini = hv_mini + 10;
                ho_A2_Rectangles.Dispose();
                HOperatorSet.SelectShapeXld(ho_A2_Edges, out ho_A2_Rectangles, "contlength",
                                            "and", hv_mini, 99999);
                HOperatorSet.CountObj(ho_A2_Rectangles, out hv_A2_RecNumber);
            }
            HOperatorSet.FitRectangle2ContourXld(ho_A2_Rectangles, "regression", -1, 0,
                                                 0, 3, 2, out hv_A2Row, out hv_A2Column, out hv_A2Phi, out hv_A2Length1,
                                                 out hv_A2Length2, out hv_A2PointOrder);
            HOperatorSet.CountObj(ho_A2_Rectangles, out hv_A2Number);
            //取A4
            if ((int)(new HTuple(hv_A2Number.TupleGreater(1))) != 0)
            {
                //取 A4Object 資訊
                hv_A4_Center_X = hv_A2Column[1];
                hv_A4_Center_Y = hv_A2Row[1];
                ho_A4Cross.Dispose();
                HOperatorSet.GenCrossContourXld(out ho_A4Cross, hv_A4_Center_Y, hv_A4_Center_X, 10, 0);

                if (mResult != null)
                {
                    HOperatorSet.DistancePp(mResult.Row1, mResult.Col1, hv_A4_Center_Y, hv_A4_Center_X, out mResult.Distance);
                    mResult.Row2 = new HTuple(hv_A4_Center_Y);
                    mResult.Col2 = new HTuple(hv_A4_Center_X);
                }
            }



            //*****A4 End
            ho_A2_Region.Dispose();
            ho_A2_Reduced.Dispose();
            ho_A2Region.Dispose();
            ho_A2_RegionBorder.Dispose();
            ho_A2_RegionDilation.Dispose();
            ho_A2_Edges.Dispose();
            ho_A2_Rectangles.Dispose();
            ho_A2Cross.Dispose();
            ho_A4Cross.Dispose();


            return(mResult);
        }
Esempio n. 13
0
        // Main procedure
        public string  action(string fileName)
        {
            // Local iconic variables

            HObject ho_GrayImage, ho_Region, ho_ConnectedRegions;
            HObject ho_SelectedRegions2, ho_RegionTrans1, ho_RegionErosion;
            HObject ho_ImageReduced, ho_ImageCleared, ho_SymbolXLDs;


            // Local control variables

            HTuple hv_DataCodeHandle = null, hv_ResultHandles = null;
            HTuple hv_DecodedDataStrings = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_GrayImage);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_RegionTrans1);
            HOperatorSet.GenEmptyObj(out ho_RegionErosion);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImageCleared);
            HOperatorSet.GenEmptyObj(out ho_SymbolXLDs);

            try
            {
                ho_GrayImage.Dispose();
                HOperatorSet.ReadImage(out ho_GrayImage, fileName);
                ho_Region.Dispose();
                HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 0, 50);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions);
                //*消除噪声
                //mean_image (ImageReduced1, ImageMean, 200, 200)
                //*获得一个平滑处理后的参考图
                //dyn_threshold (GrayImage, ImageMean, RegionDynThresh, 5, 'light')
                //*填充图像中各个区域的小孔
                //fill_up (RegionDynThresh, RegionFillUp1)
                //connection (RegionDynThresh, ConnectedRegions2)
                ho_SelectedRegions2.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions2, "area",
                                         "and", 57000, 90000);

                //*变换成区域的最小外接矩形形状
                ho_RegionTrans1.Dispose();
                HOperatorSet.ShapeTrans(ho_SelectedRegions2, out ho_RegionTrans1, "rectangle2");
                //*用一个矩形结构元素膨胀图像
                ho_RegionErosion.Dispose();
                HOperatorSet.ErosionRectangle1(ho_RegionTrans1, out ho_RegionErosion, 5, 5);
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(ho_GrayImage, ho_RegionErosion, out ho_ImageReduced
                                          );

                //*创建一个指定的固定灰度值的图像
                ho_ImageCleared.Dispose();
                HOperatorSet.GenImageProto(ho_GrayImage, out ho_ImageCleared, 255);
                //*将灰度值不相同区域用不同颜色绘制到ImageDestination中, ImageSource包含希望的灰度值图像
                HOperatorSet.OverpaintGray(ho_ImageCleared, ho_ImageReduced);

                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
                }
                HOperatorSet.CreateDataCode2dModel("Data Matrix ECC 200", new HTuple(), new HTuple(),
                                                   out hv_DataCodeHandle);
                ho_SymbolXLDs.Dispose();
                HOperatorSet.FindDataCode2d(ho_ImageCleared, out ho_SymbolXLDs, hv_DataCodeHandle,
                                            "train", "all", out hv_ResultHandles, out hv_DecodedDataStrings);
                disp_message(3600, "条码" + hv_DecodedDataStrings, "window", 12, 12, "black", "true");
                string result = hv_DecodedDataStrings.ToString();
                return(result);
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_GrayImage.Dispose();
                ho_Region.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_RegionTrans1.Dispose();
                ho_RegionErosion.Dispose();
                ho_ImageReduced.Dispose();
                ho_ImageCleared.Dispose();
                ho_SymbolXLDs.Dispose();

                throw HDevExpDefaultException;
            }
            ho_GrayImage.Dispose();
            ho_Region.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions2.Dispose();
            ho_RegionTrans1.Dispose();
            ho_RegionErosion.Dispose();
            ho_ImageReduced.Dispose();
            ho_ImageCleared.Dispose();
            ho_SymbolXLDs.Dispose();
            return("");
        }
Esempio n. 14
0
        private void action()
        {
            // Local iconic variables

            HObject ho_ImageMean, ho_RegionDynThresh;
            HObject ho_RegionOpening, ho_ConnectedRegions, ho_SelectedRegions1;
            HObject ho_Rectangle, ho_Region1, ho_ConnectedRegions2;
            HObject ho_SelectedRegions3, ho_Circle, ho_SelectedRegions2;
            HObject ho_Circle2;

            // Local control variables

            HTuple hv_Row1 = null, hv_Column1 = null, hv_Phi = null;
            HTuple hv_Length1 = null, hv_Length2 = null, hv_Row = null;
            HTuple hv_Column = null, hv_Radius = null, hv_Row2 = null;
            HTuple hv_Column2 = null, hv_Radius2 = null, hv_DistanceMin = null;
            HTuple hv_DistanceMax = null, hv_RowArr = null, hv_ColArr = null;
            HTuple hv_RadiusArr = null, hv_Distance1 = null, hv_Distance2 = null;
            HTuple hv_Distance3 = null, hv_Distance4 = null, hv_Distance5 = null;
            HTuple hv_Distance6 = null, hv_DistanceArr = null, hv_Sorted = null;
            HTuple hv_Sorted1 = null;

            // Initialize local and output iconic variables
            //HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_ImageMean);
            HOperatorSet.GenEmptyObj(out ho_RegionDynThresh);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_Region1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions3);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_Circle2);
            try
            {
                ho_ImageMean.Dispose();
                HOperatorSet.MeanImage(Image, out ho_ImageMean, 70, 70);
                ho_RegionDynThresh.Dispose();
                HOperatorSet.DynThreshold(Image, ho_ImageMean, out ho_RegionDynThresh, 3.5,
                                          "dark");
                ho_RegionOpening.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionDynThresh, out ho_RegionOpening, 4);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions1, "area",
                                         "and", 150000, 9999900);
                HOperatorSet.SmallestRectangle2(ho_SelectedRegions1, out hv_Row1, out hv_Column1,
                                                out hv_Phi, out hv_Length1, out hv_Length2);
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle, hv_Row1, hv_Column1,
                                                     hv_Phi, hv_Length1, hv_Length2);
                ho_Region1.Dispose();
                HOperatorSet.Threshold(Image, out ho_Region1, 240, 255);
                ho_ConnectedRegions2.Dispose();
                HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions2);
                ho_SelectedRegions3.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions3, "area",
                                         "and", 150, 99999);
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
                }
                HOperatorSet.SmallestCircle(ho_SelectedRegions3, out hv_Row, out hv_Column,
                                            out hv_Radius);
                ho_Circle.Dispose();
                HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius);
                ho_SelectedRegions2.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions2, "area",
                                         "and", 70000, 99999);
                HOperatorSet.SmallestCircle(ho_SelectedRegions2, out hv_Row2, out hv_Column2,
                                            out hv_Radius2);
                ho_Circle2.Dispose();
                HOperatorSet.GenCircle(out ho_Circle2, hv_Row2, hv_Column2, hv_Radius2);
                HOperatorSet.DistancePc(ho_Rectangle, hv_Row2, hv_Column2, out hv_DistanceMin,
                                        out hv_DistanceMax);
                hv_RowArr    = new HTuple();
                hv_ColArr    = new HTuple();
                hv_RadiusArr = new HTuple();
                hv_RowArr    = hv_RowArr.TupleConcat(hv_Row);
                hv_ColArr    = hv_ColArr.TupleConcat(hv_Column);
                hv_RadiusArr = hv_RadiusArr.TupleConcat(hv_Radius);
                //*disp_line(3600,RowArr[0], ColArr[0], RowArr[1], ColArr[1])
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(0), hv_ColArr.TupleSelect(0),
                                        hv_RowArr.TupleSelect(1), hv_ColArr.TupleSelect(1), out hv_Distance1);
                //*disp_line(3600,RowArr[0], ColArr[0], RowArr[2], ColArr[2])
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(0), hv_ColArr.TupleSelect(0),
                                        hv_RowArr.TupleSelect(2), hv_ColArr.TupleSelect(2), out hv_Distance2);
                //*disp_line(3600,RowArr[1], ColArr[1], RowArr[3], ColArr[3])
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(1), hv_ColArr.TupleSelect(1),
                                        hv_RowArr.TupleSelect(3), hv_ColArr.TupleSelect(3), out hv_Distance3);
                //*disp_line(3600,RowArr[2], ColArr[2], RowArr[3], ColArr[3])
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(2), hv_ColArr.TupleSelect(2),
                                        hv_RowArr.TupleSelect(3), hv_ColArr.TupleSelect(3), out hv_Distance4);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(1), hv_ColArr.TupleSelect(1),
                                        hv_RowArr.TupleSelect(2), hv_ColArr.TupleSelect(2), out hv_Distance5);
                HOperatorSet.DistancePp(hv_RowArr.TupleSelect(0), hv_ColArr.TupleSelect(0),
                                        hv_RowArr.TupleSelect(3), hv_ColArr.TupleSelect(3), out hv_Distance6);
                hv_DistanceArr = new HTuple();
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance1);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance2);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance3);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance4);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance5);
                hv_DistanceArr = hv_DistanceArr.TupleConcat(hv_Distance6);
                HOperatorSet.TupleSort(hv_DistanceArr, out hv_Sorted);
                //disp_message(3600, "L1="+((hv_Sorted.TupleSelect(0))*pixeldist), "window", 10,
                //    10, "green", "false");
                //disp_message(3600, "L2="+((hv_Sorted.TupleSelect(1))*pixeldist), "window", 30,
                //    10, "green", "false");
                //disp_message(3600, "L3="+((hv_Sorted.TupleSelect(2))*pixeldist), "window", 50,
                //    10, "green", "false");
                //disp_message(3600, "L4="+((hv_Sorted.TupleSelect(3))*pixeldist), "window", 70,
                //    10, "green", "false");
                HOperatorSet.TupleSort(hv_RadiusArr, out hv_Sorted1);
                //disp_message(3600, "D1="+(((hv_Sorted1.TupleSelect(0))*pixeldist)*2), "window",
                //    90, 10, "green", "false");
                //disp_message(3600, "D2="+(((hv_Sorted1.TupleSelect(1))*pixeldist)*2), "window",
                //    110, 10, "green", "false");
                //disp_message(3600, "D3="+(((hv_Sorted1.TupleSelect(2))*pixeldist)*2), "window",
                //    130, 10, "green", "false");
                //disp_message(3600, "D4="+(((hv_Sorted1.TupleSelect(3))*pixeldist)*2), "window",
                //    150, 10, "green", "false");
                //disp_message(3600, "L="+((hv_Length1*pixeldist)*2), "window", 170, 10, "green",
                //    "false");
                //disp_message(3600, "W="+((hv_Length2*pixeldist)*2), "window", 190, 10, "green",
                //    "false");
                //disp_message(3600, "Ls1="+((hv_DistanceMin.TupleSelect(0))*pixeldist), "window",
                //    210, 10, "green", "false");
                //disp_message(3600, "Ls2="+((hv_DistanceMin.TupleSelect(1))*pixeldist), "window",
                //    230, 10, "green", "false");
                //}


                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("孔距L1");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(0)).D * pixeldist);
                hv_result = hv_result.TupleConcat("孔距L2");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(1)).D * pixeldist);
                hv_result = hv_result.TupleConcat("孔距L3");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(2)).D * pixeldist);
                hv_result = hv_result.TupleConcat("孔距L4");
                hv_result = hv_result.TupleConcat((hv_Sorted.TupleSelect(3)).D * pixeldist);
                hv_result = hv_result.TupleConcat("直径1");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(0)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("直径2");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(1)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("直径3");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(2)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("直径4");
                hv_result = hv_result.TupleConcat(((hv_Sorted1.TupleSelect(3)).D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("长度L");
                hv_result = hv_result.TupleConcat((hv_Length1.D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("宽度W");
                hv_result = hv_result.TupleConcat((hv_Length2.D * pixeldist) * 2);
                hv_result = hv_result.TupleConcat("圆心1到边缘1");
                hv_result = hv_result.TupleConcat((hv_DistanceMin.TupleSelect(0)).D * pixeldist);
                hv_result = hv_result.TupleConcat("圆心2到边缘2");
                hv_result = hv_result.TupleConcat((hv_DistanceMin.TupleSelect(1)).D * pixeldist);
                result    = hv_result.Clone();
            }
            catch
            {
                HTuple hv_result = GetHv_result();
                hv_result = hv_result.TupleConcat("孔距L1");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("孔距L2");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("孔距L3");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("孔距L4");
                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);
                hv_result = hv_result.TupleConcat("长度L");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("宽度W");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("圆心1到边缘1");
                hv_result = hv_result.TupleConcat(0);
                hv_result = hv_result.TupleConcat("圆心2到边缘2");
                hv_result = hv_result.TupleConcat(0);
                result    = hv_result.Clone();
            }
            finally
            {
                //ho_Image.Dispose();
                ho_RegionDynThresh.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_Rectangle.Dispose();
                ho_Region1.Dispose();
                ho_ConnectedRegions2.Dispose();
                ho_SelectedRegions3.Dispose();
                ho_Circle.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_Circle2.Dispose();
            }
        }
Esempio n. 15
0
    // Procedures
    // Chapter: Matching / Shape-Based
    // Short Description: Display the results of Shape-Based Matching.
    public void dev_display_shape_matching_results(HTuple hv_ModelID, HTuple hv_Color,
                                                   HTuple hv_Row, HTuple hv_Column, HTuple hv_Angle, HTuple hv_ScaleR, HTuple hv_ScaleC,
                                                   HTuple hv_Model)
    {
        // Local iconic variables

        HObject ho_ModelContours = null, ho_ContoursAffinTrans = null;

        // Local control variables

        HTuple hv_NumMatches = null, hv_Index = new HTuple();
        HTuple hv_Match = new HTuple(), hv_HomMat2DIdentity = new HTuple();
        HTuple hv_HomMat2DScale = new HTuple(), hv_HomMat2DRotate = new HTuple();
        HTuple hv_HomMat2DTranslate   = new HTuple();
        HTuple hv_Model_COPY_INP_TMP  = hv_Model.Clone();
        HTuple hv_ScaleC_COPY_INP_TMP = hv_ScaleC.Clone();
        HTuple hv_ScaleR_COPY_INP_TMP = hv_ScaleR.Clone();

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_ModelContours);
        HOperatorSet.GenEmptyObj(out ho_ContoursAffinTrans);
        try
        {
            //This procedure displays the results of Shape-Based Matching.
            //
            hv_NumMatches = new HTuple(hv_Row.TupleLength());
            if ((int)(new HTuple(hv_NumMatches.TupleGreater(0))) != 0)
            {
                if ((int)(new HTuple((new HTuple(hv_ScaleR_COPY_INP_TMP.TupleLength())).TupleEqual(
                                         1))) != 0)
                {
                    HOperatorSet.TupleGenConst(hv_NumMatches, hv_ScaleR_COPY_INP_TMP, out hv_ScaleR_COPY_INP_TMP);
                }
                if ((int)(new HTuple((new HTuple(hv_ScaleC_COPY_INP_TMP.TupleLength())).TupleEqual(
                                         1))) != 0)
                {
                    HOperatorSet.TupleGenConst(hv_NumMatches, hv_ScaleC_COPY_INP_TMP, out hv_ScaleC_COPY_INP_TMP);
                }
                if ((int)(new HTuple((new HTuple(hv_Model_COPY_INP_TMP.TupleLength())).TupleEqual(
                                         0))) != 0)
                {
                    HOperatorSet.TupleGenConst(hv_NumMatches, 0, out hv_Model_COPY_INP_TMP);
                }
                else if ((int)(new HTuple((new HTuple(hv_Model_COPY_INP_TMP.TupleLength()
                                                      )).TupleEqual(1))) != 0)
                {
                    HOperatorSet.TupleGenConst(hv_NumMatches, hv_Model_COPY_INP_TMP, out hv_Model_COPY_INP_TMP);
                }
                for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_ModelID.TupleLength()
                                                                      )) - 1); hv_Index = (int)hv_Index + 1)
                {
                    ho_ModelContours.Dispose();
                    HOperatorSet.GetShapeModelContours(out ho_ModelContours, hv_ModelID.TupleSelect(
                                                           hv_Index), 1);
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.SetColor(HDevWindowStack.GetActive(), hv_Color.TupleSelect(
                                                  hv_Index % (new HTuple(hv_Color.TupleLength()))));
                    }
                    HTuple end_val18  = hv_NumMatches - 1;
                    HTuple step_val18 = 1;
                    for (hv_Match = 0; hv_Match.Continue(end_val18, step_val18); hv_Match = hv_Match.TupleAdd(step_val18))
                    {
                        if ((int)(new HTuple(hv_Index.TupleEqual(hv_Model_COPY_INP_TMP.TupleSelect(
                                                                     hv_Match)))) != 0)
                        {
                            HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity);
                            HOperatorSet.HomMat2dScale(hv_HomMat2DIdentity, hv_ScaleR_COPY_INP_TMP.TupleSelect(
                                                           hv_Match), hv_ScaleC_COPY_INP_TMP.TupleSelect(hv_Match), 0, 0,
                                                       out hv_HomMat2DScale);
                            HOperatorSet.HomMat2dRotate(hv_HomMat2DScale, hv_Angle.TupleSelect(
                                                            hv_Match), 0, 0, out hv_HomMat2DRotate);
                            HOperatorSet.HomMat2dTranslate(hv_HomMat2DRotate, hv_Row.TupleSelect(
                                                               hv_Match), hv_Column.TupleSelect(hv_Match), out hv_HomMat2DTranslate);
                            ho_ContoursAffinTrans.Dispose();
                            HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ContoursAffinTrans,
                                                               hv_HomMat2DTranslate);
                            if (HDevWindowStack.IsOpen())
                            {
                                HOperatorSet.DispObj(ho_ContoursAffinTrans, HDevWindowStack.GetActive()
                                                     );
                            }
                        }
                    }
                }
            }
            ho_ModelContours.Dispose();
            ho_ContoursAffinTrans.Dispose();

            return;
        }
        catch (HalconException HDevExpDefaultException)
        {
            ho_ModelContours.Dispose();
            ho_ContoursAffinTrans.Dispose();

            throw HDevExpDefaultException;
        }
    }
Esempio n. 16
0
        private void btn_ExtractNinePoints_Click(object sender, EventArgs e)
        {
            HObject Region, ho_ConnectedRegions, ho_SelectedRegions, ho_SortedRegions, ho_ObjectSelected = null;
            HTuple  hv_Area, hv_CalRow = new HTuple(), hv_CalColumn = new HTuple(), hv_Number;

            double[] XCalPixelArray = new double[9];
            double[] YCalPixelArray = new double[9];


            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
            if (hv_image == null)
            {
                MessageBox.Show("hv_image");
                return;
            }
            HOperatorSet.Threshold(hv_image, out Region, MinThreshold, MaxThreshold);
            HOperatorSet.Connection(Region, out ho_ConnectedRegions);
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", MinArea, MaxArea);
            try
            {
                HOperatorSet.SortRegion(ho_SelectedRegions, out ho_SortedRegions, "character",
                                        "true", "row");

                HOperatorSet.AreaCenter(ho_SortedRegions, out hv_Area, out hv_CalRow, out hv_CalColumn);

                HOperatorSet.CountObj(ho_SortedRegions, out hv_Number);
                HTuple end_val9 = hv_Number;

                HTuple step_val9 = 1;

                if (hv_Number != 9)
                {
                    MessageBox.Show("提取的点不等于9" + "目前拥有的值是:" + hv_Number);
                    return;
                }
                if (HDevWindowStack.IsOpen())
                {
                    //清除窗口图片与信息
                    HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
                    //显示图片
                    HOperatorSet.DispObj(hv_image, HDevWindowStack.GetActive());
                    HOperatorSet.DispObj(ho_SortedRegions, HDevWindowStack.GetActive());
                }
                for (int i = 1; i < hv_Number + 1; i++)
                {
                    HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected, i);
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                    //HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Area, out hv_Row, out hv_Column);
                    HOperatorSet.DispCross(200000, hv_CalRow[i - 1], hv_CalColumn[i - 1], new HTuple(16), new HTuple(0));
                    disp_message(200000, i, "image", hv_CalRow[i - 1], hv_CalColumn[i - 1], "black", "true");

                    CalPicturePoints[i - 1].Text     = hv_CalRow[i - 1].D.ToString();
                    CalPicturePoints[9 + i - 1].Text = hv_CalColumn[i - 1].D.ToString();
                }

                //释放
                Region.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_SortedRegions.Dispose();
                ho_ObjectSelected.Dispose();
                //for (int i = 1; i < 10; i++)
                //{
                //    string Xname = "tbox_CalColumn" + i;
                //    string Yname = "tbox_CalRow" + i;
                //    GetControlObject<TextBox>(Xname).Text = Convert.ToString(XCalPixelArray[i - 1]);
                //    GetControlObject<TextBox>(Yname).Text = Convert.ToString(YCalPixelArray[i - 1]);

                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 17
0
    // Main procedure
    private void action()
    {
        // Local iconic variables

        HObject ho_Region, ho_SmoothedImage, ho_ReducedImage;
        HObject ho_ModelImages, ho_ModelRegions, ho_ConnectedRegions;
        HObject ho_SelectedRegions, ho_ModelContours, ho_TestImage = null;

        // Local control variables

        HTuple hv_WindowHandle = null, hv_Colors = null;
        HTuple hv_MinScore = null, hv_NumMatches = null, hv_AcqHandle = null;
        HTuple hv_Size = null, hv_Coeffs = null, hv_ModelID = null;
        HTuple hv_NumLevels = null, hv_AngleStart = null, hv_AngleExtent = null;
        HTuple hv_AngleStep = null, hv_ScaleMin = null, hv_ScaleMax = null;
        HTuple hv_ScaleStep = null, hv_Metric = null, hv_MinContrast = null;
        HTuple hv_keepGrabbing = null, hv_Row = new HTuple(), hv_Column = new HTuple();
        HTuple hv_Button = new HTuple(), hv_Exception = new HTuple();
        HTuple hv_ErrorCode = new HTuple(), hv_Angle = new HTuple();
        HTuple hv_Score = new HTuple(), hv_ScoreLength = new HTuple();
        HTuple hv_BestMatchScore = new HTuple(), hv_location = new HTuple();

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Region);
        HOperatorSet.GenEmptyObj(out ho_SmoothedImage);
        HOperatorSet.GenEmptyObj(out ho_ReducedImage);
        HOperatorSet.GenEmptyObj(out ho_ModelImages);
        HOperatorSet.GenEmptyObj(out ho_ModelRegions);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_ModelContours);
        HOperatorSet.GenEmptyObj(out ho_TestImage);
        try
        {
            // import(...); only in hdevelop
            // import(...); only in hdevelop

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.CloseWindow(HDevWindowStack.Pop());
            }
            HOperatorSet.SetWindowAttr("background_color", "white");
            HOperatorSet.OpenWindow(0, 0, 1024, 768, 0, "", "", out hv_WindowHandle);
            HDevWindowStack.Push(hv_WindowHandle);
            // dev_update_time(...); only in hdevelop
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 3);
            }
            hv_Colors     = new HTuple();
            hv_Colors[0]  = "red";
            hv_Colors[1]  = "green";
            hv_Colors[2]  = "cyan";
            hv_MinScore   = 0.5;
            hv_NumMatches = 1;

            //global object Image


            HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1,
                                          "default", -1, "false", "default", "00111cf51192_SENSORTECHNOLOGYCOLTD_STCGE83A",
                                          0, -1, out hv_AcqHandle);
            HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "ExposureTimeRaw", 9000);
            disp_message(hv_WindowHandle, "Press F5 to begin live grab. Press Left mouse click to exit live acquisition...",
                         "window", -1, -1, "black", "true");
            // stop(...); only in hdevelop
            abshear_async_acquisition(hv_WindowHandle, hv_AcqHandle);
            disp_message(hv_WindowHandle, "Hold down Left Mouse Button to select region",
                         "window", -1, -1, "black", "true");

            ho_Region.Dispose();
            HOperatorSet.DrawRegion(out ho_Region, hv_WindowHandle);

            HOperatorSet.InfoSmooth("deriche2", 0.3, out hv_Size, out hv_Coeffs);
            ho_SmoothedImage.Dispose();
            HOperatorSet.SmoothImage(ExpGetGlobalVar_Image(), out ho_SmoothedImage, "deriche2",
                                     0.3);

            ho_ReducedImage.Dispose();
            HOperatorSet.ReduceDomain(ho_SmoothedImage, ho_Region, out ho_ReducedImage);

            ho_ModelImages.Dispose(); ho_ModelRegions.Dispose();
            HOperatorSet.InspectShapeModel(ho_ReducedImage, out ho_ModelImages, out ho_ModelRegions,
                                           1, 160);

            //Since the shape models contain a few extraneous edges, they will be
            //removed here to give a slightly nicer visualization.
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_ModelRegions, out ho_ConnectedRegions);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", 20, 100000);
            ho_ModelRegions.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_ModelRegions);
            ho_ModelContours.Dispose();
            HOperatorSet.GenContoursSkeletonXld(ho_ModelRegions, out ho_ModelContours,
                                                1, "filter");

            HOperatorSet.CreateShapeModel(ho_ReducedImage, "auto", -0.39, 0.79, "auto",
                                          "auto", "use_polarity", "auto", "auto", out hv_ModelID);
            HOperatorSet.GetShapeModelParams(hv_ModelID, out hv_NumLevels, out hv_AngleStart,
                                             out hv_AngleExtent, out hv_AngleStep, out hv_ScaleMin, out hv_ScaleMax,
                                             out hv_ScaleStep, out hv_Metric, out hv_MinContrast);

            abshear_serialize_and_save(ho_SmoothedImage, hv_ModelID);

            hv_keepGrabbing = 1;
            while ((int)(hv_keepGrabbing) != 0)
            {
                try
                {
                    HOperatorSet.GetMposition(hv_WindowHandle, out hv_Row, out hv_Column, out hv_Button);
                }
                // catch (Exception)
                catch (HalconException HDevExpDefaultException1)
                {
                    HDevExpDefaultException1.ToHTuple(out hv_Exception);
                    hv_ErrorCode = hv_Exception.TupleSelect(0);
                }

                if ((int)(new HTuple(hv_Button.TupleEqual(1))) != 0)
                {
                    hv_keepGrabbing = 0;
                }

                //Grab and display an image for the matching
                ho_TestImage.Dispose();
                HOperatorSet.GrabImageAsync(out ho_TestImage, hv_AcqHandle, -1);
                ho_SmoothedImage.Dispose();
                HOperatorSet.SmoothImage(ho_TestImage, out ho_SmoothedImage, "deriche2",
                                         0.3);
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.DispObj(ho_TestImage, HDevWindowStack.GetActive());
                }
                HOperatorSet.FindShapeModel(ho_TestImage, hv_ModelID, -0.39, 0.79, hv_MinScore,
                                            hv_NumMatches, 0.5, "least_squares", 0, 0.9, out hv_Row, out hv_Column,
                                            out hv_Angle, out hv_Score);

                HDevWindowStack.SetActive(hv_WindowHandle);
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                }

                dev_display_shape_matching_results(hv_ModelID, "green", hv_Row, hv_Column,
                                                   hv_Angle, 1.0, 1.0, 0);
                HOperatorSet.TupleLength(hv_Score, out hv_ScoreLength);
                if ((int)(new HTuple(hv_ScoreLength.TupleGreater(0))) != 0)
                {
                    HOperatorSet.TupleFirstN(hv_Score, 0, out hv_BestMatchScore);
                    disp_message(hv_WindowHandle, "BestMatch: " + hv_BestMatchScore, "window",
                                 -1, -1, "black", "true");
                    hv_location = (("Location: " + hv_Row) + new HTuple(", ")) + hv_Column;
                    disp_message(hv_WindowHandle, hv_location, "window", 40, -1, "black", "true");
                }
                else
                {
                    disp_message(hv_WindowHandle, "No match found...", "window", -1, -1, "black",
                                 "true");
                }
            }

            HOperatorSet.CloseFramegrabber(hv_AcqHandle);
        }
        catch (HalconException HDevExpDefaultException)
        {
            ho_Region.Dispose();
            ho_SmoothedImage.Dispose();
            ho_ReducedImage.Dispose();
            ho_ModelImages.Dispose();
            ho_ModelRegions.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_ModelContours.Dispose();
            ho_TestImage.Dispose();

            throw HDevExpDefaultException;
        }
        ho_Region.Dispose();
        ho_SmoothedImage.Dispose();
        ho_ReducedImage.Dispose();
        ho_ModelImages.Dispose();
        ho_ModelRegions.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_ModelContours.Dispose();
        ho_TestImage.Dispose();
    }
Esempio n. 18
0
    // Main procedure
    private void action()
    {
        // Local iconic variables

        HObject ho_Image, ho_ModelRegion, ho_TemplateImage;
        HObject ho_ModelContours, ho_RectifiedImage = null, ho_Regions = null;
        HObject ho_ConnectedRegions = null, ho_SelectedRegions = null;
        HObject ho_Contours = null, ho_Regions1 = null, ho_RegionLines = null;

        // Local control variables

        HTuple hv_ModelID = new HTuple(), hv_ModelRegionArea = new HTuple();
        HTuple hv_RefRow = new HTuple(), hv_RefColumn = new HTuple();
        HTuple hv_TestImages = new HTuple(), hv_T = new HTuple();
        HTuple hv_Row = new HTuple(), hv_Column = new HTuple();
        HTuple hv_Angle = new HTuple(), hv_Score = new HTuple();
        HTuple hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple();
        HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
        HTuple hv_Radius = new HTuple(), hv_MetrologyHandle = new HTuple();
        HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
        HTuple hv_Index = new HTuple(), hv_Row3 = new HTuple();
        HTuple hv_Column3 = new HTuple(), hv_Parameter = new HTuple();
        HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
        HTuple hv_Radius1 = new HTuple(), hv_MetrologyHandle1 = new HTuple();
        HTuple hv_Index1 = new HTuple(), hv_Parameter1 = new HTuple();
        HTuple hv_SmlC = new HTuple(), hv_SR = new HTuple(), hv_SC = new HTuple();
        HTuple hv_BR = new HTuple(), hv_BC = new HTuple(), hv_Distance = new HTuple();

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_ModelRegion);
        HOperatorSet.GenEmptyObj(out ho_TemplateImage);
        HOperatorSet.GenEmptyObj(out ho_ModelContours);
        HOperatorSet.GenEmptyObj(out ho_RectifiedImage);
        HOperatorSet.GenEmptyObj(out ho_Regions);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_Contours);
        HOperatorSet.GenEmptyObj(out ho_Regions1);
        HOperatorSet.GenEmptyObj(out ho_RegionLines);
        //
        //Matching 01: ************************************************
        //Matching 01: BEGIN of generated code for model initialization
        //Matching 01: ************************************************
        HOperatorSet.SetSystem("border_shape_models", "false");
        //
        //Matching 01: Obtain the model image
        ho_Image.Dispose();
        HOperatorSet.ReadImage(out ho_Image, "C:/Users/Chanru/Desktop/Class/bd/bd1.png");
        //
        //Matching 01: Build the ROI from basic regions
        ho_ModelRegion.Dispose();
        HOperatorSet.GenRectangle1(out ho_ModelRegion, 445.809, 637.592, 801.311, 1070.62);
        //
        //Matching 01: Reduce the model template
        ho_TemplateImage.Dispose();
        HOperatorSet.ReduceDomain(ho_Image, ho_ModelRegion, out ho_TemplateImage);
        //
        //Matching 01: Create the shape model
        hv_ModelID.Dispose();
        HOperatorSet.CreateShapeModel(ho_TemplateImage, 6, (new HTuple(0)).TupleRad()
                                      , (new HTuple(360)).TupleRad(), (new HTuple(0.4233)).TupleRad(), (new HTuple("point_reduction_medium")).TupleConcat(
                                          "no_pregeneration"), "use_polarity", ((new HTuple(10)).TupleConcat(14)).TupleConcat(
                                          35), 3, out hv_ModelID);
        //
        //Matching 01: Get the model contour for transforming it later into the image
        ho_ModelContours.Dispose();
        HOperatorSet.GetShapeModelContours(out ho_ModelContours, hv_ModelID, 1);
        //
        //Matching 01: Get the reference position
        hv_ModelRegionArea.Dispose(); hv_RefRow.Dispose(); hv_RefColumn.Dispose();
        HOperatorSet.AreaCenter(ho_ModelRegion, out hv_ModelRegionArea, out hv_RefRow,
                                out hv_RefColumn);
        //
        //Matching 01: END of generated code for model initialization
        //Matching 01:  * * * * * * * * * * * * * * * * * * * * * * *
        //Matching 01: BEGIN of generated code for model application
        //
        //Matching 01: Loop over all specified test images
        hv_TestImages.Dispose();
        hv_TestImages    = new HTuple();
        hv_TestImages[0] = "C:/Users/Chanru/Desktop/Class/bd/bd1.png";
        hv_TestImages[1] = "C:/Users/Chanru/Desktop/Class/bd/bd10.png";
        hv_TestImages[2] = "C:/Users/Chanru/Desktop/Class/bd/bd2.png";
        hv_TestImages[3] = "C:/Users/Chanru/Desktop/Class/bd/bd3.png";
        hv_TestImages[4] = "C:/Users/Chanru/Desktop/Class/bd/bd4.png";
        hv_TestImages[5] = "C:/Users/Chanru/Desktop/Class/bd/bd5.png";
        hv_TestImages[6] = "C:/Users/Chanru/Desktop/Class/bd/bd6.png";
        hv_TestImages[7] = "C:/Users/Chanru/Desktop/Class/bd/bd7.png";
        hv_TestImages[8] = "C:/Users/Chanru/Desktop/Class/bd/bd8.png";
        hv_TestImages[9] = "C:/Users/Chanru/Desktop/Class/bd/bd9.png";
        for (hv_T = 0; (int)hv_T <= 9; hv_T = (int)hv_T + 1)
        {
            //
            //Matching 01: Obtain the test image
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, hv_TestImages.TupleSelect(hv_T));
            //
            //Matching 01: Find the model
            hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Score.Dispose();
            HOperatorSet.FindShapeModel(ho_Image, hv_ModelID, (new HTuple(0)).TupleRad()
                                        , (new HTuple(360)).TupleRad(), 0.5, 0, 0.5, "least_squares", (new HTuple(6)).TupleConcat(
                                            1), 0.75, out hv_Row, out hv_Column, out hv_Angle, out hv_Score);
            //
            //Matching 01: Code for rectification of the image
            //Matching 01: Calculate an inverse hom_mat2d for each of the matching results
            for (hv_I = 0; (int)hv_I <= (int)((new HTuple(hv_Score.TupleLength())) - 1); hv_I = (int)hv_I + 1)
            {
                hv_RectificationHomMat2D.Dispose();
                HOperatorSet.HomMat2dIdentity(out hv_RectificationHomMat2D);
                {
                    HTuple ExpTmpOutVar_0;
                    HOperatorSet.HomMat2dTranslate(hv_RectificationHomMat2D, hv_RefRow - (hv_Row.TupleSelect(
                                                                                              hv_I)), hv_RefColumn - (hv_Column.TupleSelect(hv_I)), out ExpTmpOutVar_0);
                    hv_RectificationHomMat2D.Dispose();
                    hv_RectificationHomMat2D = ExpTmpOutVar_0;
                }
                {
                    HTuple ExpTmpOutVar_0;
                    HOperatorSet.HomMat2dRotate(hv_RectificationHomMat2D, -(hv_Angle.TupleSelect(
                                                                                hv_I)), hv_RefRow, hv_RefColumn, out ExpTmpOutVar_0);
                    hv_RectificationHomMat2D.Dispose();
                    hv_RectificationHomMat2D = ExpTmpOutVar_0;
                }
                ho_RectifiedImage.Dispose();
                HOperatorSet.AffineTransImage(ho_Image, out ho_RectifiedImage, hv_RectificationHomMat2D,
                                              "constant", "false");
                //
                //Matching 01: Insert your code using the rectified image here

                ho_Regions.Dispose();
                HOperatorSet.Threshold(ho_Image, out ho_Regions, 99, 255);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", 150, 800);

                hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Radius.Dispose();
                HOperatorSet.SmallestCircle(ho_SelectedRegions, out hv_Row1, out hv_Column1,
                                            out hv_Radius);
                hv_MetrologyHandle.Dispose();
                HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);
                hv_Width.Dispose(); hv_Height.Dispose();
                HOperatorSet.GetImageSize(ho_RectifiedImage, out hv_Width, out hv_Height);
                HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandle, hv_Width, hv_Height);
                hv_Index.Dispose();
                HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, hv_Row1,
                                                             hv_Column1, hv_Radius, 20, 5, 1, 30, "num_measures", 30, out hv_Index);
                HOperatorSet.ApplyMetrologyModel(ho_RectifiedImage, hv_MetrologyHandle);
                ho_Contours.Dispose(); hv_Row3.Dispose(); hv_Column3.Dispose();
                HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours, hv_MetrologyHandle,
                                                        "all", "all", out hv_Row3, out hv_Column3);
                hv_Parameter.Dispose();
                HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type",
                                                      "all_param", out hv_Parameter);
                //*********

                ho_Regions1.Dispose();
                HOperatorSet.Threshold(ho_Image, out ho_Regions1, 22, 78);
                hv_Row2.Dispose(); hv_Column2.Dispose(); hv_Radius1.Dispose();
                HOperatorSet.SmallestCircle(ho_Regions1, out hv_Row2, out hv_Column2, out hv_Radius1);
                hv_MetrologyHandle1.Dispose();
                HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle1);
                HOperatorSet.SetMetrologyModelImageSize(hv_MetrologyHandle1, hv_Width, hv_Height);
                hv_Index1.Dispose();
                HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle1, hv_Row2,
                                                             hv_Column2, hv_Radius1, 20, 5, 1, 30, new HTuple(), new HTuple(), out hv_Index1);
                HOperatorSet.ApplyMetrologyModel(ho_RectifiedImage, hv_MetrologyHandle1);
                hv_Parameter1.Dispose();
                HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle1, "all", "all",
                                                      "result_type", "all_param", out hv_Parameter1);
                //*******

                hv_SmlC.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_SmlC = HTuple.TupleGenSequence(
                        0, (new HTuple(hv_Parameter.TupleLength())) - 1, 3);
                }
                hv_SR.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_SR = hv_Parameter.TupleSelect(
                        hv_SmlC);
                }
                hv_SC.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_SC = hv_Parameter.TupleSelect(
                        hv_SmlC + 1);
                }

                hv_BR.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_BR = (hv_SR * 0) + (hv_Parameter1.TupleSelect(
                                               0));
                }
                hv_BC.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_BC = (hv_SC * 0) + (hv_Parameter1.TupleSelect(
                                               1));
                }


                hv_Distance.Dispose();
                HOperatorSet.DistancePp(hv_SR, hv_SC, hv_BR, hv_BC, out hv_Distance);

                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.DispObj(ho_RectifiedImage, HDevWindowStack.GetActive());
                }
                ho_RegionLines.Dispose();
                HOperatorSet.GenRegionLine(out ho_RegionLines, hv_SR, hv_SC, hv_BR, hv_BC);
                // stop(...); only in hdevelop
            }
        }
        //
        //Matching 01: *******************************************
        //Matching 01: END of generated code for model application
        //Matching 01: *******************************************
        //

        ho_Image.Dispose();
        ho_ModelRegion.Dispose();
        ho_TemplateImage.Dispose();
        ho_ModelContours.Dispose();
        ho_RectifiedImage.Dispose();
        ho_Regions.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_Contours.Dispose();
        ho_Regions1.Dispose();
        ho_RegionLines.Dispose();

        hv_ModelID.Dispose();
        hv_ModelRegionArea.Dispose();
        hv_RefRow.Dispose();
        hv_RefColumn.Dispose();
        hv_TestImages.Dispose();
        hv_T.Dispose();
        hv_Row.Dispose();
        hv_Column.Dispose();
        hv_Angle.Dispose();
        hv_Score.Dispose();
        hv_I.Dispose();
        hv_RectificationHomMat2D.Dispose();
        hv_Row1.Dispose();
        hv_Column1.Dispose();
        hv_Radius.Dispose();
        hv_MetrologyHandle.Dispose();
        hv_Width.Dispose();
        hv_Height.Dispose();
        hv_Index.Dispose();
        hv_Row3.Dispose();
        hv_Column3.Dispose();
        hv_Parameter.Dispose();
        hv_Row2.Dispose();
        hv_Column2.Dispose();
        hv_Radius1.Dispose();
        hv_MetrologyHandle1.Dispose();
        hv_Index1.Dispose();
        hv_Parameter1.Dispose();
        hv_SmlC.Dispose();
        hv_SR.Dispose();
        hv_SC.Dispose();
        hv_BR.Dispose();
        hv_BC.Dispose();
        hv_Distance.Dispose();
    }
        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);
        }
Esempio n. 20
0
        public void SortRegions(HObject hv_image, List <TextBox> calPicturePoints)
        {
            HObject Region, ho_ConnectedRegions, ho_SelectedRegions, ho_SortedRegions = null, ho_ObjectSelected = null;
            HTuple  hv_Area, hv_CalRow = new HTuple(), hv_CalColumn = new HTuple(), hv_Number;

            // calPicturePoints = null;
            double[] XCalPixelArray = new double[9];
            double[] YCalPixelArray = new double[9];

            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
            try
            {
                if (hv_image == null)
                {
                    throw new MyException("hv_image bucunza不存在哟");
                }
            }
            catch (MyException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            HOperatorSet.Threshold(hv_image, out Region, _ThresholdMin, _ThresholdMax);
            HOperatorSet.Connection(Region, out ho_ConnectedRegions);
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", _AreaMin, _AreaMax);
            try
            {
                HOperatorSet.SortRegion(ho_SelectedRegions, out ho_SortedRegions, "character",
                                        "true", "row");

                HOperatorSet.AreaCenter(ho_SortedRegions, out hv_Area, out hv_CalRow, out hv_CalColumn);

                HOperatorSet.CountObj(ho_SortedRegions, out hv_Number);
                HTuple end_val9 = hv_Number;

                HTuple step_val9 = 1;

                if (hv_Number != 9)
                {
                    throw new MyException("提取的点不等于9" + "目前拥有的值是:" + hv_Number);
                }
                if (HDevWindowStack.IsOpen())
                {
                    //清除窗口图片与信息
                    HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
                    //显示图片
                    HOperatorSet.DispObj(hv_image, HDevWindowStack.GetActive());
                    HOperatorSet.DispObj(ho_SortedRegions, HDevWindowStack.GetActive());
                }
                else
                {
                    throw new MyException("窗体没有打开");
                }
                for (int i = 1; i < hv_Number + 1; i++)
                {
                    HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected, i);
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                    //HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Area, out hv_Row, out hv_Column);
                    HOperatorSet.DispCross(200000, hv_CalRow[i - 1], hv_CalColumn[i - 1], new HTuple(16), new HTuple(0));
                    disp_message(200000, i, "image", hv_CalRow[i - 1], hv_CalColumn[i - 1], "black", "true");
                    calPicturePoints[i - 1].Text     = hv_CalRow[i - 1].D.ToString();
                    calPicturePoints[9 + i - 1].Text = hv_CalColumn[i - 1].D.ToString();
                }
            }
            catch (MyException aex)
            {
                MessageBox.Show(aex.ToString());
            }
            finally
            {
                //释放
                if (Region != null)
                {
                    Region.Dispose();
                }
                if (ho_ConnectedRegions != null)
                {
                    ho_ConnectedRegions.Dispose();
                }
                if (ho_SelectedRegions != null)
                {
                    ho_SelectedRegions.Dispose();
                }
                if (ho_SortedRegions != null)
                {
                    ho_SortedRegions.Dispose();
                }
                if (ho_ObjectSelected != null)
                {
                    ho_ObjectSelected.Dispose();
                }
            }
        }
Esempio n. 21
0
        static private void dilate_regions_pro(HObject ho_image, out HObject ho_ConnectedDilations,
                                               HTuple hv_Row1OfRectangles, HTuple hv_Row2OfRectangles, HTuple hv_Column1OfRectangles,
                                               HTuple hv_Column2OfRectangles, HTuple hv_RadiusOfDilation, out HTuple hv_IndexOfRectangles,
                                               out HTuple hv_NumberListOfRectangles)
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];

            // Local iconic variables

            HObject ho_OrgRectangles = null, ho_RegionDilation = null;
            HObject ho_RegionUnion = null, ho_ConnectedRegions = null, ho_RectangleDilationSelected = null;
            HObject ho_RectangleSelected = null;

            // Local control variables

            HTuple hv_numOfRectangles = new HTuple();
            HTuple hv_Number = new HTuple(), hv_IndexOfConnectedRegions = new HTuple();
            HTuple hv_NumberOfRectangles = new HTuple(), hv_SubDefectIndexList = new HTuple();
            HTuple hv_IndexOfOrgRectangles = new HTuple(), hv_IsSubset = new HTuple();
            HTuple hv_Exception                        = null;
            HTuple hv_Column2OfRectangles_COPY_INP_TMP = hv_Column2OfRectangles.Clone();
            HTuple hv_RadiusOfDilation_COPY_INP_TMP    = hv_RadiusOfDilation.Clone();
            HTuple hv_Row2OfRectangles_COPY_INP_TMP    = hv_Row2OfRectangles.Clone();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_ConnectedDilations);
            HOperatorSet.GenEmptyObj(out ho_OrgRectangles);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RectangleDilationSelected);
            HOperatorSet.GenEmptyObj(out ho_RectangleSelected);
            try
            {
                dev_update_off();
                HOperatorSet.SetSystem("clip_region", "true");
                //
                ho_ConnectedDilations.Dispose();
                HOperatorSet.GenEmptyObj(out ho_ConnectedDilations);
                //
                hv_IndexOfRectangles      = new HTuple();
                hv_NumberListOfRectangles = new HTuple();
                //
                try
                {
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.DispObj(ho_image, HDevWindowStack.GetActive());
                    }
                    hv_numOfRectangles = 0;
                    HOperatorSet.TupleLength(hv_Row1OfRectangles, out hv_numOfRectangles);
                    if ((int)(new HTuple(hv_numOfRectangles.TupleLessEqual(0))) != 0)
                    {
                        ho_OrgRectangles.Dispose();
                        ho_RegionDilation.Dispose();
                        ho_RegionUnion.Dispose();
                        ho_ConnectedRegions.Dispose();
                        ho_RectangleDilationSelected.Dispose();
                        ho_RectangleSelected.Dispose();

                        return;
                    }
                    if ((int)((new HTuple((new HTuple(hv_numOfRectangles.TupleNotEqual(new HTuple(hv_Row2OfRectangles_COPY_INP_TMP.TupleLength()
                                                                                                  )))).TupleOr(new HTuple(hv_numOfRectangles.TupleNotEqual(new HTuple(hv_Column1OfRectangles.TupleLength()
                                                                                                                                                                      )))))).TupleOr(new HTuple(hv_numOfRectangles.TupleNotEqual(new HTuple(hv_Column2OfRectangles_COPY_INP_TMP.TupleLength()
                                                                                                                                                                                                                                            ))))) != 0)
                    {
                        ho_OrgRectangles.Dispose();
                        ho_RegionDilation.Dispose();
                        ho_RegionUnion.Dispose();
                        ho_ConnectedRegions.Dispose();
                        ho_RectangleDilationSelected.Dispose();
                        ho_RectangleSelected.Dispose();

                        return;
                    }
                    HOperatorSet.TupleMax2(hv_Row1OfRectangles, hv_Row2OfRectangles_COPY_INP_TMP,
                                           out hv_Row2OfRectangles_COPY_INP_TMP);
                    HOperatorSet.TupleMax2(hv_Column1OfRectangles, hv_Column2OfRectangles_COPY_INP_TMP,
                                           out hv_Column2OfRectangles_COPY_INP_TMP);
                    ho_OrgRectangles.Dispose();
                    HOperatorSet.GenRectangle1(out ho_OrgRectangles, hv_Row1OfRectangles, hv_Column1OfRectangles,
                                               hv_Row2OfRectangles_COPY_INP_TMP, hv_Column2OfRectangles_COPY_INP_TMP);
                    HOperatorSet.TupleMax2(1.5, hv_RadiusOfDilation_COPY_INP_TMP, out hv_RadiusOfDilation_COPY_INP_TMP);
                    ho_RegionDilation.Dispose();
                    HOperatorSet.DilationCircle(ho_OrgRectangles, out ho_RegionDilation, hv_RadiusOfDilation_COPY_INP_TMP);
                    ho_RegionUnion.Dispose();
                    HOperatorSet.Union1(ho_RegionDilation, out ho_RegionUnion);
                    ho_ConnectedRegions.Dispose();
                    HOperatorSet.Connection(ho_RegionUnion, out ho_ConnectedRegions);
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.SortRegion(ho_ConnectedRegions, out ExpTmpOutVar_0, "first_point",
                                                "true", "row");
                        ho_ConnectedRegions.Dispose();
                        ho_ConnectedRegions = ExpTmpOutVar_0;
                    }
                    HOperatorSet.CountObj(ho_ConnectedRegions, out hv_Number);
                    HTuple end_val27  = hv_Number;
                    HTuple step_val27 = 1;
                    for (hv_IndexOfConnectedRegions = 1; hv_IndexOfConnectedRegions.Continue(end_val27, step_val27); hv_IndexOfConnectedRegions = hv_IndexOfConnectedRegions.TupleAdd(step_val27))
                    {
                        hv_NumberOfRectangles = 0;
                        ho_RectangleDilationSelected.Dispose();
                        HOperatorSet.SelectObj(ho_ConnectedRegions, out ho_RectangleDilationSelected,
                                               hv_IndexOfConnectedRegions);
                        hv_SubDefectIndexList = new HTuple();
                        HTuple end_val31  = hv_numOfRectangles;
                        HTuple step_val31 = 1;
                        for (hv_IndexOfOrgRectangles = 1; hv_IndexOfOrgRectangles.Continue(end_val31, step_val31); hv_IndexOfOrgRectangles = hv_IndexOfOrgRectangles.TupleAdd(step_val31))
                        {
                            ho_RectangleSelected.Dispose();
                            HOperatorSet.SelectObj(ho_OrgRectangles, out ho_RectangleSelected, hv_IndexOfOrgRectangles);
                            HOperatorSet.TestSubsetRegion(ho_RectangleSelected, ho_RectangleDilationSelected,
                                                          out hv_IsSubset);
                            if ((int)(hv_IsSubset) != 0)
                            {
                                hv_IndexOfRectangles  = hv_IndexOfRectangles.TupleConcat(hv_IndexOfOrgRectangles - 1);
                                hv_NumberOfRectangles = hv_NumberOfRectangles + 1;
                            }
                        }
                        hv_NumberListOfRectangles = hv_NumberListOfRectangles.TupleConcat(hv_NumberOfRectangles);
                    }
                    ho_ConnectedDilations.Dispose();
                    ho_ConnectedDilations = ho_ConnectedRegions.CopyObj(1, -1);
                }
                // catch (Exception)
                catch (HalconException HDevExpDefaultException1)
                {
                    HDevExpDefaultException1.ToHTuple(out hv_Exception);
                    //do nothing.
                }
                //
                ho_OrgRectangles.Dispose();
                ho_RegionDilation.Dispose();
                ho_RegionUnion.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_RectangleDilationSelected.Dispose();
                ho_RectangleSelected.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_OrgRectangles.Dispose();
                ho_RegionDilation.Dispose();
                ho_RegionUnion.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_RectangleDilationSelected.Dispose();
                ho_RectangleSelected.Dispose();

                throw HDevExpDefaultException;
            }
        }
    // Procedures
#if !NO_EXPORT_MAIN
    // Main procedure
    private void action()
    {
        // Local iconic variables

        HObject ho_Image, ho_ImageRotate, ho_ROI_0;
        HObject ho_ImageReduced, ho_Regions, ho_RegionFillUp, ho_ConnectedRegions;
        HObject ho_SelectedRegions, ho_BinImage, ho_Characters;
        HObject ho_Image2, ho_ImageRotate2, ho_ROI_02, ho_ImageReduced2;
        HObject ho_Regions2, ho_RegionFillUp2, ho_ConnectedRegions2;
        HObject ho_SelectedRegions2, ho_BinImage2, ho_Characters2;

        // Local control variables

        HTuple hv_AcqHandle = null, hv_Width = null;
        HTuple hv_Height = null, hv_TextModel = null, hv_TextResultID = null;
        HTuple hv_ResultValue = null, hv_Width2 = null, hv_Height2 = null;
        HTuple hv_TextModel2 = null, hv_TextResultID2 = null, hv_ResultValue2 = null;
        HTuple hv_license = null, hv_container = null, hv_licLength = null;
        HTuple hv_i = null, hv_conLength = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_ImageRotate);
        HOperatorSet.GenEmptyObj(out ho_ROI_0);
        HOperatorSet.GenEmptyObj(out ho_ImageReduced);
        HOperatorSet.GenEmptyObj(out ho_Regions);
        HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_BinImage);
        HOperatorSet.GenEmptyObj(out ho_Characters);
        HOperatorSet.GenEmptyObj(out ho_Image2);
        HOperatorSet.GenEmptyObj(out ho_ImageRotate2);
        HOperatorSet.GenEmptyObj(out ho_ROI_02);
        HOperatorSet.GenEmptyObj(out ho_ImageReduced2);
        HOperatorSet.GenEmptyObj(out ho_Regions2);
        HOperatorSet.GenEmptyObj(out ho_RegionFillUp2);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
        HOperatorSet.GenEmptyObj(out ho_BinImage2);
        HOperatorSet.GenEmptyObj(out ho_Characters2);
        //open_framegrabber ('GenICamTL', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', '0x305316d5c4', 0, -1, AcqHandle)
        //Image Acquisition 01: Code generated by Image Acquisition 01
        //Image Acquisition 01: Code generated by Image Acquisition 01
        HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive",
                                      -1, "default", -1, "false", "default", "licenseCam", 0, -1, out hv_AcqHandle);
        //open_framegrabber ('GigEVision', 0, 0, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', 'licenseCam', 0, -1, AcqHandle)
        HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "AcquisitionMode", "SingleFrame");

        //set_framegrabber_param (AcqHandle, 'ExposureTimeAbs', 55555.0)
        HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
        //

        ho_Image.Dispose();
        HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
        HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
        ho_ImageRotate.Dispose();
        HOperatorSet.RotateImage(ho_Image, out ho_ImageRotate, 0, "constant");
        ho_Image.Dispose();
        HOperatorSet.AccessChannel(ho_ImageRotate, out ho_Image, 1);
        //OLD
        //gen_rectangle1 (ROI_0, 431.688, 468.25, 607.938, 1265.75)
        //gen_rectangle1 (ROI_0, 442.63, 403.582, 632.248, 1275.42)
        ho_ROI_0.Dispose();
        HOperatorSet.GenRectangle1(out ho_ROI_0, 490.034, 428.071, 681.714, 1339.09);


        //Remove large blobs
        //gray_closing_rect (Image, ImageClosing, 10, 10)
        //sub_image (Image, ImageClosing, ImageSub, 3, 0)
        //
        //Preprocessing to enhance contrast
        ho_ImageReduced.Dispose();
        HOperatorSet.ReduceDomain(ho_Image, ho_ROI_0, out ho_ImageReduced);
        ho_Regions.Dispose();
        HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, 0, 80);
        ho_RegionFillUp.Dispose();
        HOperatorSet.FillUpShape(ho_Regions, out ho_RegionFillUp, "area", 0, 40);
        ho_ConnectedRegions.Dispose();
        HOperatorSet.Connection(ho_RegionFillUp, out ho_ConnectedRegions);
        ho_SelectedRegions.Dispose();
        HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                 "and", 150, 99999);
        ho_BinImage.Dispose();
        HOperatorSet.RegionToBin(ho_SelectedRegions, out ho_BinImage, 0, 255, hv_Width,
                                 hv_Height);
        //
        //Perform OCR using the automatic text model reader
        HOperatorSet.CreateTextModelReader("auto", "Industrial_0-9+_Rej.omc", out hv_TextModel);
        //set_text_model_param (TextModel, 'max_char_height', 200)
        //set_text_model_param (TextModel, 'min_char_height', 20)
        //set_text_model_param (TextModel, 'min_char_width', 5)
        //set_text_model_param (TextModel, 'max_char_width', 175)
        //set_text_model_param (TextModel, 'return_separators', 'false')
        //set_text_model_param (TextModel, 'min_contrast', 30)
        HOperatorSet.FindText(ho_BinImage, hv_TextModel, out hv_TextResultID);
        //
        //Get the results from the OCR
        ho_Characters.Dispose();
        HOperatorSet.GetTextObject(out ho_Characters, hv_TextResultID, "all_lines");
        HOperatorSet.GetTextResult(hv_TextResultID, "class", out hv_ResultValue);
        //
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
        }
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
        }
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.DispObj(ho_Characters, HDevWindowStack.GetActive());
        }
        //do memory cleanup here
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
        }
        dev_update_on();

        HOperatorSet.CloseFramegrabber(hv_AcqHandle);



        //********************************************second camera

        //Image Acquisition 02: Code generated by Image Acquisition 02
        //open_framegrabber ('GigEVision', 0, 0, 0, 0, 0, 0, 'default', -1, 'default', -1, 'false', 'default', 'containerCam', 0, -1, AcqHandle)
        //Image Acquisition 02: Code generated by Image Acquisition 02
        HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive",
                                      -1, "default", -1, "false", "default", "containerCam", 0, -1, out hv_AcqHandle);

        //open_framegrabber ('GenICamTL', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', '0x3053228741', 0, -1, AcqHandle)
        //set_framegrabber_param (AcqHandle, 'ExposureTimeAbs', 55555.0)
        HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
        //
        ho_Image2.Dispose();
        HOperatorSet.GrabImageAsync(out ho_Image2, hv_AcqHandle, -1);
        HOperatorSet.GetImageSize(ho_Image2, out hv_Width2, out hv_Height2);
        ho_ImageRotate2.Dispose();
        HOperatorSet.RotateImage(ho_Image2, out ho_ImageRotate2, 180, "constant");
        ho_Image2.Dispose();
        HOperatorSet.AccessChannel(ho_ImageRotate2, out ho_Image2, 1);
        //OLD
        //gen_rectangle1 (ROI_02, 330.438, 690.75, 459.813, 1548.25)
        //gen_rectangle1 (ROI_02, 30.416, 658.276, 199.424, 1564.4)
        ho_ROI_02.Dispose();
        HOperatorSet.GenRectangle1(out ho_ROI_02, -4.62214, 670.52, 114.92, 1527.66);

        //Remove large blobs
        //gray_closing_rect (Image2, ImageClosing2, 10, 10)
        //sub_image (Image2, ImageClosing2, ImageSub2, 3, 180)
        //
        //Preprocessing to enhance contrast
        ho_ImageReduced2.Dispose();
        HOperatorSet.ReduceDomain(ho_Image2, ho_ROI_02, out ho_ImageReduced2);
        ho_Regions2.Dispose();
        HOperatorSet.Threshold(ho_ImageReduced2, out ho_Regions2, 0, 120);
        ho_RegionFillUp2.Dispose();
        HOperatorSet.FillUpShape(ho_Regions2, out ho_RegionFillUp2, "area", 0, 40);
        ho_ConnectedRegions2.Dispose();
        HOperatorSet.Connection(ho_RegionFillUp2, out ho_ConnectedRegions2);
        ho_SelectedRegions2.Dispose();
        HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions2, "area",
                                 "and", 150, 99999);
        ho_BinImage2.Dispose();
        HOperatorSet.RegionToBin(ho_SelectedRegions2, out ho_BinImage2, 255, 0, hv_Width2,
                                 hv_Height2);
        //
        //Perform OCR using the automatic text model reader
        HOperatorSet.CreateTextModelReader("auto", "Industrial_0-9A-Z_Rej.omc", out hv_TextModel2);
        //set_text_model_param (TextModel2, 'max_char_height', 200)
        //set_text_model_param (TextModel2, 'min_char_height', 1)
        //set_text_model_param (TextModel2, 'min_char_width', 1)
        //set_text_model_param (TextModel2, 'max_char_width', 175)
        //set_text_model_param (TextModel2, 'return_separators', 'false')
        //set_text_model_param (TextModel2, 'min_contrast', 30)
        HOperatorSet.FindText(ho_BinImage2, hv_TextModel2, out hv_TextResultID2);
        //
        //Get the results from the OCR
        ho_Characters2.Dispose();
        HOperatorSet.GetTextObject(out ho_Characters2, hv_TextResultID2, "all_lines");
        HOperatorSet.GetTextResult(hv_TextResultID2, "class", out hv_ResultValue2);
        //
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.DispObj(ho_Image2, HDevWindowStack.GetActive());
        }
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
        }
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.DispObj(ho_Characters2, HDevWindowStack.GetActive());
        }
        //do memory cleanup here
        if (HDevWindowStack.IsOpen())
        {
            HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
        }
        dev_update_on();

        HOperatorSet.CloseFramegrabber(hv_AcqHandle);
        hv_license   = "";
        hv_container = "";
        HOperatorSet.TupleStrlen(hv_ResultValue, out hv_licLength);
        HOperatorSet.TupleSum(hv_licLength, out hv_licLength);
        HTuple end_val117  = hv_licLength - 1;
        HTuple step_val117 = 1;

        for (hv_i = 0; hv_i.Continue(end_val117, step_val117); hv_i = hv_i.TupleAdd(step_val117))
        {
            hv_license = hv_license + (hv_ResultValue.TupleSelect(hv_i));
        }
        HOperatorSet.TupleStrlen(hv_ResultValue2, out hv_conLength);
        HOperatorSet.TupleSum(hv_conLength, out hv_conLength);
        HTuple end_val122  = hv_conLength - 1;
        HTuple step_val122 = 1;

        for (hv_i = 0; hv_i.Continue(end_val122, step_val122); hv_i = hv_i.TupleAdd(step_val122))
        {
            hv_container = hv_container + (hv_ResultValue2.TupleSelect(hv_i));
        }
        hv_license = hv_license.TupleSelect(0);


        ho_Image.Dispose();
        ho_ImageRotate.Dispose();
        ho_ROI_0.Dispose();
        ho_ImageReduced.Dispose();
        ho_Regions.Dispose();
        ho_RegionFillUp.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_BinImage.Dispose();
        ho_Characters.Dispose();
        ho_Image2.Dispose();
        ho_ImageRotate2.Dispose();
        ho_ROI_02.Dispose();
        ho_ImageReduced2.Dispose();
        ho_Regions2.Dispose();
        ho_RegionFillUp2.Dispose();
        ho_ConnectedRegions2.Dispose();
        ho_SelectedRegions2.Dispose();
        ho_BinImage2.Dispose();
        ho_Characters2.Dispose();
    }