示例#1
0
    // Main procedure
    private void action()
    {
        // Local iconic variables

        HObject ho_Image, ho_Image1, ho_Image2, ho_Image3;
        HObject ho_ImageResult1, ho_ImageResult2, ho_ImageResult3;
        HObject ho_ClassRegionsNotRejected, ho_ObjectSelected, ho_RegionOpening2;
        HObject ho_ConnectedRegions, ho_SelectedRegions, ho_RegionUnion;
        HObject ho_RegionOpening, ho_RegionTrans, ho_ImageReduced;
        HObject ho_ObjectSelected1, ho_RegionOpening1, ho_RegionFillUp;
        HObject ho_RegionClosing, ho_ConnectedRegions1, ho_SelectedRegions1;
        HObject ho_Rectangle;


        // Local control variables

        HTuple hv_WindowHandle, hv_MLPHandle, hv_MLPHandle1;
        HTuple hv_Row1, hv_Column1, hv_Phi, hv_Length1, hv_Length2;
        HTuple hv_Area, hv_Row, hv_Column;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_Image1);
        HOperatorSet.GenEmptyObj(out ho_Image2);
        HOperatorSet.GenEmptyObj(out ho_Image3);
        HOperatorSet.GenEmptyObj(out ho_ImageResult1);
        HOperatorSet.GenEmptyObj(out ho_ImageResult2);
        HOperatorSet.GenEmptyObj(out ho_ImageResult3);
        HOperatorSet.GenEmptyObj(out ho_ClassRegionsNotRejected);
        HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
        HOperatorSet.GenEmptyObj(out ho_RegionOpening2);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_RegionUnion);
        HOperatorSet.GenEmptyObj(out ho_RegionOpening);
        HOperatorSet.GenEmptyObj(out ho_RegionTrans);
        HOperatorSet.GenEmptyObj(out ho_ImageReduced);
        HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
        HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
        HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
        HOperatorSet.GenEmptyObj(out ho_RegionClosing);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
        HOperatorSet.GenEmptyObj(out ho_Rectangle);

        try
        {
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, new HTuple(new HTuple("C:/Code/Halcon/╪Л╡Бспнч/м╪ф╛1/") + 1) + ".jpg");
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.CloseWindow(HDevWindowStack.Pop());
            }
            dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle);

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }


            HOperatorSet.ReadClassMlp("mlp_1.gmc", out hv_MLPHandle);
            HOperatorSet.ReadClassMlp("mlp_2.gmc", out hv_MLPHandle1);


            HOperatorSet.SetTposition(hv_WindowHandle, 10, 10);
            set_display_font(hv_WindowHandle, 50, "mono", "true", "false");

            ho_Image1.Dispose();
            ho_Image2.Dispose();
            ho_Image3.Dispose();
            HOperatorSet.Decompose3(ho_Image, out ho_Image1, out ho_Image2, out ho_Image3
                                    );
            ho_ImageResult1.Dispose();
            ho_ImageResult2.Dispose();
            ho_ImageResult3.Dispose();
            HOperatorSet.TransFromRgb(ho_Image1, ho_Image2, ho_Image3, out ho_ImageResult1,
                                      out ho_ImageResult2, out ho_ImageResult3, "hsv");
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image3, HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetColored(HDevWindowStack.GetActive(), 12);
            }

            ho_ClassRegionsNotRejected.Dispose();
            HOperatorSet.ClassifyImageClassMlp(ho_Image, out ho_ClassRegionsNotRejected,
                                               hv_MLPHandle, 0.5);

            ho_ObjectSelected.Dispose();
            HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected, 1);
            ho_RegionOpening2.Dispose();
            HOperatorSet.OpeningCircle(ho_ObjectSelected, out ho_RegionOpening2, 5);


            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_RegionOpening2, out ho_ConnectedRegions);

            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", 6000.2, 159205);
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);

            ho_RegionOpening.Dispose();
            HOperatorSet.OpeningCircle(ho_RegionUnion, out ho_RegionOpening, 3.5);

            ho_RegionTrans.Dispose();
            HOperatorSet.ShapeTrans(ho_RegionOpening, out ho_RegionTrans, "circle");
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_RegionTrans, HDevWindowStack.GetActive());
            }

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "fill");
            }
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_RegionTrans, out ho_ImageReduced);
            ho_ClassRegionsNotRejected.Dispose();
            HOperatorSet.ClassifyImageClassMlp(ho_ImageReduced, out ho_ClassRegionsNotRejected,
                                               hv_MLPHandle1, 0.5);

            ho_ObjectSelected1.Dispose();
            HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected1,
                                   4);

            ho_RegionOpening1.Dispose();
            HOperatorSet.OpeningCircle(ho_ObjectSelected1, out ho_RegionOpening1, 3.5);

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

            ho_RegionClosing.Dispose();
            HOperatorSet.ClosingCircle(ho_RegionFillUp, out ho_RegionClosing, 10);

            ho_ConnectedRegions1.Dispose();
            HOperatorSet.Connection(ho_RegionClosing, out ho_ConnectedRegions1);

            ho_SelectedRegions1.Dispose();
            HOperatorSet.SelectShapeStd(ho_ConnectedRegions1, out ho_SelectedRegions1,
                                        "max_area", 70);


            HOperatorSet.SmallestRectangle2(ho_SelectedRegions1, out hv_Row1, out hv_Column1,
                                            out hv_Phi, out hv_Length1, out hv_Length2);
            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row1, hv_Column1, hv_Phi, hv_Length1,
                                       hv_Length2);


            HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area, out hv_Row, out hv_Column);
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetDraw(HDevWindowStack.GetActive(), "margin");
            }
            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.ClearWindow(HDevWindowStack.GetActive());
            }

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.DispObj(ho_Image, HDevWindowStack.GetActive());
            }



            if ((int)((new HTuple((new HTuple((new HTuple(hv_Length1.TupleLess(200))).TupleAnd(
                                                  new HTuple(hv_Length2.TupleLess(200))))).TupleAnd(new HTuple(hv_Length1.TupleGreater(
                                                                                                                   50))))).TupleAnd(new HTuple(hv_Length2.TupleGreater(50)))) != 0)
            {
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                }
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.DispObj(ho_Rectangle, HDevWindowStack.GetActive());
                }
                HOperatorSet.WriteString(hv_WindowHandle, "OK");
                //set_framegrabber_param (AcqHandle, 'UserOutputValue', 0)
            }
            else
            {
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "red");
                }
                HOperatorSet.WriteString(hv_WindowHandle, "NG");
                //set_framegrabber_param (AcqHandle, 'UserOutputValue', 1)
            }
        }
        catch (HalconException HDevExpDefaultException)
        {
            ho_Image.Dispose();
            ho_Image1.Dispose();
            ho_Image2.Dispose();
            ho_Image3.Dispose();
            ho_ImageResult1.Dispose();
            ho_ImageResult2.Dispose();
            ho_ImageResult3.Dispose();
            ho_ClassRegionsNotRejected.Dispose();
            ho_ObjectSelected.Dispose();
            ho_RegionOpening2.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionOpening.Dispose();
            ho_RegionTrans.Dispose();
            ho_ImageReduced.Dispose();
            ho_ObjectSelected1.Dispose();
            ho_RegionOpening1.Dispose();
            ho_RegionFillUp.Dispose();
            ho_RegionClosing.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_Rectangle.Dispose();

            throw HDevExpDefaultException;
        }
        ho_Image.Dispose();
        ho_Image1.Dispose();
        ho_Image2.Dispose();
        ho_Image3.Dispose();
        ho_ImageResult1.Dispose();
        ho_ImageResult2.Dispose();
        ho_ImageResult3.Dispose();
        ho_ClassRegionsNotRejected.Dispose();
        ho_ObjectSelected.Dispose();
        ho_RegionOpening2.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_RegionUnion.Dispose();
        ho_RegionOpening.Dispose();
        ho_RegionTrans.Dispose();
        ho_ImageReduced.Dispose();
        ho_ObjectSelected1.Dispose();
        ho_RegionOpening1.Dispose();
        ho_RegionFillUp.Dispose();
        ho_RegionClosing.Dispose();
        ho_ConnectedRegions1.Dispose();
        ho_SelectedRegions1.Dispose();
        ho_Rectangle.Dispose();
    }
