C3032
2025-12-30 65509ea2a0808389a07a446f2df1cadb16d97dbc
LB_VisionProcesses/Alogrithms/OpenCvSharp/FindModelTool/FindModelToolEdit.cs
@@ -241,9 +241,10 @@
                if (Subject.InputImage != null && Subject.InputImage is Mat)
                {
                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
                    {
                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
                        inputImageHSmartWindowControl.ShowHoImage(image);
                }
                        Type type = Subject.Params.ROI?.GetType();
                        if (Subject.Params.ROI != null)
                        {
@@ -298,9 +299,6 @@
                        }
                        ShowModel(((FindModelTool)Subject).ModelID);
                    }
                }
            }));
        }
@@ -359,10 +357,11 @@
                if (Subject.InputImage != null && Subject.InputImage is Mat)
                {
                    using (HImage image = TAlgorithm.Mat2HObject((Mat)Subject.InputImage))
                    {
                        image.GetImageSize(out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
                    TAlgorithm.Mat2HObject((Mat)Subject.InputImage, out HObject image);
                    HOperatorSet.GetImageSize(image, out HTuple ho_ImageWidth, out HTuple ho_ImageHeight);
                        recordImageHSmartWindowControl.ShowHoImage(image);
                }
                        //先判断子类再判断父类
                        if (Subject.Record != null && Subject.Record is MsgRecord msgRecord)
                        {
@@ -377,9 +376,6 @@
                        {
                            recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_OK, true);
                            recordImageHSmartWindowControl.DispObj(objRecord.RecordObject_NG, false);
                        }
                    }
                }
                GC.Collect();
@@ -502,9 +498,9 @@
                    HTuple hv_imageHeight = 0;
                    if (InputImage != null && InputImage is Mat)
                    {
                        using (HImage image = TAlgorithm.Mat2HObject((Mat)InputImage))
                        {
                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject image);
                            HOperatorSet.GetImageSize(image, out hv_imageWidth, out hv_imageHeight);
                    }
                            switch (type)
                            {
                                case RoiType.Rectangle2:
@@ -524,8 +520,6 @@
                                default:
                                    inputImageHSmartWindowControl.oRoi = null;
                                    break;
                            }
                        }
                    }
                }
            }
@@ -1102,14 +1096,13 @@
            if (InputImage != null && InputImage is Mat)
            {
                imgTabControl.SelectedTab = tabPageModelImage;
                using (HImage hoDomainImage = TAlgorithm.Mat2HObject((Mat)InputImage))
                {
                TAlgorithm.Mat2HObject((Mat)InputImage, out HObject hoDomainImage);
                    HOperatorSet.GetImageSize(hoDomainImage, out HTuple hv_imageWidth, out HTuple hv_imageHeight);
                    createModelImageHSmartWindowControl.ShowHoImage((HObject)hoDomainImage);
                    createModelImageHSmartWindowControl.bAollowDraw = true;
                    createModelImageHSmartWindowControl.oRoi = new HRectangle2(hv_imageWidth.TupleReal() / 2, hv_imageHeight.TupleReal() / 2
                        , 0, hv_imageWidth.TupleReal() / 4, hv_imageHeight.TupleReal() / 4);
                }
            }
        }
