public static bool CheckFunction(HWindowTool.HWindowTool hWindow, HObject ho_Image, HObject ho_CheckRegion, ModelConfig modelConfig, double minThreshold, double maxThreshold, double minScore, double minArea) { bool b = true; // Local iconic variables HObject ho_ImageReduced = null; HObject ho_ModelContours; HObject ho_ContoursAffineTrans, ho_RegionAffineTrans = null; HObject ho_Region = null, ho_ConnectedRegions = null, ho_RegionOpening = null; HObject ho_RegionUnion = null; // Local control variables HTuple hv_Width = new HTuple(), hv_Height = new HTuple(); HTuple hv_WindowHandle = new HTuple(); HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple(); HTuple hv_Angle1 = new HTuple(), hv_Score = new HTuple(); HTuple hv_HomMat2D = new HTuple(), hv_ImageFiles = new HTuple(); HTuple hv_Index = new HTuple(), hv_Row = new HTuple(); HTuple hv_Column = new HTuple(), hv_Angle = new HTuple(); HTuple hv_Scale = new HTuple(), hv_HomMat2D1 = new HTuple(); HTuple hv_Area = new HTuple(), hv_Row2 = new HTuple(); HTuple hv_Column2 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_ModelContours); HOperatorSet.GenEmptyObj(out ho_ContoursAffineTrans); HOperatorSet.GenEmptyObj(out ho_RegionAffineTrans); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionOpening); HOperatorSet.GenEmptyObj(out ho_RegionUnion); try { hv_Width.Dispose(); hv_Height.Dispose(); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); // 获取模型轮廓 ho_ModelContours.Dispose(); HOperatorSet.GetShapeModelContours(out ho_ModelContours, modelConfig.ModelID, 1); using (HDevDisposeHelper dh = new HDevDisposeHelper()) { hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Scale.Dispose(); hv_Score.Dispose(); HOperatorSet.FindScaledShapeModel(ho_Image, modelConfig.ModelID, (new HTuple(0)).TupleRad() , (new HTuple(360)).TupleRad(), 0.6, 1.5, 0.2, 1, 0.5, "least_squares", 0, 0.9, out hv_Row, out hv_Column, out hv_Angle, out hv_Scale, out hv_Score); } if ((int)(new HTuple((new HTuple(hv_Score.TupleLength())).TupleGreater(0))) != 0) { if ((int)(new HTuple(hv_Score.TupleGreater(minScore))) != 0) { hWindow.ViewController.AddMessage("Score:" + hv_Score.ToString(), Colors.Lime, 10, 10, AnchorType.LeftTop, CoordSystemType.window, false); hv_HomMat2D.Dispose(); HOperatorSet.VectorAngleToRigid(0, 0, 0, hv_Row, hv_Column, hv_Angle, out hv_HomMat2D); ho_ContoursAffineTrans.Dispose(); HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_ContoursAffineTrans, hv_HomMat2D); hv_HomMat2D1.Dispose(); HOperatorSet.VectorAngleToRigid(modelConfig.ModelRow, modelConfig.ModelColumn, 0, hv_Row, hv_Column, hv_Angle, out hv_HomMat2D1); ho_RegionAffineTrans.Dispose(); HOperatorSet.AffineTransRegion(ho_CheckRegion, out ho_RegionAffineTrans, hv_HomMat2D1, "nearest_neighbor"); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_RegionAffineTrans, out ho_ImageReduced ); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, minThreshold, maxThreshold); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_RegionOpening.Dispose(); HOperatorSet.OpeningCircle(ho_ConnectedRegions, out ho_RegionOpening, 3.5); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_RegionOpening, out ho_RegionUnion); hv_Area.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); HOperatorSet.AreaCenter(ho_RegionUnion, out hv_Area, out hv_Row2, out hv_Column2); if ((int)(new HTuple(hv_Area.TupleLess(minArea))) != 0) { hWindow.ViewController.AddMessage("NG", Colors.Red, 10, 35, AnchorType.LeftTop, CoordSystemType.window, false); // hWindow.repaint(); //刷新显示 hWindow.DisplayHObject(ho_RegionAffineTrans, Colors.Red, DrawModelType.margin); hWindow.DisplayHObject(ho_ContoursAffineTrans, Colors.Red, DrawModelType.margin); b = false; } else { hWindow.ViewController.AddMessage("OK:" + hv_Area.ToString(), Colors.Lime, 10, 35, AnchorType.LeftTop, CoordSystemType.window, false); //hWindow.repaint(); //刷新显示 hWindow.DisplayHObject(ho_RegionAffineTrans, Colors.Lime, DrawModelType.margin); hWindow.DisplayHObject(ho_ContoursAffineTrans, Colors.Lime, DrawModelType.margin); } } else { hWindow.ViewController.AddMessage("Low Score:" + hv_Score.ToString(), Colors.Red, 10, 10, AnchorType.LeftTop, CoordSystemType.window, false); // hWindow.repaint(); //刷新显示 b = false; } } else { hWindow.ViewController.AddMessage("Not Find Model", Colors.Red, 10, 10, AnchorType.LeftTop, CoordSystemType.window, false); // hWindow.repaint(); //刷新显示 b = false; } } catch (HalconException) { return(false); } finally { hWindow.Repaint(); //刷新显示 ho_ImageReduced.Dispose(); ho_ModelContours.Dispose(); ho_ContoursAffineTrans.Dispose(); ho_RegionAffineTrans.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_RegionOpening.Dispose(); ho_RegionUnion.Dispose(); hv_Width.Dispose(); hv_Height.Dispose(); hv_WindowHandle.Dispose(); hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Angle1.Dispose(); hv_Score.Dispose(); hv_HomMat2D.Dispose(); hv_ImageFiles.Dispose(); hv_Index.Dispose(); hv_Row.Dispose(); hv_Column.Dispose(); hv_Angle.Dispose(); hv_Scale.Dispose(); hv_HomMat2D1.Dispose(); hv_Area.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose(); } return(b); }