示例#2
0
        public bool TestCake(HWindow WindowHandle)
        {
            // Local iconic variables
            var     StartTime = DateTime.Now.Ticks;
            HObject ho_Image1, ho_Image2, ho_Image3;
            HObject ho_ImageResult1, ho_ImageResult2, ho_ImageResult3;
            HObject ho_ClassRegionsNotRejected, ho_ObjectSelected, ho_RegionOpening2;
            HObject ho_ConnectedRegions, ho_SelectedRegions, ho_RegionUnion;
            HObject ho_RegionOpening, ho_RegionTrans, ho_ImageReduced;
            HObject ho_ObjectSelected1, ho_RegionOpening1, ho_RegionFillUp;
            HObject ho_RegionClosing, ho_ConnectedRegions1, ho_SelectedRegions1;
            HObject ho_Rectangle;

            // Local control variables

            HTuple hv_Row1, hv_Column1, hv_Phi, hv_Length1, hv_Length2;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_Image1);
            HOperatorSet.GenEmptyObj(out ho_Image2);
            HOperatorSet.GenEmptyObj(out ho_Image3);
            HOperatorSet.GenEmptyObj(out ho_ImageResult1);
            HOperatorSet.GenEmptyObj(out ho_ImageResult2);
            HOperatorSet.GenEmptyObj(out ho_ImageResult3);
            HOperatorSet.GenEmptyObj(out ho_ClassRegionsNotRejected);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening2);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_RegionTrans);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_RegionClosing);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);

            try
            {
                //HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, 100000);
                ho_Image.Dispose();
                //HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);

                HOperatorSet.ReadImage(out ho_Image, @"C:\Code\Halcon\检测有无\图片1\13.bmp");
                ho_image_Copy = ho_Image.SelectObj(1);
                HOperatorSet.GetImageSize(ho_Image, out HTuple width, out HTuple height);
                HOperatorSet.SetPart(WindowHandle, 0, 0, height, width);



                HOperatorSet.SetTposition(WindowHandle, 10, 10);
                set_display_font(WindowHandle, (int)(ParaSetting.FontSize), "mono", "true", "false");

                ho_Image1.Dispose();
                ho_Image2.Dispose();
                ho_Image3.Dispose();
                HOperatorSet.Decompose3(ho_Image, out ho_Image1, out ho_Image2, out ho_Image3
                                        );
                ho_ImageResult1.Dispose();
                ho_ImageResult2.Dispose();
                ho_ImageResult3.Dispose();
                HOperatorSet.TransFromRgb(ho_Image1, ho_Image2, ho_Image3, out ho_ImageResult1,
                                          out ho_ImageResult2, out ho_ImageResult3, "hsv");

                //HOperatorSet.DispObj(ho_Image3, WindowHandle);


                //HOperatorSet.SetColored(WindowHandle, 12);


                ho_ClassRegionsNotRejected.Dispose();
                HOperatorSet.ClassifyImageClassMlp(ho_Image, out ho_ClassRegionsNotRejected,
                                                   hv_MLPHandle, 0.5);

                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected, 1);
                ho_RegionOpening2.Dispose();
                HOperatorSet.OpeningCircle(ho_ObjectSelected, out ho_RegionOpening2, 5);


                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_RegionOpening2, out ho_ConnectedRegions);

                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", 6000.2, 259205);
                ho_RegionUnion.Dispose();
                HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);

                ho_RegionOpening.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionUnion, out ho_RegionOpening, 3.5);

                ho_RegionTrans.Dispose();
                HOperatorSet.ShapeTrans(ho_RegionOpening, out ho_RegionTrans, "circle");
                HOperatorSet.AreaCenter(ho_RegionTrans, out HTuple CircleArea, out HTuple CircleRow, out HTuple CircleCol);
                //HOperatorSet.SetDraw(WindowHandle, "margin");
                //HOperatorSet.ClearWindow(WindowHandle);
                //HOperatorSet.DispObj(ho_Image, WindowHandle);

                //HOperatorSet.DispObj(ho_RegionTrans, WindowHandle);
                //HOperatorSet.SetDraw(WindowHandle, "fill");
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(ho_Image, ho_RegionTrans, out ho_ImageReduced);
                ho_ClassRegionsNotRejected.Dispose();
                HOperatorSet.ClassifyImageClassMlp(ho_ImageReduced, out ho_ClassRegionsNotRejected,
                                                   hv_MLPHandle1, 0.5);



                ho_ObjectSelected1.Dispose();
                HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected1,
                                       4);

                ho_RegionOpening1.Dispose();
                HOperatorSet.OpeningCircle(ho_ObjectSelected1, out ho_RegionOpening1, 3.5);

                //将中间的膨胀
                HOperatorSet.Connection(ho_RegionOpening1, out HObject ConnectedRegProcess);
                HOperatorSet.CountObj(ConnectedRegProcess, out HTuple number);
                int R = 210;
                HOperatorSet.GenEmptyObj(out HObject EmptObjProcess);
                for (int i = 1; i < number; i++)
                {
                    HOperatorSet.SelectObj(ConnectedRegProcess, out HObject ObjSelectProcess, i);
                    HOperatorSet.AreaCenter(ObjSelectProcess, out HTuple areaSelect, out HTuple rowSelect, out HTuple colSelect);
                    if (rowSelect > CircleRow - R && rowSelect < CircleRow + R && colSelect > CircleCol - R && colSelect < CircleCol + R)
                    {
                        HOperatorSet.DilationCircle(ObjSelectProcess, out HObject regionDilationProcess, 10);
                        HOperatorSet.ConcatObj(EmptObjProcess, regionDilationProcess, out EmptObjProcess);
                        regionDilationProcess.Dispose();
                    }
                    ObjSelectProcess.Dispose();
                }
                HOperatorSet.Union1(EmptObjProcess, out HObject regUnionProcess);

                //

                ho_ConnectedRegions1.Dispose();
                HOperatorSet.Connection(regUnionProcess, out ho_ConnectedRegions1);

                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShapeStd(ho_ConnectedRegions1, out ho_SelectedRegions1,
                                            "max_area", 70);


                HOperatorSet.SmallestRectangle2(ho_SelectedRegions1, out hv_Row1, out hv_Column1,
                                                out hv_Phi, out hv_Length1, out hv_Length2);
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row1, hv_Column1, hv_Phi, hv_Length1,
                                           hv_Length2);

                //HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area, out hv_Row, out hv_Column);
                HOperatorSet.SetDraw(WindowHandle, "margin");
                HOperatorSet.ClearWindow(WindowHandle);
                HOperatorSet.DispObj(ho_Image, WindowHandle);

                if (hv_Length1 > ParaSetting.MinL1 && hv_Length1 < ParaSetting.MaxL1 && hv_Length2 > ParaSetting.MinL2 && hv_Length2 < ParaSetting.MaxL2)
                {
                    HOperatorSet.SetColor(WindowHandle, "green");
                    HOperatorSet.DispObj(ho_Rectangle, WindowHandle);
                    HOperatorSet.WriteString(WindowHandle, "OK");
                    if (ParaSetting.UseOutput == EnumUseOutput.Use)
                    {
                        HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "UserOutputValue", ParaSetting.OutputLogicNG == EnumOutputLogic.False ? 1 : 0);
                    }
                }
                else
                {
                    HOperatorSet.SetColor(WindowHandle, "red");
                    HOperatorSet.WriteString(WindowHandle, "NG");
                    if (ParaSetting.UseOutput == EnumUseOutput.Use)
                    {
                        HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "UserOutputValue", ParaSetting.OutputLogicNG == EnumOutputLogic.False ? 0 : 1);
                    }
                }

                HOperatorSet.SetTposition(WindowHandle, 160, 10);
                HOperatorSet.SetColor(WindowHandle, "green");
                set_display_font(WindowHandle, (int)(ParaSetting.FontSize), "mono", "true", "false");
                HOperatorSet.WriteString(WindowHandle, $"L1={hv_Length1.I}, L2={hv_Length2.I}");
            }
            catch (HalconException HDevExpDefaultException)
            {
                HOperatorSet.SetTposition(WindowHandle, 10, 10);
                set_display_font(WindowHandle, (int)(ParaSetting.FontSize), "mono", "true", "false");
                HOperatorSet.SetColor(WindowHandle, "red");
                HOperatorSet.WriteString(WindowHandle, "NG");
                if (ParaSetting.UseOutput == EnumUseOutput.Use)
                {
                    HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "UserOutputValue", ParaSetting.OutputLogicNG == EnumOutputLogic.False ? 0 : 1);
                }

                ho_Image1.Dispose();
                ho_Image2.Dispose();
                ho_Image3.Dispose();
                ho_ImageResult1.Dispose();
                ho_ImageResult2.Dispose();
                ho_ImageResult3.Dispose();
                ho_ClassRegionsNotRejected.Dispose();
                ho_ObjectSelected.Dispose();
                ho_RegionOpening2.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_RegionUnion.Dispose();
                ho_RegionOpening.Dispose();
                ho_RegionTrans.Dispose();
                ho_ImageReduced.Dispose();
                ho_ObjectSelected1.Dispose();
                ho_RegionOpening1.Dispose();
                ho_RegionFillUp.Dispose();
                ho_RegionClosing.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_Rectangle.Dispose();
                throw HDevExpDefaultException;
            }

            ho_Image1.Dispose();
            ho_Image2.Dispose();
            ho_Image3.Dispose();
            ho_ImageResult1.Dispose();
            ho_ImageResult2.Dispose();
            ho_ImageResult3.Dispose();
            ho_ClassRegionsNotRejected.Dispose();
            ho_ObjectSelected.Dispose();
            ho_RegionOpening2.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionOpening.Dispose();
            ho_RegionTrans.Dispose();
            ho_ImageReduced.Dispose();
            ho_ObjectSelected1.Dispose();
            ho_RegionOpening1.Dispose();
            ho_RegionFillUp.Dispose();
            ho_RegionClosing.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_Rectangle.Dispose();
            var TimeElipps = TimeSpan.FromTicks(DateTime.Now.Ticks - StartTime).TotalMilliseconds;

            Console.WriteLine(TimeElipps);
            return(true);
        }
