// Main procedure

    #region 循环执行
    private void actionMiaUsed()
    {
        // Stack for temporary objects 临时对象堆栈
        HObject[] OTemp = new HObject[20];

        // Local variables 变量
        HObject ho_InfoModelContours, ho_SignModelContours;
        HObject ho_Image = null, ho_SymbolRegions = null, ho_ROI_OCR_01_0 = null;
        HObject ho_EDGE = null, ho_ObjectSelected = null, ho_InfoTransContours = null;
        HObject ho_SignTransContours = null;

        // Local control variables 全局变量

        HTuple hv_BarWidth = new HTuple(), hv_BarHeight = new HTuple();
        HTuple hv_BarCodeHandle = new HTuple(), hv_InfoModel = new HTuple();
        HTuple hv_SignModel = new HTuple(), hv_WindowHandle = new HTuple();
        HTuple hv_AcqHandle = new HTuple(), hv_InfoRow = new HTuple();
        HTuple hv_InfoColumn = new HTuple(), hv_InfoAngle = new HTuple();
        HTuple hv_InfoScore = new HTuple(), hv_DecodedDataStrings = new HTuple();
        HTuple hv_someitem = new HTuple(), hv_SignRow = new HTuple();
        HTuple hv_SignColumn = new HTuple(), hv_SignAngle = new HTuple();
        HTuple hv_SignScore = new HTuple(), hv_SymbolNames_OCR_01_0 = new HTuple();
        HTuple hv_Ocr_Split = new HTuple(), hv_Area = new HTuple();
        HTuple hv_IDRow = new HTuple(), hv_IDColumn = new HTuple();
        HTuple hv_IDRow1 = new HTuple(), hv_IDColumn1 = new HTuple();
        HTuple hv_IDRow2 = new HTuple(), hv_IDColumn2 = new HTuple();
        HTuple hv_IDHeight = new HTuple(), hv_IDWidth = new HTuple();
        HTuple hv_IDRatio = new HTuple(), hv_HeadSignScale = new HTuple();
        HTuple hv_HeadSignRow = new HTuple(), hv_HeadSignCol = new HTuple();
        HTuple hv_HeadPhi = new HTuple(), hv_sign = new HTuple();
        HTuple hv_BarIndex = new HTuple(), hv_Row = new HTuple();
        HTuple hv_Column = new HTuple(), hv_InfoHomMat2D = new HTuple();
        HTuple hv_SignHomMat2D = new HTuple(), hv_Exception = new HTuple();

        // Initialize local and output iconic variables 初始化本地和输出图标变量
        HOperatorSet.GenEmptyObj(out ho_InfoModelContours);
        HOperatorSet.GenEmptyObj(out ho_SignModelContours);
        HOperatorSet.GenEmptyObj(out ho_Image);
        HOperatorSet.GenEmptyObj(out ho_SymbolRegions);
        HOperatorSet.GenEmptyObj(out ho_ROI_OCR_01_0);
        HOperatorSet.GenEmptyObj(out ho_EDGE);
        HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
        HOperatorSet.GenEmptyObj(out ho_InfoTransContours);
        HOperatorSet.GenEmptyObj(out ho_SignTransContours);
        try
        {
            //***
            //** INIT
            //* INIT CONST 常量
            hv_BarWidth.Dispose();
            hv_BarWidth = 800;
            hv_BarHeight.Dispose();
            hv_BarHeight = 100;
            //* INIT IMAGE 图像

            //* INIT BARCODE 条形码
            hv_BarCodeHandle.Dispose();
            HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out hv_BarCodeHandle);
            HOperatorSet.SetBarCodeParam(hv_BarCodeHandle, "quiet_zone", "true");
            //* INIT LOC 位置
            //* Info:
            hv_InfoModel.Dispose();
            HOperatorSet.ReadShapeModel("C:/Users/zhang-sh/source/repos/repo/Model/file/InvV1CaliSign.shm",
                                        out hv_InfoModel);
            ho_InfoModelContours.Dispose();
            HOperatorSet.GetShapeModelContours(out ho_InfoModelContours, hv_InfoModel,
                                               1);
            //* Sign 标志
            hv_SignModel.Dispose();
            HOperatorSet.ReadShapeModel("C:/Users/zhang-sh/source/repos/repo/Model/file/InvV1CaliSign.shm",
                                        out hv_SignModel);
            ho_SignModelContours.Dispose();
            HOperatorSet.GetShapeModelContours(out ho_SignModelContours, hv_SignModel,
                                               1);

            //***
            //** DISPLAY
            //* DISPLAY INIT
            hDevelo.dev_update_off();
            //dev_close_window(...);
            //dev_open_window(...);

            //***
            //** LOOP
            //Image Acquisition 01: Code generated by Image Acquisition 01  图像采集01:图像采集01生成的代码
            hv_AcqHandle.Dispose();
            hv_AcqHandle = acqHandle;
            while ((int)(1) != 0)
            {
                ho_Image.Dispose();

                HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);
                if (ho_Image != null)
                {
                    HOperatorSet.Intensity(ho_Image, ho_Image, out hv_Mean, out hv_Deviation); // 求图片平均值和方差
                }
                {
                    HObject ExpTmpOutVar_0;
                    hDevelo.image_cali_map(ho_Image, out ExpTmpOutVar_0, new HTuple(), new HTuple());
                    ho_Image.Dispose();
                    ho_Image = ExpTmpOutVar_0;
                    HOperatorSet.DispObj(ho_Image, hv_ExpImageRawWinHandle);
                }
                try
                {
                    //** PRE
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose();
                        HOperatorSet.FindShapeModel(ho_Image, hv_InfoModel, (new HTuple(0)).TupleRad()
                                                    , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat(
                                                        1), 0.6, out hv_InfoRow, out hv_InfoColumn, out hv_InfoAngle, out hv_InfoScore);
                    }
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.RotateImage(ho_Image, out ExpTmpOutVar_0, ((-hv_InfoAngle)).TupleDeg()
                                                 , "constant");
                        ho_Image.Dispose();
                        ho_Image = ExpTmpOutVar_0;
                    }
                    HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
                    //** RECOGNITION
                    //* BARCODE
                    ho_SymbolRegions.Dispose(); hv_DecodedDataStrings.Dispose(); hv_someitem.Dispose();
                    hDevelo.image_get_bar(ho_Image, out ho_SymbolRegions, hv_BarCodeHandle, out hv_DecodedDataStrings,
                                          out hv_someitem);
                    //* LOC
                    //* Info:
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_InfoRow.Dispose(); hv_InfoColumn.Dispose(); hv_InfoAngle.Dispose(); hv_InfoScore.Dispose();
                        HOperatorSet.FindShapeModel(ho_Image, hv_InfoModel, (new HTuple(0)).TupleRad()
                                                    , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat(
                                                        1), 0.7, out hv_InfoRow, out hv_InfoColumn, out hv_InfoAngle, out hv_InfoScore);
                    }
                    //* HaedSign
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_SignRow.Dispose(); hv_SignColumn.Dispose(); hv_SignAngle.Dispose(); hv_SignScore.Dispose();
                        HOperatorSet.FindShapeModel(ho_Image, hv_SignModel, (new HTuple(0)).TupleRad()
                                                    , (new HTuple(360)).TupleRad(), 0.3, 1, 0.5, "least_squares", (new HTuple(7)).TupleConcat(
                                                        1), 0.7, out hv_SignRow, out hv_SignColumn, out hv_SignAngle, out hv_SignScore);
                    }
                    //* Ocr
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ROI_OCR_01_0.Dispose();
                        HOperatorSet.GenRectangle2(out ho_ROI_OCR_01_0, hv_InfoRow + 70, hv_InfoColumn - 700,
                                                   hv_InfoAngle, 100, 30);
                    }
                    hv_SymbolNames_OCR_01_0.Dispose(); hv_Ocr_Split.Dispose();
                    hDevelo.region_ocr_num_svm(ho_Image, ho_ROI_OCR_01_0, new HTuple(), new HTuple(),
                                               out hv_SymbolNames_OCR_01_0, out hv_Ocr_Split);
                    hv_Area.Dispose(); hv_IDRow.Dispose(); hv_IDColumn.Dispose();
                    HOperatorSet.AreaCenter(ho_ROI_OCR_01_0, out hv_Area, out hv_IDRow, out hv_IDColumn);
                    hv_IDRow1.Dispose(); hv_IDColumn1.Dispose(); hv_IDRow2.Dispose(); hv_IDColumn2.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ROI_OCR_01_0, out hv_IDRow1, out hv_IDColumn1,
                                                    out hv_IDRow2, out hv_IDColumn2);
                    hv_IDHeight.Dispose(); hv_IDWidth.Dispose(); hv_IDRatio.Dispose();
                    HOperatorSet.HeightWidthRatio(ho_ROI_OCR_01_0, out hv_IDHeight, out hv_IDWidth,
                                                  out hv_IDRatio);
                    //* Sign
                    hv_HeadSignScale.Dispose();
                    hv_HeadSignScale = 1;
                    hv_HeadSignRow.Dispose();
                    hv_HeadSignRow = new HTuple(hv_SignRow);
                    hv_HeadSignCol.Dispose();
                    hv_HeadSignCol = new HTuple(hv_SignColumn);
                    hv_HeadPhi.Dispose();
                    hv_HeadPhi = new HTuple(hv_SignAngle);
                    ho_EDGE.Dispose(); hv_sign.Dispose();
                    hDevelo.region_judge_sign(ho_Image, out ho_EDGE, hv_HeadSignScale, hv_HeadSignRow,
                                              hv_HeadSignCol, hv_HeadPhi, hv_WindowHandle, out hv_sign);
                    //** DISPLAY
                    //* DISPLAY BARCODE 显示条形码
                    hDevelo.set_display_font(hv_ExpDefaultWinHandle, 14, "mono", "true", "false");
                    HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "margin");
                    HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 3);
                    HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "forest green");
                    HOperatorSet.DispObj(ho_SymbolRegions, hv_ExpDefaultWinHandle);
                    for (hv_BarIndex = 1; (int)hv_BarIndex <= (int)(new HTuple(hv_DecodedDataStrings.TupleLength()
                                                                               )); hv_BarIndex = (int)hv_BarIndex + 1)
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_SymbolRegions, out ho_ObjectSelected, hv_BarIndex);
                        hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                        HOperatorSet.AreaCenter(ho_ObjectSelected, out hv_Area, out hv_Row, out hv_Column);
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_Row - hv_BarHeight,
                                                      hv_Column - (0.25 * hv_BarWidth));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_DecodedDataStrings.TupleSelect(
                                                         hv_BarIndex - 1));
                        }
                    }
                    //* DISPLAY LOC
                    HOperatorSet.SetLineWidth(hv_ExpDefaultWinHandle, 1);
                    //* Info:
                    hv_InfoHomMat2D.Dispose();
                    HOperatorSet.HomMat2dIdentity(out hv_InfoHomMat2D);
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.HomMat2dRotate(hv_InfoHomMat2D, hv_InfoAngle, 0, 0, out ExpTmpOutVar_0);
                        hv_InfoHomMat2D.Dispose();
                        hv_InfoHomMat2D = ExpTmpOutVar_0;
                    }
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.HomMat2dTranslate(hv_InfoHomMat2D, hv_InfoRow, hv_InfoColumn,
                                                       out ExpTmpOutVar_0);
                        hv_InfoHomMat2D.Dispose();
                        hv_InfoHomMat2D = ExpTmpOutVar_0;
                    }
                    ho_InfoTransContours.Dispose();
                    HOperatorSet.AffineTransContourXld(ho_InfoModelContours, out ho_InfoTransContours,
                                                       hv_InfoHomMat2D);
                    HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green");
                    HOperatorSet.DispObj(ho_InfoTransContours, hv_ExpDefaultWinHandle);
                    //* Ocr
                    //dev_disp_text (Ocr_Split, 'image', IDRow1 + IDHeight, IDColumn1, 'blue', [], []) 开发显示文本
                    //* HeadSign
                    hv_SignHomMat2D.Dispose();
                    HOperatorSet.HomMat2dIdentity(out hv_SignHomMat2D);
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.HomMat2dRotate(hv_SignHomMat2D, hv_SignAngle, 0, 0, out ExpTmpOutVar_0);
                        hv_SignHomMat2D.Dispose();
                        hv_SignHomMat2D = ExpTmpOutVar_0;
                    }
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.HomMat2dTranslate(hv_SignHomMat2D, hv_SignRow, hv_SignColumn,
                                                       out ExpTmpOutVar_0);
                        hv_SignHomMat2D.Dispose();
                        hv_SignHomMat2D = ExpTmpOutVar_0;
                    }
                    ho_SignTransContours.Dispose();
                    HOperatorSet.AffineTransContourXld(ho_SignModelContours, out ho_SignTransContours,
                                                       hv_SignHomMat2D);
                    HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "green");
                    HOperatorSet.DispObj(ho_SignTransContours, hv_ExpDefaultWinHandle);
                    //* Sign
                    HOperatorSet.SetColored(hv_ExpDefaultWinHandle, 12);
                    HOperatorSet.DispObj(ho_EDGE, hv_ExpDefaultWinHandle);
                    //dump_window_image (ImageResult, WindowHandle) 转储窗口图像
                    // 手动保存图片和数据
                    if (ImgAuto.state == ImgAutoState.imgAutoFalse && SaveData.state == SaveDataState.saveDataTrue)
                    {
                        // 时间
                        string      ScanDate    = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        MainFormDAL mainFormDAL = new MainFormDAL();
                        ImgHelper   imgHelper   = new ImgHelper();
                        // 保存图片
                        imgHelper.SaveImg(ScanDate, ho_Image);
                        SaveData.state = SaveDataState.saveDataFalse;
                        // 保存数据
                        UsedInfo usedInfo;
                        usedInfo = mainFormDAL.ConvertStruct(hv_Ocr_Split, hv_DecodedDataStrings, hv_sign);
                        mainFormDAL.SaveTemp(usedInfo, ScanDate);
                        imgNumber         = imgNumber + 1;
                        usedInfo.ImgCount = imgNumber;
                    }
                    ;
                    // 自动保存图片和数据
                    if (ImgAuto.state == ImgAutoState.imgAutoTrue)
                    {
                        // 时间
                        string      ScanDate    = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        MainFormDAL mainFormDAL = new MainFormDAL();
                        ImgHelper   imgHelper   = new ImgHelper();
                        // 保存图片
                        imgHelper.SaveImg(ScanDate, ho_Image);
                        SaveData.state = SaveDataState.saveDataFalse;
                        // 保存数据
                        UsedInfo usedInfo;
                        usedInfo = mainFormDAL.ConvertStruct(hv_Ocr_Split, hv_DecodedDataStrings, hv_sign);
                        mainFormDAL.SaveTemp(usedInfo, ScanDate);
                        imgNumber        += imgNumber;
                        usedInfo.ImgCount = imgNumber;
                        Thread.Sleep(5000);
                    }
                    //stop ()
                }
                // catch (Exception)
                catch (HalconException HDevExpDefaultException1)
                {
                    HDevExpDefaultException1.ToHTuple(out hv_Exception);
                }
            }
            HOperatorSet.CloseFramegrabber(hv_AcqHandle);
        }
        catch (HalconException HDevExpDefaultException)
        {
            ho_InfoModelContours.Dispose();
            ho_SignModelContours.Dispose();
            ho_Image.Dispose();
            ho_SymbolRegions.Dispose();
            ho_ROI_OCR_01_0.Dispose();
            ho_EDGE.Dispose();
            ho_ObjectSelected.Dispose();
            ho_InfoTransContours.Dispose();
            ho_SignTransContours.Dispose();

            hv_BarWidth.Dispose();
            hv_BarHeight.Dispose();
            hv_BarCodeHandle.Dispose();
            hv_InfoModel.Dispose();
            hv_SignModel.Dispose();
            hv_WindowHandle.Dispose();
            hv_AcqHandle.Dispose();
            hv_InfoRow.Dispose();
            hv_InfoColumn.Dispose();
            hv_InfoAngle.Dispose();
            hv_InfoScore.Dispose();
            hv_DecodedDataStrings.Dispose();
            hv_someitem.Dispose();
            hv_SignRow.Dispose();
            hv_SignColumn.Dispose();
            hv_SignAngle.Dispose();
            hv_SignScore.Dispose();
            hv_SymbolNames_OCR_01_0.Dispose();
            hv_Ocr_Split.Dispose();
            hv_Area.Dispose();
            hv_IDRow.Dispose();
            hv_IDColumn.Dispose();
            hv_IDRow1.Dispose();
            hv_IDColumn1.Dispose();
            hv_IDRow2.Dispose();
            hv_IDColumn2.Dispose();
            hv_IDHeight.Dispose();
            hv_IDWidth.Dispose();
            hv_IDRatio.Dispose();
            hv_HeadSignScale.Dispose();
            hv_HeadSignRow.Dispose();
            hv_HeadSignCol.Dispose();
            hv_HeadPhi.Dispose();
            hv_sign.Dispose();
            hv_BarIndex.Dispose();
            hv_Row.Dispose();
            hv_Column.Dispose();
            hv_InfoHomMat2D.Dispose();
            hv_SignHomMat2D.Dispose();
            hv_Exception.Dispose();

            throw HDevExpDefaultException;
        }
        ho_InfoModelContours.Dispose();
        ho_SignModelContours.Dispose();
        ho_Image.Dispose();
        ho_SymbolRegions.Dispose();
        ho_ROI_OCR_01_0.Dispose();
        ho_EDGE.Dispose();
        ho_ObjectSelected.Dispose();
        ho_InfoTransContours.Dispose();
        ho_SignTransContours.Dispose();

        hv_BarWidth.Dispose();
        hv_BarHeight.Dispose();
        hv_BarCodeHandle.Dispose();
        hv_InfoModel.Dispose();
        hv_SignModel.Dispose();
        hv_WindowHandle.Dispose();
        hv_AcqHandle.Dispose();
        hv_InfoRow.Dispose();
        hv_InfoColumn.Dispose();
        hv_InfoAngle.Dispose();
        hv_InfoScore.Dispose();
        hv_DecodedDataStrings.Dispose();
        hv_someitem.Dispose();
        hv_SignRow.Dispose();
        hv_SignColumn.Dispose();
        hv_SignAngle.Dispose();
        hv_SignScore.Dispose();
        hv_SymbolNames_OCR_01_0.Dispose();
        hv_Ocr_Split.Dispose();
        hv_Area.Dispose();
        hv_IDRow.Dispose();
        hv_IDColumn.Dispose();
        hv_IDRow1.Dispose();
        hv_IDColumn1.Dispose();
        hv_IDRow2.Dispose();
        hv_IDColumn2.Dispose();
        hv_IDHeight.Dispose();
        hv_IDWidth.Dispose();
        hv_IDRatio.Dispose();
        hv_HeadSignScale.Dispose();
        hv_HeadSignRow.Dispose();
        hv_HeadSignCol.Dispose();
        hv_HeadPhi.Dispose();
        hv_sign.Dispose();
        hv_BarIndex.Dispose();
        hv_Row.Dispose();
        hv_Column.Dispose();
        hv_InfoHomMat2D.Dispose();
        hv_SignHomMat2D.Dispose();
        hv_Exception.Dispose();
    }