@@ -1120,6 +1113,7 @@
                if (InputImage != null && InputImage is Mat)
                {
                    double result = 0;
                    if (Enum.TryParse(cmbModelType.Text, out ModelType modelType))
                    {
                        string NumLevels = this.dtxtModelParam1.Text;
@@ -1137,29 +1131,27 @@
                        string Contrast = this.dtxtModelParam11.Text;
                        int MinContrast = Convert.ToInt16(this.dtxtModelParam12.Text);
                        HRectangle2 ROI = (HRectangle2)createModelImageHSmartWindowControl.oRoi;
                        using (HRegion hRectangle = new HRegion())
                        {
                            hRectangle.GenRectangle2(ROI.Row, ROI.Column, ROI.Phi, ROI.SemiLength1, ROI.SemiLength2);
                            using (HImage hoDomainImage = TAlgorithm.Mat2HObject((Mat)InputImage))
                            {
                        HOperatorSet.GenRectangle2(out HObject hRectangle, ROI.Row, ROI.Column, ROI.Phi, ROI.SemiLength1, ROI.SemiLength2);
                        TAlgorithm.Mat2HObject((Mat)InputImage, out HObject hoDomainImage);
                                HTuple hv_Channels = new HTuple();
                                //判断是否为灰度图
                                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                                {
                                    try
                                    {
                                        //hv_Channels = hoDomainImage.CountChannels();
                                        //if (hv_Channels.TupleInt() != 1)
                                        //    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
                                HOperatorSet.CountChannels(hoDomainImage, out hv_Channels);
                                if (hv_Channels.TupleInt() != 1)
                                    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
                                        ////转换后再次检查是否为灰度图
                                        //HOperatorSet.CountChannels(hoDomainImage, out hv_Channels);
                                        //if (hv_Channels.TupleInt() != 1)
                                        //    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
                                //转换后再次检查是否为灰度图
                                HOperatorSet.CountChannels(hoDomainImage, out hv_Channels);
                                if (hv_Channels.TupleInt() != 1)
                                    HOperatorSet.Rgb1ToGray(hoDomainImage, out hoDomainImage);
                                    }
                                    catch { }
                                }
                                HObject hoImageReduced = hoDomainImage.Rgb1ToGray().ReduceDomain(hRectangle);
                        HOperatorSet.ReduceDomain(hoDomainImage, hRectangle, out HObject hoImageReduced);
                                HOperatorSet.CropDomain(hoImageReduced, out hoImageReduced);
                                TAlgorithm.HObject2Mat(hoImageReduced, out Mat hoModelImage);
                                bool bCreateModel = false;
@@ -1186,8 +1178,7 @@
                                if (bCreateModel)
                                {
                                    using (HObject ho_ModelContours = new HObject())
                                    {
                            HObject ho_ModelContours = new HObject();
                                        //switch (((FindModelTool)Subject).ModelID.Type)
                                        //{
                                        //    case ModelType.局部变形模板:
@@ -1205,15 +1196,10 @@
                                        //建模成功导航到子页
                                        parasTabControl.SelectedTab = tabPageRunParas;
                                        //modelImageHSmartWindowControl.ShowHoImage(((HFindModelTool)Subject).ModelID.hoImage);
                                        using (HImage modelImage = TAlgorithm.Mat2HObject(((FindModelTool)Subject).ModelID.hoImage))
                                        {
                            TAlgorithm.Mat2HObject(((FindModelTool)Subject).ModelID.hoImage, out HObject modelImage);
                                            modelImageHSmartWindowControl.ShowHoImage(modelImage);
                                            modelImageHSmartWindowControl.DispObj(ho_ModelContours, false);
                                            modelImageHSmartWindowControl.ShowMsg("创建模板成功", true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
@@ -1229,9 +1215,7 @@
                if (ModelID != null && ModelID.Width > 0)
                {
                    //HOperatorSet.GenEmptyObj(out HObject ho_ModelContours);
                    using (HRegion ho_ModelContours = new HRegion())
                    {
                    HOperatorSet.GenEmptyObj(out HObject ho_ModelContours);
                        //switch (ModelID.Type)
                        //{
                        //    case ModelType.各向异形模板:
@@ -1247,14 +1231,11 @@
                        //HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ModelContours, hv_HomMat2D);
                        modelImageHSmartWindowControl.ClearObj();
                        using (HImage hoImage = TAlgorithm.Mat2HObject(ModelID.hoImage))
                        {
                    TAlgorithm.Mat2HObject(ModelID.hoImage, out HObject hoImage);
                            //modelImageHSmartWindowControl.ShowHoImage(ModelID.hoImage);
                            modelImageHSmartWindowControl.ShowHoImage(hoImage);
                            modelImageHSmartWindowControl.DispObj(ho_ModelContours, false);
                            modelImageHSmartWindowControl.ShowMsg("创建模板成功", true);
                        }
                    }
                }
            }
            catch { }