示例#3
0
        public void Action(HWindow hv_ExpDefaultWinHandle)
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];
            long      SP_O  = 0;

            // Local iconic variables

            HObject ho_Image, ho_Image1, ho_Image2, ho_Image3;
            HObject ho_ImageResult1, ho_ImageResult2, ho_ImageResult3;
            HObject ho_ClassRegionsNotRejected, ho_ObjectSelected, ho_RegionOpening2;
            HObject ho_ConnectedRegions, ho_SelectedRegions, ho_RegionUnion;
            HObject ho_RegionOpening, ho_RegionTrans, ho_ImageReduced;
            HObject ho_ObjectSelected1, ho_RegionOpening1, ho_RegionFillUp;
            HObject ho_ConnectedRegions1, ho_EmptyObject, ho_ObjectSelected2 = null;
            HObject ho_RegionDilation = null, ho_RegionUnion1, ho_ConnectedRegions2;
            HObject ho_SelectedRegions1, ho_Rectangle;


            // Local control variables

            HTuple hv_WindowHandle = new HTuple();
            HTuple hv_Area2, hv_CircleRow, hv_CircleCol;
            HTuple hv_Number, hv_R, hv_Index1, hv_Area3 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple(), hv_Row1;
            HTuple hv_Column1, hv_Phi, hv_Length1, hv_Length2, hv_Area;
            HTuple hv_Row, hv_Column;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Image);
            HOperatorSet.GenEmptyObj(out ho_Image1);
            HOperatorSet.GenEmptyObj(out ho_Image2);
            HOperatorSet.GenEmptyObj(out ho_Image3);
            HOperatorSet.GenEmptyObj(out ho_ImageResult1);
            HOperatorSet.GenEmptyObj(out ho_ImageResult2);
            HOperatorSet.GenEmptyObj(out ho_ImageResult3);
            HOperatorSet.GenEmptyObj(out ho_ClassRegionsNotRejected);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening2);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_RegionTrans);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_EmptyObject);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected2);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation);
            HOperatorSet.GenEmptyObj(out ho_RegionUnion1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);

            try
            {
                ho_Image.Dispose();
                //HOperatorSet.ReadImage(out ho_Image, new HTuple(new HTuple("C:/Code/Halcon/检测有无/图片1/") + 13) + ".bmp");
                HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);
                //HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);

                ho_image_Copy = ho_Image.SelectObj(1);
                HOperatorSet.GetImageSize(ho_Image, out HTuple width, out HTuple height);


                //HOperatorSet.ReadClassMlp("mlp_1.gmc", out hv_MLPHandle);
                //HOperatorSet.ReadClassMlp("mlp_3.gmc", out hv_MLPHandle1);



                HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 10, 10);
                set_display_font(hv_ExpDefaultWinHandle, (int)ParaSetting.FontSize, "mono", "true", "false");

                ho_Image1.Dispose();
                ho_Image2.Dispose();
                ho_Image3.Dispose();
                HOperatorSet.Decompose3(ho_Image, out ho_Image1, out ho_Image2, out ho_Image3
                                        );
                ho_ImageResult1.Dispose();
                ho_ImageResult2.Dispose();
                ho_ImageResult3.Dispose();
                HOperatorSet.TransFromRgb(ho_Image1, ho_Image2, ho_Image3, out ho_ImageResult1,
                                          out ho_ImageResult2, out ho_ImageResult3, "hsv");
                //HOperatorSet.DispObj(ho_Image3, hv_ExpDefaultWinHandle);
                //HOperatorSet.SetColored(hv_ExpDefaultWinHandle, 12);

                ho_ClassRegionsNotRejected.Dispose();
                HOperatorSet.ClassifyImageClassMlp(ho_Image, out ho_ClassRegionsNotRejected,
                                                   hv_MLPHandle, 0.3);

                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected, 1);
                ho_RegionOpening2.Dispose();
                HOperatorSet.OpeningCircle(ho_ObjectSelected, out ho_RegionOpening2, 5);


                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_RegionOpening2, out ho_ConnectedRegions);
                //area_center (ConnectedRegions, Area1, Row3, Column3)

                ho_SelectedRegions.Dispose();
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                         "and", 6000.2, 309205);
                ho_RegionUnion.Dispose();
                HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);

                ho_RegionOpening.Dispose();
                HOperatorSet.OpeningCircle(ho_RegionUnion, out ho_RegionOpening, 3.5);

                ho_RegionTrans.Dispose();
                HOperatorSet.ShapeTrans(ho_RegionOpening, out ho_RegionTrans, "circle");
                //HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill");
                //HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
                //HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);

                //HOperatorSet.DispObj(ho_RegionTrans, hv_ExpDefaultWinHandle);

                //HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill");
                ho_ImageReduced.Dispose();
                HOperatorSet.ReduceDomain(ho_Image, ho_RegionTrans, out ho_ImageReduced);
                HOperatorSet.AreaCenter(ho_RegionTrans, out hv_Area2, out hv_CircleRow, out hv_CircleCol);

                ho_ClassRegionsNotRejected.Dispose();
                HOperatorSet.ClassifyImageClassMlp(ho_ImageReduced, out ho_ClassRegionsNotRejected,
                                                   hv_MLPHandle1, 0.3);
                //HOperatorSet.SetColored(hv_ExpDefaultWinHandle, 12);
                //HOperatorSet.DispObj(ho_ClassRegionsNotRejected, hv_ExpDefaultWinHandle);
                ho_ObjectSelected1.Dispose();
                HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected1,
                                       4);

                ho_RegionOpening1.Dispose();
                HOperatorSet.OpeningCircle(ho_ObjectSelected1, out ho_RegionOpening1, 3.5);

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

                //closing_circle (RegionFillUp, RegionClosing, 10)

                ho_ConnectedRegions1.Dispose();
                HOperatorSet.Connection(ho_RegionFillUp, out ho_ConnectedRegions1);
                HOperatorSet.CountObj(ho_ConnectedRegions1, out hv_Number);

                //找除靠近中心的圆
                ho_EmptyObject.Dispose();
                HOperatorSet.GenEmptyObj(out ho_EmptyObject);

                hv_R = 200;
                for (hv_Index1 = 1; hv_Index1.Continue(hv_Number, 1); hv_Index1 = hv_Index1.TupleAdd(1))
                {
                    ho_ObjectSelected2.Dispose();
                    HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected2, hv_Index1);
                    HOperatorSet.AreaCenter(ho_ObjectSelected2, out hv_Area3, out hv_Row2, out hv_Column2);

                    if ((int)((new HTuple((new HTuple((new HTuple(hv_Row2.TupleGreater(hv_CircleRow - hv_R))).TupleAnd(
                                                          new HTuple(hv_Row2.TupleLess(hv_CircleRow + hv_R))))).TupleAnd(new HTuple(hv_Column2.TupleGreater(
                                                                                                                                        hv_CircleCol - hv_R))))).TupleAnd(new HTuple(hv_Column2.TupleLess(hv_CircleCol + hv_R)))) != 0)
                    {
                        ho_RegionDilation.Dispose();
                        HOperatorSet.DilationCircle(ho_ObjectSelected2, out ho_RegionDilation,
                                                    10);
                        OTemp[SP_O] = ho_EmptyObject.CopyObj(1, -1);
                        SP_O++;
                        ho_EmptyObject.Dispose();
                        HOperatorSet.ConcatObj(ho_RegionDilation, OTemp[SP_O - 1], out ho_EmptyObject
                                               );
                        OTemp[SP_O - 1].Dispose();
                        SP_O = 0;
                    }
                }

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

                ho_ConnectedRegions2.Dispose();
                HOperatorSet.Connection(ho_RegionUnion1, out ho_ConnectedRegions2);

                ho_SelectedRegions1.Dispose();
                HOperatorSet.SelectShapeStd(ho_ConnectedRegions2, out ho_SelectedRegions1,
                                            "max_area", 70);

                HOperatorSet.SmallestRectangle2(ho_SelectedRegions1, out hv_Row1, out hv_Column1,
                                                out hv_Phi, out hv_Length1, out hv_Length2);
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row1, hv_Column1, hv_Phi, hv_Length1,
                                           hv_Length2);


                HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area, out hv_Row, out hv_Column);
                HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin");
                HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);


                lock (SyncData.VisionLock)
                {
                    if (SyncData.IsNewSizing == false)
                    {
                        if (SyncData.IsNewSizing != SyncData.IsOldSizing)
                        {
                            Thread.Sleep(300);
                            SyncData.IsOldSizing = SyncData.IsNewSizing;
                            Console.WriteLine("Trig");
                        }
                        HOperatorSet.SetPart(hv_ExpDefaultWinHandle, 0, 0, height, width);
                        HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);

                        if (hv_Length1 > ParaSetting.MinL1 && hv_Length1 < ParaSetting.MaxL1 && hv_Length2 > ParaSetting.MinL2 && hv_Length2 < ParaSetting.MaxL2)
                        {
                            HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green");
                            HOperatorSet.DispObj(ho_Rectangle, hv_ExpDefaultWinHandle);
                            HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "OK");
                            if (ParaSetting.UseOutput == EnumUseOutput.Use)
                            {
                                HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "UserOutputValue", ParaSetting.OutputLogicNG == EnumOutputLogic.False ? 1 : 0);
                            }
                        }
                        else
                        {
                            HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red");
                            HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "NG");
                            if (ParaSetting.UseOutput == EnumUseOutput.Use)
                            {
                                HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "UserOutputValue", ParaSetting.OutputLogicNG == EnumOutputLogic.False ? 0 : 1);
                            }
                        }

                        HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 160, 10);
                        HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green");
                        set_display_font(hv_ExpDefaultWinHandle, (int)(ParaSetting.FontSize), "mono", "true", "false");
                        HOperatorSet.WriteString(hv_ExpDefaultWinHandle, $"L1={hv_Length1}, L2={hv_Length2}");
                    }
                }
            }
            catch (HalconException HDevExpDefaultException)
            {
                lock (SyncData.VisionLock)
                {
                    if (SyncData.IsNewSizing == false)
                    {
                        if (SyncData.IsNewSizing != SyncData.IsOldSizing)
                        {
                            Thread.Sleep(300);
                            SyncData.IsOldSizing = SyncData.IsNewSizing;
                            Console.WriteLine("Trig");
                        }
                        HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 10, 10);
                        set_display_font(hv_ExpDefaultWinHandle, (int)(ParaSetting.FontSize), "mono", "true", "false");
                        HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red");
                        HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "NG");
                    }
                }
                if (ParaSetting.UseOutput == EnumUseOutput.Use)
                {
                    HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "UserOutputValue", ParaSetting.OutputLogicNG == EnumOutputLogic.False ? 0 : 1);
                }

                ho_Image.Dispose();
                ho_Image1.Dispose();
                ho_Image2.Dispose();
                ho_Image3.Dispose();
                ho_ImageResult1.Dispose();
                ho_ImageResult2.Dispose();
                ho_ImageResult3.Dispose();
                ho_ClassRegionsNotRejected.Dispose();
                ho_ObjectSelected.Dispose();
                ho_RegionOpening2.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_RegionUnion.Dispose();
                ho_RegionOpening.Dispose();
                ho_RegionTrans.Dispose();
                ho_ImageReduced.Dispose();
                ho_ObjectSelected1.Dispose();
                ho_RegionOpening1.Dispose();
                ho_RegionFillUp.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_EmptyObject.Dispose();
                ho_ObjectSelected2.Dispose();
                ho_RegionDilation.Dispose();
                ho_RegionUnion1.Dispose();
                ho_ConnectedRegions2.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_Rectangle.Dispose();

                throw HDevExpDefaultException;
            }
            ho_Image.Dispose();
            ho_Image1.Dispose();
            ho_Image2.Dispose();
            ho_Image3.Dispose();
            ho_ImageResult1.Dispose();
            ho_ImageResult2.Dispose();
            ho_ImageResult3.Dispose();
            ho_ClassRegionsNotRejected.Dispose();
            ho_ObjectSelected.Dispose();
            ho_RegionOpening2.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionOpening.Dispose();
            ho_RegionTrans.Dispose();
            ho_ImageReduced.Dispose();
            ho_ObjectSelected1.Dispose();
            ho_RegionOpening1.Dispose();
            ho_RegionFillUp.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_EmptyObject.Dispose();
            ho_ObjectSelected2.Dispose();
            ho_RegionDilation.Dispose();
            ho_RegionUnion1.Dispose();
            ho_ConnectedRegions2.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_Rectangle.Dispose();
        }
