public void get_features(HObject ho_Region, out HTuple hv_Features) { // Local iconic variables HObject ho_SingleRegion, ho_Contours; // Local control variables HTuple hv_Circularity_xld = null, hv_ContLength = null; HTuple hv_Circularity = null, hv_Anisometry = null, hv_Bulkiness = null; HTuple hv_StructureFactor = null, hv_Distance = null, hv_Sigma = null; HTuple hv_Roundness = null, hv_Sides = null, hv_PSI1 = null; HTuple hv_PSI2 = null, hv_PSI3 = null, hv_PSI4 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_SingleRegion); HOperatorSet.GenEmptyObj(out ho_Contours); ho_SingleRegion.Dispose(); HOperatorSet.SelectObj(ho_Region, out ho_SingleRegion, 1); ho_Contours.Dispose(); HOperatorSet.GenContourRegionXld(ho_SingleRegion, out ho_Contours, "border"); HOperatorSet.CircularityXld(ho_Contours, out hv_Circularity_xld); HOperatorSet.Contlength(ho_SingleRegion, out hv_ContLength); HOperatorSet.Circularity(ho_SingleRegion, out hv_Circularity); HOperatorSet.Eccentricity(ho_SingleRegion, out hv_Anisometry, out hv_Bulkiness, out hv_StructureFactor); HOperatorSet.Roundness(ho_SingleRegion, out hv_Distance, out hv_Sigma, out hv_Roundness, out hv_Sides); HOperatorSet.MomentsRegionCentralInvar(ho_SingleRegion, out hv_PSI1, out hv_PSI2, out hv_PSI3, out hv_PSI4); hv_Features = new HTuple(); hv_Features = hv_Features.TupleConcat(hv_Circularity); hv_Features = hv_Features.TupleConcat(hv_Circularity_xld); //, PSI1, PSI2, PSI3, PSI4] ho_SingleRegion.Dispose(); ho_Contours.Dispose(); return; }
public void region_outer_circle(HObject ho_SelectedRegions, out HObject ho_outCircle, out HTuple hv_outer_Row, out HTuple hv_outer_Column, out HTuple hv_outer_Radius, out HTuple hv_Circularity) { // Local iconic variables HObject ho_RegionFillUp; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_outCircle); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); try { ho_RegionFillUp.Dispose(); HTuple Num = new HTuple(); HOperatorSet.CountObj(ho_SelectedRegions, out Num); if (Num.I == 0) { //MessageBox.Show("请先二值化图像"); hv_outer_Row = new HTuple(); hv_outer_Column = new HTuple(); hv_outer_Radius = new HTuple(); hv_Circularity = new HTuple(); return; } HOperatorSet.FillUp(ho_SelectedRegions, out ho_RegionFillUp); ho_outCircle.Dispose(); HOperatorSet.ShapeTrans(ho_RegionFillUp, out ho_outCircle, "outer_circle"); HOperatorSet.SmallestCircle(ho_outCircle, out hv_outer_Row, out hv_outer_Column, out hv_outer_Radius); HOperatorSet.Circularity(ho_RegionFillUp, out hv_Circularity); HTuple dist = new HTuple(), sigma = new HTuple(), roundness = new HTuple(), sides = new HTuple(); HOperatorSet.Roundness(ho_RegionFillUp, out dist, out sigma, out roundness, out sides); if (hv_outer_Row.Length > 1) { HOperatorSet.SelectShape(ho_outCircle, out ho_outCircle, "inner_radius", "and", hv_outer_Radius.TupleMax() - 1, hv_outer_Radius.TupleMax() + 1); hv_outer_Radius = hv_outer_Radius.TupleMax(); HTuple index = new HTuple(); index = hv_outer_Radius.TupleFind(hv_outer_Radius.TupleMax()); hv_outer_Row = hv_outer_Row[index]; hv_outer_Column = hv_outer_Column[index]; hv_Circularity = hv_Circularity[index]; } ho_RegionFillUp.Dispose(); return; } catch (HalconException HDevExpDefaultException) { ho_RegionFillUp.Dispose(); throw HDevExpDefaultException; } }
// Main procedure private void porosityHorizonatal() { // Local iconic variables HObject ho_Image = null, ho_Rectangle = null, ho_ImageReduced = null; HObject ho_ImageMean = null, ho_Region = null, ho_ConnectedRegions = null; HObject ho_RegionClosing = null, ho_SmallConnection = null; HObject ho_ContCircle = null; // Local control variables HTuple hv_AcqHandle = null, hv_found = null; HTuple hv_cnt = null, hv_bol = null, hv_porosity_area_px = null; HTuple hv_porosity_area_mm = null; HTuple hv_UsedThreshold = new HTuple(), hv_Circularity = new HTuple(); HTuple hv_Area = new HTuple(), hv_Row = new HTuple(), hv_Column = new HTuple(); HTuple hv_Length = new HTuple(), hv_circ_min = new HTuple(); HTuple hv_area_min = new HTuple(), hv_index = new HTuple(); HTuple hv_i = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_ImageMean); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_SmallConnection); HOperatorSet.GenEmptyObj(out ho_ContCircle); // Wait for CAM4 thread to be closed _waitHandleCam3.WaitOne(); // Close te thread DOOR _waitHandleCam3.Reset(); // Open camera frame HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1, "default", -1, "false", "default", "GC2591MP_CAM_3", 0, -1, out hv_AcqHandle); HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "ExposureTime", 35000.0); // 30 000 // Information for PLC that frame is opened DetectionHorStart(); hv_found = 0; hv_cnt = 0; hv_bol = 0; Porositydetectedhor = false; while (Porositydetectedhor == false) { ho_Image.Dispose(); HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle); ho_Rectangle.Dispose(); //HOperatorSet.GenRectangle1(out ho_Rectangle, 520, 200, 1050, 700); //HOperatorSet.GenRectangle1(out ho_Rectangle, 1020, 200, 1460, 700); HOperatorSet.GenRectangle1(out ho_Rectangle, 900, 200, 1460, 700); //HOperatorSet.GenRectangle1(out ho_Rectangle, 1120, 200, 1630, 700); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced); ho_ImageMean.Dispose(); HOperatorSet.MeanImage(ho_ImageReduced, out ho_ImageMean, 21, 21); ho_Region.Dispose(); HOperatorSet.BinaryThreshold(ho_ImageMean, out ho_Region, "max_separability", "dark", out hv_UsedThreshold); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_RegionClosing.Dispose(); HOperatorSet.ClosingCircle(ho_ConnectedRegions, out ho_RegionClosing, 17); ho_SmallConnection.Dispose(); HOperatorSet.Connection(ho_RegionClosing, out ho_SmallConnection); HOperatorSet.Circularity(ho_SmallConnection, out hv_Circularity); HOperatorSet.AreaCenter(ho_SmallConnection, out hv_Area, out hv_Row, out hv_Column); HOperatorSet.TupleLength(hv_Row, out hv_Length); // Criteria for porosity hv_circ_min = 0.5; hv_area_min = 300; // 300 - HDev //1000 hv_index = 0; HTuple end_val36 = hv_Length; HTuple step_val36 = 1; for (hv_i = 1; hv_i.Continue(end_val36, step_val36); hv_i = hv_i.TupleAdd(step_val36)) { if ((int)((new HTuple(((hv_Circularity.TupleSelect(hv_i - 1))).TupleGreater( hv_circ_min))).TupleAnd(new HTuple(((hv_Area.TupleSelect(hv_i - 1))).TupleGreater( hv_area_min)))) != 0) { hv_index = hv_i - 1; hv_found = hv_found + 1; hv_bol = 1; break; } else { hv_bol = 0; } } //HOperatorSet.ClearWindow(hv_porosityWinHandle); //HOperatorSet.DispObj(ho_Image, hv_porosityWinHandle); if ((int)((new HTuple(hv_found.TupleGreater(0))).TupleAnd(new HTuple(hv_bol.TupleEqual( 1)))) != 0) { PorosityIsDetected(); ho_ContCircle.Dispose(); //HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row.TupleSelect(hv_index), // hv_Column.TupleSelect(hv_index), 50, 0, 6.28318, "positive", 1); //HOperatorSet.DispObj(ho_ContCircle, hv_porosityWinHandle); hv_found = 0; hv_cnt = 0; Porositydetectedhor = true; } hv_cnt = hv_cnt + 1; } //HOperatorSet.ClearWindow(hv_porosityWinHandle); HOperatorSet.CloseFramegrabber(hv_AcqHandle); // Open the thread DOOR _waitHandleCam3.Set(); // Dispose all iconic variables ho_Image.Dispose(); ho_Rectangle.Dispose(); ho_ImageReduced.Dispose(); ho_ImageMean.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_RegionClosing.Dispose(); ho_SmallConnection.Dispose(); ho_ContCircle.Dispose(); }
//DateTime t1, t2, t3, t4,t5,t6,t7; private void action() { HObject ho_Region2 = null, ho_ConnectedRegions4 = null; HObject ho_SelectedRegions1 = null, ho_RegionClosing = null; HObject ho_RegionDifference = null, ho_ConnectedRegions1 = null; HObject ho_ObjectSelected1 = null, ho_Contours = null, ho_RegionErosion1 = null; HObject ho_RegionDilation1 = null, ho_RegionErosion = null; HObject ho_RegionIntersection = null, ho_RegionDilation2 = null; HObject ho_RegionDifference1 = null, ho_ConnectedRegions2 = null; HObject ho_SelectedRegions = null, ho_RegionUnion = null, ho_RegionDilation = null; HObject ho_ImageReduced = null, ho_Region1 = null, ho_ConnectedRegions3 = null; HObject ho_ObjectSelected2 = null, ho_RegionFillUp = null, ho_Circle = null; HObject ho_Circle1 = null, ho_RegionDifference2 = null, ho_RegionUnion1 = null; HObject ho_RegionUnion2 = null; HTuple hv_Area1 = new HTuple(), hv_Row2 = new HTuple(); HTuple hv_Column2 = new HTuple(), hv_Indices1 = new HTuple(); HTuple hv_Row3 = new HTuple(), hv_Column3 = new HTuple(); HTuple hv_Radius1 = new HTuple(), hv_StartPhi = new HTuple(); HTuple hv_EndPhi = new HTuple(), hv_PointOrder = new HTuple(); HTuple hv_Circularity = new HTuple(), hv_Area2 = new HTuple(); HTuple hv_Row5 = new HTuple(), hv_Column5 = new HTuple(); HTuple hv_Area3 = new HTuple(), hv_Row6 = new HTuple(); HTuple hv_Column6 = new HTuple(), hv_Indices2 = new HTuple(); HTuple hv_Row7 = new HTuple(), hv_Column7 = new HTuple(); HTuple hv_Radius2 = new HTuple(), hv_Row8 = new HTuple(); HTuple hv_Column8 = new HTuple(), hv_Radius3 = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Region2); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions4); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_ObjectSelected1); HOperatorSet.GenEmptyObj(out ho_Contours); HOperatorSet.GenEmptyObj(out ho_RegionErosion1); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); HOperatorSet.GenEmptyObj(out ho_RegionDilation2); HOperatorSet.GenEmptyObj(out ho_RegionDifference1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionUnion); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions3); HOperatorSet.GenEmptyObj(out ho_ObjectSelected2); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_Circle1); HOperatorSet.GenEmptyObj(out ho_RegionDifference2); HOperatorSet.GenEmptyObj(out ho_RegionUnion1); HOperatorSet.GenEmptyObj(out ho_RegionUnion2); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); //t3 = DateTime.Now; try { ho_Region2.Dispose(); HOperatorSet.Threshold(Image, out ho_Region2, 0, thv); ho_ConnectedRegions4.Dispose(); HOperatorSet.Connection(ho_Region2, out ho_ConnectedRegions4); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions4, out ho_SelectedRegions1, "area", "and", mjxx, mjsx); ho_RegionClosing.Dispose(); HOperatorSet.ClosingCircle(ho_SelectedRegions1, out ho_RegionClosing, 700); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionClosing, ho_SelectedRegions1, out ho_RegionDifference ); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1); HOperatorSet.AreaCenter(ho_ConnectedRegions1, out hv_Area1, out hv_Row2, out hv_Column2); HOperatorSet.TupleFind(hv_Area1, hv_Area1.TupleMax(), out hv_Indices1); ho_ObjectSelected1.Dispose(); HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected1, hv_Indices1 + 1); ho_Contours.Dispose(); HOperatorSet.GenContourRegionXld(ho_ObjectSelected1, out ho_Contours, "border"); HOperatorSet.FitCircleContourXld(ho_Contours, "algebraic", -1, 0, 0, 3, 2, out hv_Row3, out hv_Column3, out hv_Radius1, out hv_StartPhi, out hv_EndPhi, out hv_PointOrder); ho_RegionErosion1.Dispose(); HOperatorSet.ErosionCircle(ho_ObjectSelected1, out ho_RegionErosion1, 10.5); ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_RegionErosion1, out ho_RegionDilation1, 10.5); HOperatorSet.Circularity(ho_RegionDilation1, out hv_Circularity); ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_RegionClosing, out ho_RegionErosion, 25.5); ho_RegionIntersection.Dispose(); HOperatorSet.Intersection(ho_RegionDifference, ho_RegionErosion, out ho_RegionIntersection ); ho_RegionDilation2.Dispose(); HOperatorSet.DilationCircle(ho_RegionDilation1, out ho_RegionDilation2, 5.5); ho_RegionDifference1.Dispose(); HOperatorSet.Difference(ho_RegionIntersection, ho_RegionDilation2, out ho_RegionDifference1 ); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_RegionDifference1, out ho_ConnectedRegions2); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions2, out ho_SelectedRegions, "area", "and", 15, 99999000); ho_RegionUnion.Dispose(); HOperatorSet.Union1(ho_SelectedRegions, out ho_RegionUnion); HOperatorSet.AreaCenter(ho_RegionUnion, out hv_Area2, out hv_Row5, out hv_Column5); ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_RegionClosing, out ho_RegionDilation, 30); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_RegionDilation, out ho_ImageReduced); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, 170, 255); ho_ConnectedRegions3.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions3); HOperatorSet.AreaCenter(ho_ConnectedRegions3, out hv_Area3, out hv_Row6, out hv_Column6); HOperatorSet.TupleFind(hv_Area3, hv_Area3.TupleMax(), out hv_Indices2); ho_ObjectSelected2.Dispose(); HOperatorSet.SelectObj(ho_ConnectedRegions3, out ho_ObjectSelected2, hv_Indices2 + 1); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_ObjectSelected2, out ho_RegionFillUp); HOperatorSet.SmallestCircle(ho_RegionFillUp, out hv_Row7, out hv_Column7, out hv_Radius2); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row7, hv_Column7, hv_Radius2); HOperatorSet.InnerCircle(ho_RegionFillUp, out hv_Row8, out hv_Column8, out hv_Radius3); ho_Circle1.Dispose(); HOperatorSet.GenCircle(out ho_Circle1, hv_Row8, hv_Column8, hv_Radius3); ho_RegionDifference2.Dispose(); HOperatorSet.Difference(ho_Circle, ho_Circle1, out ho_RegionDifference2); ho_RegionUnion1.Dispose(); HOperatorSet.Union2(ho_RegionDifference2, ho_RegionUnion, out ho_RegionUnion1 ); ho_RegionUnion2.Dispose(); HOperatorSet.Union2(ho_RegionUnion1, ho_RegionDilation1, out RegionToDisp ); if (hv_Area2.TupleLength() == 0) { hv_Area2 = 0; } HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("垫片内孔圆度"); hv_result = hv_result.TupleConcat(hv_Circularity.D); hv_result = hv_result.TupleConcat("垫片内孔直径"); hv_result = hv_result.TupleConcat(hv_Radius1.D * 2 * pixeldist); hv_result = hv_result.TupleConcat("垫片灰尘"); hv_result = hv_result.TupleConcat(hv_Area2.D); hv_result = hv_result.TupleConcat("不圆"); hv_result = hv_result.TupleConcat((hv_Radius2.D - hv_Radius3.D) * pixeldist); result = hv_result.Clone(); //t4 = DateTime.Now; } 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(1000 * pixeldist); result = hv_result.Clone(); } finally { ho_Region2.Dispose(); ho_ConnectedRegions4.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionClosing.Dispose(); ho_RegionDifference.Dispose(); ho_ConnectedRegions1.Dispose(); ho_ObjectSelected1.Dispose(); ho_Contours.Dispose(); ho_RegionErosion1.Dispose(); ho_RegionDilation1.Dispose(); ho_RegionErosion.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionDilation2.Dispose(); ho_RegionDifference1.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionUnion.Dispose(); ho_RegionDilation.Dispose(); ho_ImageReduced.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions3.Dispose(); ho_ObjectSelected2.Dispose(); ho_RegionFillUp.Dispose(); ho_Circle.Dispose(); ho_Circle1.Dispose(); ho_RegionDifference2.Dispose(); ho_RegionUnion1.Dispose(); ho_RegionUnion2.Dispose(); algorithm.Region.Dispose(); } }
//DateTime t1, t2, t3, t4,t5,t6,t7; private void action() { HObject ho_Image1, ho_Image2, ho_Image33, im; HObject ho_Image3, ho_ImageResult1, ho_ImageResult2, ho_ImageResult3; HObject ho_Region, ho_ConnectedRegions, ho_SelectedRegions; HObject ho_RegionDilation, ho_RegionFillUp, ho_RegionDifference; HObject ho_ConnectedRegions1, ho_SelectedRegions1, ho_GrayImage; HObject ho_Region1, ho_ConnectedRegions2, ho_SelectedRegions2; HObject ho_RegionFillUp1; // Local control variables HTuple hv_Circularity = null, hv_Circularity1 = null; HTuple hv_Area = null, hv_Row = null, hv_Column = null, hv_Area2 = null; HTuple hv_Area1 = null, hv_Row1 = null, hv_Column1 = null; HTuple hv_Row2 = null, hv_Column2 = null, hv_Radius = null; HTuple hv_Row3 = null, hv_Column3 = null, hv_Radius1 = null, hd = null; HTuple hv_Circularity2 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image1); HOperatorSet.GenEmptyObj(out im); HOperatorSet.GenEmptyObj(out ho_Image33); 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_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_RegionDifference); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); HOperatorSet.GenEmptyObj(out ho_GrayImage); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2); HOperatorSet.GenEmptyObj(out ho_SelectedRegions2); HOperatorSet.GenEmptyObj(out ho_RegionFillUp1); //t3 = DateTime.Now; try { ho_Image1.Dispose(); ho_Image2.Dispose(); ho_Image3.Dispose(); HOperatorSet.Decompose3(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, "hls"); HOperatorSet.SubImage(ho_Image1, ho_Image2, out ho_ImageResult1, 1, 0); //im.Dispose(); //HOperatorSet.MeanImage(ho_ImageResult1,out im,9,9); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageResult1, out ho_Region, 10, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions, out ho_SelectedRegions, "max_area", 70); ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_SelectedRegions, out ho_RegionDilation, 1.5); HOperatorSet.AreaCenter(ho_RegionDilation, out hv_Area2, out hv_Row, out hv_Column); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_RegionDilation, out ho_RegionFillUp); ho_RegionDifference.Dispose(); HOperatorSet.Difference(ho_RegionFillUp, ho_RegionDilation, out ho_RegionDifference ); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions1, out ho_SelectedRegions1, "max_area", 70); HOperatorSet.Circularity(ho_SelectedRegions1, out hv_Circularity); HOperatorSet.Circularity(ho_RegionFillUp, out hv_Circularity1); HOperatorSet.AreaCenter(ho_SelectedRegions1, out hv_Area, out hv_Row, out hv_Column); HOperatorSet.AreaCenter(ho_RegionFillUp, out hv_Area1, out hv_Row1, out hv_Column1); ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(Image, out ho_GrayImage); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_GrayImage, out ho_Region1, 80, 255); ho_ConnectedRegions2.Dispose(); HOperatorSet.Connection(ho_Region1, out ho_ConnectedRegions2); ho_SelectedRegions2.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions2, out ho_SelectedRegions2, "max_area", 70); ho_RegionFillUp1.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions2, out ho_RegionFillUp1); HOperatorSet.SmallestCircle(ho_RegionFillUp1, out hv_Row2, out hv_Column2, out hv_Radius); HOperatorSet.InnerCircle(ho_RegionFillUp1, out hv_Row3, out hv_Column3, out hv_Radius1); HOperatorSet.Circularity(ho_RegionFillUp1, out hv_Circularity2); HOperatorSet.ReduceDomain(Image, ho_SelectedRegions1, out ho_Image33); HOperatorSet.Intensity(ho_SelectedRegions1, ho_Image33, out hd, out hv_Column); HOperatorSet.Union1(ho_RegionDilation, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("橡皮圆度"); hv_result = hv_result.TupleConcat(hv_Circularity1.D); hv_result = hv_result.TupleConcat("橡皮内孔圆度"); hv_result = hv_result.TupleConcat(hv_Circularity.D); hv_result = hv_result.TupleConcat("橡皮内孔面积"); hv_result = hv_result.TupleConcat(hv_Area.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_Area1.D - hv_Area.D - hv_Area2.D); hv_result = hv_result.TupleConcat("外圆圆度"); hv_result = hv_result.TupleConcat(hv_Circularity2.D); hv_result = hv_result.TupleConcat("外圆内圆直径"); hv_result = hv_result.TupleConcat(hv_Radius1.D * pixeldist * 2); hv_result = hv_result.TupleConcat("外圆外圆直径"); hv_result = hv_result.TupleConcat(hv_Radius.D * pixeldist * 2); hv_result = hv_result.TupleConcat("内孔灰度"); hv_result = hv_result.TupleConcat(hd.D); result = hv_result.Clone(); //t4 = DateTime.Now; } 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(0); 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(0); 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(0); result = hv_result.Clone(); } finally { ho_Image1.Dispose(); ho_Image2.Dispose(); ho_Image3.Dispose(); ho_ImageResult1.Dispose(); ho_ImageResult2.Dispose(); ho_ImageResult3.Dispose(); ho_Region.Dispose(); im.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionDilation.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionDifference.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); ho_GrayImage.Dispose(); ho_Region1.Dispose(); ho_ConnectedRegions2.Dispose(); ho_SelectedRegions2.Dispose(); ho_RegionFillUp1.Dispose(); algorithm.Region.Dispose(); } }
//DateTime t1, t2, t3, t4,t5,t6,t7; private void action() { HObject ho_GrayImage, ho_Region, regd, regd2, regd3; HObject ho_ConnectedRegions, ho_SelectedRegions, ho_Circle; HObject ho_ImageReduced, ho_Region1, ho_RegionClosing, ho_ConnectedRegions1; HObject ho_SelectedRegions1; // Local control variables HTuple hv_Row2 = null, hv_Column2 = null, hv_Radius1 = null, hd = null; HTuple hv_Row = null, hv_Column = null, hv_Radius = null; HTuple hv_Mean = null, hv_Deviation = null, hv_Circularity = null; HTuple hv_Area = null, hv_Row1 = null, hv_Column1 = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_GrayImage); HOperatorSet.GenEmptyObj(out regd); HOperatorSet.GenEmptyObj(out regd3); HOperatorSet.GenEmptyObj(out regd2); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region1); HOperatorSet.GenEmptyObj(out ho_RegionClosing); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1); HOperatorSet.GenEmptyObj(out ho_SelectedRegions1); //t3 = DateTime.Now; try { ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(Image, out ho_GrayImage); ho_Region.Dispose(); HOperatorSet.Threshold(ho_GrayImage, out ho_Region, 40, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions, out ho_SelectedRegions, "max_area", 70); regd.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions, out regd); HOperatorSet.InnerCircle(regd, out hv_Row2, out hv_Column2, out hv_Radius1); HOperatorSet.SmallestCircle(ho_SelectedRegions, out hv_Row, out hv_Column, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius / 1.7); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_GrayImage, ho_Circle, out ho_ImageReduced); HOperatorSet.Intensity(ho_Circle, ho_ImageReduced, out hv_Mean, out hv_Deviation); ho_Region1.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region1, hv_Mean - 10, 255); ho_RegionClosing.Dispose(); HOperatorSet.ClosingCircle(ho_Region1, out ho_RegionClosing, 3.5); ho_ConnectedRegions1.Dispose(); HOperatorSet.Connection(ho_RegionClosing, out ho_ConnectedRegions1); ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShapeStd(ho_ConnectedRegions1, out ho_SelectedRegions1, "max_area", 70); regd2.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions1, out regd2); HOperatorSet.Circularity(regd2, out hv_Circularity); HOperatorSet.AreaCenter(regd2, out hv_Area, out hv_Row1, out hv_Column1); HOperatorSet.Union1(regd2, out RegionToDisp); HOperatorSet.ReduceDomain(ho_GrayImage, regd2, out regd3); HOperatorSet.Intensity(regd2, regd3, out hd, out hv_Row1); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("橡皮内孔圆度"); hv_result = hv_result.TupleConcat(hv_Circularity.D); hv_result = hv_result.TupleConcat("橡皮内孔面积"); hv_result = hv_result.TupleConcat(hv_Area.D); hv_result = hv_result.TupleConcat("金属外圆"); hv_result = hv_result.TupleConcat(hv_Radius.D * pixeldist * 2); hv_result = hv_result.TupleConcat("金属内圆"); hv_result = hv_result.TupleConcat(hv_Radius1.D * pixeldist * 2); hv_result = hv_result.TupleConcat("内孔灰度"); hv_result = hv_result.TupleConcat(hd.D); result = hv_result.Clone(); //t4 = DateTime.Now; } 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(0); hv_result = hv_result.TupleConcat("金属内圆"); hv_result = hv_result.TupleConcat(0); hv_result = hv_result.TupleConcat("内孔灰度"); hv_result = hv_result.TupleConcat(0); result = hv_result.Clone(); } finally { regd.Dispose(); regd2.Dispose(); regd3.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_Circle.Dispose(); ho_ImageReduced.Dispose(); ho_Region1.Dispose(); ho_RegionClosing.Dispose(); ho_ConnectedRegions1.Dispose(); ho_SelectedRegions1.Dispose(); algorithm.Region.Dispose(); } }
private void action() { // Local iconic variables HObject ho_Circle, ho_Region, ho_ImageReduced, ho_ConnectedRegions, ho_RegionDilation, ho_RegionErosion, ho_RegionDilation1; HObject ho_SelectedRegions, ho_RegionIntersection = null; HObject ho_RegionFillUp = null, ho_RegionTrans = null, ho_Circle1 = null; // Local control variables HTuple hv_ir = null, hv_yy = null, hv_Distance = null, hv_Sigma = null, hv_Roundness = null, hv_Sides = null; HTuple hv_Number = null, hv_Row1 = new HTuple(), hv_Column1 = new HTuple(); HTuple hv_Radius1 = new HTuple(), hv_Circularity = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.GenEmptyObj(out ho_ImageReduced); HOperatorSet.GenEmptyObj(out ho_Region); HOperatorSet.GenEmptyObj(out ho_RegionErosion); HOperatorSet.GenEmptyObj(out ho_RegionDilation); HOperatorSet.GenEmptyObj(out ho_RegionDilation1); HOperatorSet.GenEmptyObj(out ho_ConnectedRegions); HOperatorSet.GenEmptyObj(out ho_SelectedRegions); HOperatorSet.GenEmptyObj(out ho_RegionIntersection); HOperatorSet.GenEmptyObj(out ho_RegionFillUp); HOperatorSet.GenEmptyObj(out ho_RegionTrans); HOperatorSet.GenEmptyObj(out ho_Circle1); HOperatorSet.Union1(algorithm.Region, out RegionToDisp); try { ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, DCenterRow, DCenterColumn, DRadius); ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(Image, ho_Circle, out ho_ImageReduced); ho_Region.Dispose(); HOperatorSet.Threshold(ho_ImageReduced, out ho_Region, Dthv, 255); ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_Region, out ho_ConnectedRegions); ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", mjxx, mjsx); hv_ir = -1; hv_yy = -1; HOperatorSet.CountObj(ho_SelectedRegions, out hv_Number); if ((int)(new HTuple(hv_Number.TupleEqual(1))) != 0) { //ho_RegionIntersection.Dispose(); //HOperatorSet.Intersection(ho_Circle, ho_SelectedRegions, out ho_RegionIntersection // ); ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions, out ho_RegionFillUp); ho_RegionTrans.Dispose(); HOperatorSet.ShapeTrans(ho_RegionFillUp, out ho_RegionTrans, "inner_circle"); HOperatorSet.SmallestCircle(ho_RegionTrans, out hv_Row1, out hv_Column1, out hv_Radius1); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionDilation1.Dispose(); HOperatorSet.Circularity(ho_RegionFillUp, out hv_Circularity); HOperatorSet.DilationCircle(ho_RegionFillUp, out ho_RegionDilation1, 15); HOperatorSet.ErosionCircle(ho_RegionDilation1, out ho_RegionErosion, 40); HOperatorSet.DilationCircle(ho_RegionErosion, out ho_RegionDilation, 25); HOperatorSet.Roundness(ho_RegionDilation, out hv_Distance, out hv_Sigma, out hv_Roundness, out hv_Sides); //shape_trans (RegionFillUp, RegionTrans1, 'outer_circle') //* smallest_circle (RegionTrans1, Row, Column, Radius) //* gen_region_line (RegionLines, Row, Column, Row1, Column1) //* distance_pp (Row1, Column1, Row, Column, Distance1) //* m := Radius-Radius1 //* n := Distance1 ho_Circle1.Dispose(); HOperatorSet.GenCircle(out ho_Circle1, hv_Row1, hv_Column1, hv_Radius1); if (hv_Radius1 * 2 * pixeldist >= this.mj && hv_Radius1 * 2 * pixeldist <= this.cd) { hv_ir = hv_Radius1 * 2 * pixeldist; } else { hv_ir = -1; } if (hv_Roundness >= this.y1 && hv_Roundness <= this.y2) { hv_yy = hv_Roundness; } else { hv_yy = -1; } } HOperatorSet.Union1(ho_Circle1, out RegionToDisp); HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("内圆直径"); hv_result = hv_result.TupleConcat(hv_ir); hv_result = hv_result.TupleConcat("圆度"); hv_result = hv_result.TupleConcat(hv_yy); result = hv_result.Clone(); ho_Circle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionTrans.Dispose(); ho_Circle1.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionDilation1.Dispose(); algorithm.Region.Dispose(); } catch { HTuple hv_result = GetHv_result(); hv_result = hv_result.TupleConcat("内圆直径"); hv_result = hv_result.TupleConcat(-1); hv_result = hv_result.TupleConcat("圆度"); hv_result = hv_result.TupleConcat(-1); result = hv_result.Clone(); ho_Circle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionTrans.Dispose(); ho_Circle1.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionDilation1.Dispose(); algorithm.Region.Dispose(); } finally { ho_Circle.Dispose(); ho_ImageReduced.Dispose(); ho_Region.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionIntersection.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionTrans.Dispose(); ho_Circle1.Dispose(); ho_RegionErosion.Dispose(); ho_RegionDilation.Dispose(); ho_RegionDilation1.Dispose(); algorithm.Region.Dispose(); } }
// private void read_button_Click(object sender, EventArgs e) { //程序开始 HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill"); HOperatorSet.SetColored(hv_ExpDefaultWinHandle, 12); //读取图片 //ho_Image.Dispose(); //HOperatorSet.ReadImage(out ho_Image, "E:/WORKS/halcon/zhao_jobs/zhao_jobs/1-500-2.JPG"); //dev_close_window(...); HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); //获取图像窗口 //dev_open_window(...); //彩色图转成灰度图 ho_GrayImage.Dispose(); HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage); //阈值处理 ho_Regions.Dispose(); HOperatorSet.BinaryThreshold(ho_GrayImage, out ho_Regions, "max_separability", "dark", out hv_UsedThreshold); //求图像联通域 ho_Connection.Dispose(); HOperatorSet.Connection(ho_Regions, out ho_Connection); //将区域闭合 ho_RegionResult.Dispose(); HOperatorSet.CloseEdges(ho_Connection, ho_GrayImage, out ho_RegionResult, 16); //选择合适的区域 ho_SelectedRegions.Dispose(); HOperatorSet.SelectShape(ho_RegionResult, out ho_SelectedRegions, "area", "and", 2040.82, 200000); //填充区域孔洞 ho_RegionFillUp.Dispose(); HOperatorSet.FillUp(ho_SelectedRegions, out ho_RegionFillUp); //区域膨胀处理 ho_RegionDilation.Dispose(); HOperatorSet.DilationCircle(ho_RegionFillUp, out ho_RegionDilation, 15.5); //将区域群合成一个区域 ho_RegionUnion.Dispose(); HOperatorSet.Union2(ho_RegionDilation, ho_RegionDilation, out ho_RegionUnion); // 获取刚兴趣区域图像 ho_ImageReduced.Dispose(); HOperatorSet.ReduceDomain(ho_GrayImage, ho_RegionUnion, out ho_ImageReduced); //对感兴趣区域图像进行阈值处理 ho_Regions1.Dispose(); HOperatorSet.BinaryThreshold(ho_ImageReduced, out ho_Regions1, "max_separability", "dark", out hv_UsedThreshold1); //区域腐蚀处理,用于去除区域之间的粘结 ho_RegionErosion.Dispose(); HOperatorSet.ErosionCircle(ho_Regions1, out ho_RegionErosion, 1.5); //求图像连通域 ho_ConnectedRegions.Dispose(); HOperatorSet.Connection(ho_RegionErosion, out ho_ConnectedRegions); //选择合适的颗粒,去除无用的杂物 ho_SelectedRegions1.Dispose(); HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions1, "area", "and", 2000, 9999999); //对颗粒进行膨胀处理 ho_RegionDilation1.Dispose(); HOperatorSet.DilationCircle(ho_SelectedRegions1, out ho_RegionDilation1, 10.5); //数颗粒的个数 HOperatorSet.CountObj(ho_RegionDilation1, out hv_Number); //对颗粒按照第一个点的行坐标进行排序 ho_SortedRegions.Dispose(); HOperatorSet.SortRegion(ho_RegionDilation1, out ho_SortedRegions, "first_point", "false", "row"); //求颗粒的面积和中心坐标 HOperatorSet.AreaCenter(ho_SortedRegions, out hv_Area, out hv_Row, out hv_Column); //显示图像和选中的颗粒 HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle); HOperatorSet.DispObj(ho_SortedRegions, hv_ExpDefaultWinHandle); //显示图像的代码 HTuple end_val47 = hv_Number; HTuple step_val47 = 1; for (hv_i = 1; hv_i.Continue(end_val47, step_val47); hv_i = hv_i.TupleAdd(step_val47)) { ho_ObjectSelected_1.Dispose(); HOperatorSet.SelectObj(ho_SortedRegions, out ho_ObjectSelected_1, hv_i); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "red"); HOperatorSet.DispObj(ho_ObjectSelected_1, hv_ExpDefaultWinHandle); HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_Row.TupleSelect(hv_i - 1), hv_Column.TupleSelect(hv_i - 1)); HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "white"); HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_i); //write_string (WindowHandle, Area[i-1]) } //求面积占比 HOperatorSet.AreaCenter(ho_Regions, out hv_Area1, out hv_Row1, out hv_Column1); hv_Area2 = hv_Area1.TupleReal(); hv_area = ((hv_Width * hv_Height)).TupleReal(); hv_bizhong = hv_Area2 / hv_area; //计算颗粒的长度 HOperatorSet.Contlength(ho_SortedRegions, out hv_ContLength); //计算颗粒的圆度 HOperatorSet.Circularity(ho_SortedRegions, out hv_Circularity); //计算颗粒等效椭圆的长短轴 HOperatorSet.EllipticAxis(ho_SortedRegions, out hv_Ra, out hv_Rb, out hv_Phi); //求长短轴之比 HOperatorSet.TupleDiv(hv_Ra, hv_Rb, out hv_Quot); //定义总个数 hv_all = 0; //定义圆形颗粒个数 hv_ro = 0; //定义条形颗粒个数 hv_ti = 0; //定义片状颗粒个数 hv_pi = 0; HTuple end_val78 = hv_Number - 1; HTuple step_val78 = 1; for (hv_i = 0; hv_i.Continue(end_val78, step_val78); hv_i = hv_i.TupleAdd(step_val78)) { if ((int)((new HTuple(((hv_ContLength.TupleSelect(hv_i))).TupleGreater(200))).TupleAnd(new HTuple(((hv_ContLength.TupleSelect(hv_i))).TupleLess(80000)))) != 0) { hv_all = hv_all + 1; if ((int)(new HTuple(((hv_Circularity.TupleSelect(hv_i))).TupleGreater(0.65))) != 0) { hv_ro = hv_ro + 1; } if ((int)(new HTuple(((hv_Quot.TupleSelect(hv_i))).TupleGreater(3))) != 0) { hv_ti = hv_ti + 1; } else { hv_pi = hv_pi + 1; } } } //decompose3 (Image, Image1, Image2, Image3) ho_Image.Dispose(); ho_GrayImage.Dispose(); ho_Regions.Dispose(); ho_Connection.Dispose(); ho_RegionResult.Dispose(); ho_SelectedRegions.Dispose(); ho_RegionFillUp.Dispose(); ho_RegionDilation.Dispose(); ho_RegionUnion.Dispose(); ho_ImageReduced.Dispose(); ho_Regions1.Dispose(); ho_RegionErosion.Dispose(); ho_ConnectedRegions.Dispose(); ho_SelectedRegions1.Dispose(); ho_RegionDilation1.Dispose(); ho_SortedRegions.Dispose(); ho_ObjectSelected_1.Dispose(); MessageBox.Show("占图比重为:" + hv_bizhong + "\n颗粒个数:" + hv_Number + "\n圆形颗粒个数:" + hv_ro + "\n条形颗粒个数" + hv_ti + "\n片形颗粒个数" + hv_pi); }