public HRegion Process(HRegion region) { if (Math.Abs(Radius) < 0.0000001) { return(region.MoveRegion(0, 0)); } var dilation = region.DilationCircle(Radius); return(dilation); }
public bool FindShapeModeAct(HImage refImage, CreateShapeModel createShapeModel, HImage image) { this.createShapeModel = createShapeModel; this.refImage = refImage; if (createShapeModel.hShapeModel == null || !createShapeModel.hShapeModel.IsInitialized() || createShapeModel.createNewModelID) { if (!createShapeModel.CreateShapeModelAct(refImage)) { return(false); } } try { HImage searchImage; if (SearchRegion != null && SearchRegion.IsInitialized()) { searchImage = image.ReduceDomain(SearchRegion); } else { searchImage = image.Clone(); } ////阈值切割出预选框/// LG_lenght = new HTuple(); LG_Area = new HTuple(); DP_width = new HTuple(); HRegion threshold_region, closing_region, fill_up_region, connection; threshold_region = searchImage.Threshold(new HTuple(LG_threshould), 255).OpeningCircle(5.0); closing_region = threshold_region.ClosingRectangle1(Closing_width, Closing_height); fill_up_region = closing_region.FillUp(); connection = fill_up_region.Connection(); if (scan_regions != null && scan_regions.IsInitialized()) { scan_regions.Dispose(); } scan_regions = connection.SelectShape ( new HTuple("area").TupleConcat("rect2_len1").TupleConcat("rect2_len2"), "and", new HTuple(LG_Area_min).TupleConcat(LG_lenght_min / 2).TupleConcat(DP_width_min / 2), new HTuple(LG_Area_max).TupleConcat(LG_lenght_max / 2).TupleConcat(DP_width_max / 2) ); if (threshold_region != null && threshold_region.IsInitialized()) { threshold_region.Dispose(); } if (closing_region != null && closing_region.IsInitialized()) { closing_region.Dispose(); } if (fill_up_region != null && fill_up_region.IsInitialized()) { fill_up_region.Dispose(); } if (connection != null && connection.IsInitialized()) { connection.Dispose(); } ////阈值切割出预选框/// row = new HTuple(); column = new HTuple(); angle = new HTuple(); scale = new HTuple(); score = new HTuple(); int Num = scan_regions.CountObj(); if (Num == 0) { return(true); } for (int i = 1; i <= Num; i++) { HRegion scan_region_temp = scan_regions.SelectObj(i); double row_rect2, col_rect2, phi_rect2, leght1_rect2, lenght2_rect2; scan_region_temp.SmallestRectangle2(out row_rect2, out col_rect2, out phi_rect2, out leght1_rect2, out lenght2_rect2); if (LG_lenght == null || LG_lenght.Length == 0) { LG_lenght = new HTuple(2 * leght1_rect2); } else { LG_lenght = LG_lenght.TupleConcat(new HTuple(2 * leght1_rect2)); } if (DP_width == null || DP_width.Length == 0) { DP_width = new HTuple(2 * lenght2_rect2); } else { DP_width = DP_width.TupleConcat(new HTuple(2 * lenght2_rect2)); } if (LG_Area == null || LG_Area.Length == 0) { LG_Area = scan_region_temp.Area; } else { LG_Area = LG_Area.TupleConcat(scan_region_temp.Area); } row_temp = new HTuple(); column_temp = new HTuple(); angle_temp = new HTuple(); scale_temp = new HTuple(); score_temp = new HTuple(); //HRegion dilation_Diff = image.GetDomain().Difference(scan_region_temp.DilationCircle(10.0)); //HImage souce_image_temp = image.Clone(); //HImage paint_image = souce_image_temp.PaintRegion(dilation_Diff, new HTuple(10).TupleConcat(10).TupleConcat(10), "fill"); //HImage temp = paint_image.ReduceDomain(scan_region_temp.DilationCircle(10.0)); HImage temp = image.ReduceDomain(scan_region_temp.DilationCircle(10.0)); HImage guassImage = temp.GaussFilter(7); //HOperatorSet.SetSystem("thread_num", 4); HTuple t1; HOperatorSet.CountSeconds(out t1); try { createShapeModel.hShapeModel.FindScaledShapeModel( guassImage, createShapeModel.angleStart, createShapeModel.angleExtent, createShapeModel.scaleMin, createShapeModel.scaleMax, minScore, numMatches, maxOverlap, new HTuple(subPixel).TupleConcat("max_deformation 2"), new HTuple(new int[] { createShapeModel.numLevels, numLevels }), greediness, out row_temp, out column_temp, out angle_temp, out scale_temp, out score_temp); } catch { } HTuple t2; HOperatorSet.CountSeconds(out t2); double time = (t2 - t1).D * 1000; Util.Notify("每次模板匹配用时:" + time.ToString("F2") + "ms"); guassImage.Dispose(); temp.Dispose(); //souce_image_temp.Dispose(); //paint_image.Dispose(); //dilation_Diff.Dispose(); scan_region_temp.Dispose(); if (row_temp != null && row_temp.Length > 0) { if (row.Length == 0) { row = row_temp; column = column_temp; angle = angle_temp; scale = scale_temp; score = score_temp; } else { row = row.TupleConcat(row_temp); column = column.TupleConcat(column_temp); angle = angle.TupleConcat(angle_temp); scale = scale.TupleConcat(scale_temp); score = score.TupleConcat(score_temp); } } } searchImage.Dispose(); } catch { return(false); } return(true); }