示例#4
0
    // Main procedure
    private void action()
    {
        // Stack for temporary objects
        HObject[] OTemp = new HObject[20];
        long      SP_O  = 0;

        // Local iconic variables

        HObject ho_Image, ho_Image1, ho_Image2, ho_Image3;
        HObject ho_ImageResult1, ho_ImageResult2, ho_ImageResult3;
        HObject ho_ClassRegionsNotRejected, ho_ObjectSelected, ho_RegionOpening2;
        HObject ho_ConnectedRegions, ho_SelectedRegions, ho_RegionUnion;
        HObject ho_RegionOpening, ho_RegionTrans, ho_ImageReduced;
        HObject ho_ObjectSelected1, ho_RegionOpening1, ho_RegionFillUp;
        HObject ho_ConnectedRegions1, ho_EmptyObject, ho_ObjectSelected2 = null;
        HObject ho_RegionDilation = null, ho_RegionUnion1, ho_ConnectedRegions2;
        HObject ho_SelectedRegions1, ho_Rectangle;


        // Local control variables

        HTuple hv_WindowHandle = new HTuple(), hv_MLPHandle;
        HTuple hv_MLPHandle1, hv_Area2, hv_CircleRow, hv_CircleCol;
        HTuple hv_Number, hv_R, hv_Index1, hv_Area3 = new HTuple();
        HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple(), hv_Row1;
        HTuple hv_Column1, hv_Phi, hv_Length1, hv_Length2, hv_Area;
        HTuple hv_Row, hv_Column;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_Image1);
        HOperatorSet.GenEmptyObj(out ho_Image2);
        HOperatorSet.GenEmptyObj(out ho_Image3);
        HOperatorSet.GenEmptyObj(out ho_ImageResult1);
        HOperatorSet.GenEmptyObj(out ho_ImageResult2);
        HOperatorSet.GenEmptyObj(out ho_ImageResult3);
        HOperatorSet.GenEmptyObj(out ho_ClassRegionsNotRejected);
        HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
        HOperatorSet.GenEmptyObj(out ho_RegionOpening2);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_RegionUnion);
        HOperatorSet.GenEmptyObj(out ho_RegionOpening);
        HOperatorSet.GenEmptyObj(out ho_RegionTrans);
        HOperatorSet.GenEmptyObj(out ho_ImageReduced);
        HOperatorSet.GenEmptyObj(out ho_ObjectSelected1);
        HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
        HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
        HOperatorSet.GenEmptyObj(out ho_EmptyObject);
        HOperatorSet.GenEmptyObj(out ho_ObjectSelected2);
        HOperatorSet.GenEmptyObj(out ho_RegionDilation);
        HOperatorSet.GenEmptyObj(out ho_RegionUnion1);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
        HOperatorSet.GenEmptyObj(out ho_Rectangle);

        try
        {
            ho_Image.Dispose();
            HOperatorSet.ReadImage(out ho_Image, new HTuple(new HTuple("C:/Code/Halcon/¼ì²âÓÐÎÞ/ͼƬ1/") + 13) + ".bmp");
            //dev_close_window(...);
            dev_open_window_fit_image(ho_Image, 0, 0, -1, -1, out hv_WindowHandle);

            HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);


            HOperatorSet.ReadClassMlp("mlp_1.gmc", out hv_MLPHandle);
            HOperatorSet.ReadClassMlp("mlp_3.gmc", out hv_MLPHandle1);



            HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, 10, 10);
            set_display_font(hv_ExpDefaultWinHandle, 50, "mono", "true", "false");

            ho_Image1.Dispose();
            ho_Image2.Dispose();
            ho_Image3.Dispose();
            HOperatorSet.Decompose3(ho_Image, out ho_Image1, out ho_Image2, out ho_Image3
                                    );
            ho_ImageResult1.Dispose();
            ho_ImageResult2.Dispose();
            ho_ImageResult3.Dispose();
            HOperatorSet.TransFromRgb(ho_Image1, ho_Image2, ho_Image3, out ho_ImageResult1,
                                      out ho_ImageResult2, out ho_ImageResult3, "hsv");
            HOperatorSet.DispObj(ho_Image3, hv_ExpDefaultWinHandle);
            HOperatorSet.SetColored(hv_ExpDefaultWinHandle, 12);

            ho_ClassRegionsNotRejected.Dispose();
            HOperatorSet.ClassifyImageClassMlp(ho_Image, out ho_ClassRegionsNotRejected,
                                               hv_MLPHandle, 0.3);

            ho_ObjectSelected.Dispose();
            HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected, 1);
            ho_RegionOpening2.Dispose();
            HOperatorSet.OpeningCircle(ho_ObjectSelected, out ho_RegionOpening2, 5);


            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_RegionOpening2, out ho_ConnectedRegions);
            //area_center (ConnectedRegions, Area1, Row3, Column3)

            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                     "and", 6000.2, 309205);
            ho_RegionUnion.Dispose();
            HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion);

            ho_RegionOpening.Dispose();
            HOperatorSet.OpeningCircle(ho_RegionUnion, out ho_RegionOpening, 3.5);

            ho_RegionTrans.Dispose();
            HOperatorSet.ShapeTrans(ho_RegionOpening, out ho_RegionTrans, "circle");
            HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill");
            HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);
            HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);

            HOperatorSet.DispObj(ho_RegionTrans, hv_ExpDefaultWinHandle);

            HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill");
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_RegionTrans, out ho_ImageReduced);
            HOperatorSet.AreaCenter(ho_RegionTrans, out hv_Area2, out hv_CircleRow, out hv_CircleCol);

            ho_ClassRegionsNotRejected.Dispose();
            HOperatorSet.ClassifyImageClassMlp(ho_ImageReduced, out ho_ClassRegionsNotRejected,
                                               hv_MLPHandle1, 0.3);
            HOperatorSet.SetColored(hv_ExpDefaultWinHandle, 12);
            HOperatorSet.DispObj(ho_ClassRegionsNotRejected, hv_ExpDefaultWinHandle);
            ho_ObjectSelected1.Dispose();
            HOperatorSet.SelectObj(ho_ClassRegionsNotRejected, out ho_ObjectSelected1,
                                   4);

            ho_RegionOpening1.Dispose();
            HOperatorSet.OpeningCircle(ho_ObjectSelected1, out ho_RegionOpening1, 3.5);

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

            //closing_circle (RegionFillUp, RegionClosing, 10)

            ho_ConnectedRegions1.Dispose();
            HOperatorSet.Connection(ho_RegionFillUp, out ho_ConnectedRegions1);
            HOperatorSet.CountObj(ho_ConnectedRegions1, out hv_Number);

            //ÕÒ³ý¿¿½üÖÐÐĵÄÔ²
            ho_EmptyObject.Dispose();
            HOperatorSet.GenEmptyObj(out ho_EmptyObject);

            hv_R = 200;
            for (hv_Index1 = 1; hv_Index1.Continue(hv_Number, 1); hv_Index1 = hv_Index1.TupleAdd(1))
            {
                ho_ObjectSelected2.Dispose();
                HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected2, hv_Index1);
                HOperatorSet.AreaCenter(ho_ObjectSelected2, out hv_Area3, out hv_Row2, out hv_Column2);

                if ((int)((new HTuple((new HTuple((new HTuple(hv_Row2.TupleGreater(hv_CircleRow - hv_R))).TupleAnd(
                                                      new HTuple(hv_Row2.TupleLess(hv_CircleRow + hv_R))))).TupleAnd(new HTuple(hv_Column2.TupleGreater(
                                                                                                                                    hv_CircleCol - hv_R))))).TupleAnd(new HTuple(hv_Column2.TupleLess(hv_CircleCol + hv_R)))) != 0)
                {
                    ho_RegionDilation.Dispose();
                    HOperatorSet.DilationCircle(ho_ObjectSelected2, out ho_RegionDilation,
                                                10);
                    OTemp[SP_O] = ho_EmptyObject.CopyObj(1, -1);
                    SP_O++;
                    ho_EmptyObject.Dispose();
                    HOperatorSet.ConcatObj(ho_RegionDilation, OTemp[SP_O - 1], out ho_EmptyObject
                                           );
                    OTemp[SP_O - 1].Dispose();
                    SP_O = 0;
                }
            }

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

            ho_ConnectedRegions2.Dispose();
            HOperatorSet.Connection(ho_RegionUnion1, out ho_ConnectedRegions2);

            ho_SelectedRegions1.Dispose();
            HOperatorSet.SelectShapeStd(ho_ConnectedRegions2, out ho_SelectedRegions1,
                                        "max_area", 70);

            HOperatorSet.SmallestRectangle2(ho_SelectedRegions1, out hv_Row1, out hv_Column1,
                                            out hv_Phi, out hv_Length1, out hv_Length2);
            ho_Rectangle.Dispose();
            HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row1, hv_Column1, hv_Phi, hv_Length1,
                                       hv_Length2);


            HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area, out hv_Row, out hv_Column);
            HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin");
            HOperatorSet.ClearWindow(hv_ExpDefaultWinHandle);

            HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);


            if ((int)((new HTuple((new HTuple((new HTuple(hv_Length1.TupleLess(200))).TupleAnd(
                                                  new HTuple(hv_Length2.TupleLess(200))))).TupleAnd(new HTuple(hv_Length1.TupleGreater(
                                                                                                                   50))))).TupleAnd(new HTuple(hv_Length2.TupleGreater(50)))) != 0)
            {
                HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green");
                HOperatorSet.DispObj(ho_Rectangle, hv_ExpDefaultWinHandle);
                HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "OK");
                //set_framegrabber_param (AcqHandle, 'UserOutputValue', 0)
            }
            else
            {
                HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red");
                HOperatorSet.WriteString(hv_ExpDefaultWinHandle, "NG");
                //set_framegrabber_param (AcqHandle, 'UserOutputValue', 1)
            }
        }
        catch (HalconException HDevExpDefaultException)
        {
            ho_Image.Dispose();
            ho_Image1.Dispose();
            ho_Image2.Dispose();
            ho_Image3.Dispose();
            ho_ImageResult1.Dispose();
            ho_ImageResult2.Dispose();
            ho_ImageResult3.Dispose();
            ho_ClassRegionsNotRejected.Dispose();
            ho_ObjectSelected.Dispose();
            ho_RegionOpening2.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionUnion.Dispose();
            ho_RegionOpening.Dispose();
            ho_RegionTrans.Dispose();
            ho_ImageReduced.Dispose();
            ho_ObjectSelected1.Dispose();
            ho_RegionOpening1.Dispose();
            ho_RegionFillUp.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_EmptyObject.Dispose();
            ho_ObjectSelected2.Dispose();
            ho_RegionDilation.Dispose();
            ho_RegionUnion1.Dispose();
            ho_ConnectedRegions2.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_Rectangle.Dispose();

            throw HDevExpDefaultException;
        }
        ho_Image.Dispose();
        ho_Image1.Dispose();
        ho_Image2.Dispose();
        ho_Image3.Dispose();
        ho_ImageResult1.Dispose();
        ho_ImageResult2.Dispose();
        ho_ImageResult3.Dispose();
        ho_ClassRegionsNotRejected.Dispose();
        ho_ObjectSelected.Dispose();
        ho_RegionOpening2.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_RegionUnion.Dispose();
        ho_RegionOpening.Dispose();
        ho_RegionTrans.Dispose();
        ho_ImageReduced.Dispose();
        ho_ObjectSelected1.Dispose();
        ho_RegionOpening1.Dispose();
        ho_RegionFillUp.Dispose();
        ho_ConnectedRegions1.Dispose();
        ho_EmptyObject.Dispose();
        ho_ObjectSelected2.Dispose();
        ho_RegionDilation.Dispose();
        ho_RegionUnion1.Dispose();
        ho_ConnectedRegions2.Dispose();
        ho_SelectedRegions1.Dispose();
        ho_Rectangle.Dispose();
    }