- *1.裁切roi
- read_image (Image1, './1.png')
- * read_image (Image1, 'C:/Users/Annan/Downloads/焊接/557.png')
- * read_image (Image1, 'C:/Users/Annan/Downloads/焊接/456.png')
- * read_image (Image1, 'C:/Users/Annan/Downloads/焊接/253.png')
- gen_circle (ROI_0, 273.938, 236.098, 165.243)
- area_center (ROI_0, Area, RowC, ColumnC)
- reduce_domain (Image1, ROI_0, ImageReduced)
- gen_cross_contour_xld (Cross, RowC, ColumnC, 36, 0.785398)
- dev_display (Image1)
- dev_set_draw ('margin')
- dev_display (Cross)
- dev_display (ROI_0)
- stop ()
- *2.预处理
- rgb1_to_gray (ImageReduced, GrayImage)
- mean_image (GrayImage, ImageMean, 12, 12)
- *3.动态阈值取边缘
- dyn_threshold (GrayImage, ImageMean, RegionDynThresh, 20, 'dark')
- connection (RegionDynThresh, ConnectedRegions2)
- select_shape (ConnectedRegions2, SelectedRegions, 'outer_radius', 'and', 30, 200)
- select_shape (SelectedRegions, SelectedRegions1, 'width', 'and', 10, 99999)
- union1 (SelectedRegions1, RegionUnion)
- *4.连接边缘
- dilation_circle (RegionUnion, RegionDilation, 3.5)
- *--------------方法1:blob------------------------
- skeleton (RegionDilation, Skeleton1)
- gen_contour_region_xld (Skeleton1, Contours1, 'center')
- select_obj (Contours1, ObjectSelected, 1)
- segment_contours_xld (ObjectSelected, ContoursSplit, 'lines_ellipses', 5, 4, 1)
- select_shape_xld (ContoursSplit, SelectedXLD1, ['circularity','area'], 'and', [0.24704,3792.88], [1,50000])
-
- fit_ellipse_contour_xld (SelectedXLD1, 'fhuber', -1, 0, 0, 200, 3, 2, \
- Row1, Column1, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
- gen_ellipse_contour_xld (ContEllipse, Row1, Column1, Phi, Radius1, Radius2, \
- StartPhi, EndPhi, PointOrder, 1.5)
- select_shape_xld (ContEllipse, SelectedXLD, 'area', 'and', 25658.8, 50000)
- select_obj (Contours1, ObjectSelected1, 2)
- fit_ellipse_contour_xld (ObjectSelected1, 'fhuber', -1, 0, 0, 200, 3, 2, \
- Row1, Column1, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
- gen_ellipse_contour_xld (ContEllipse1, Row1, Column1, Phi, Radius1, Radius2, \
- StartPhi, EndPhi, PointOrder, 1.5)
- *-----------------------------------------------------------------
-
- *--------------------------方法2---------------------------
- *5.展开坐标系 去除毛刺干扰
- area_center (RegionDilation, Area1, Row, Column)
- get_image_size (ImageReduced, Width, Height)
- OuterRadius:=200
- InnerRadius:=0
- polar_trans_region (RegionDilation, PolarTransRegion, Row, Column, 0, 6.28319, 0, OuterRadius, Width, Height, 'nearest_neighbor')
- opening_circle (PolarTransRegion, RegionOpening, 7)
- *6.逆变换
- polar_trans_region_inv (RegionOpening, XYTransRegion, Row, Column, 0, 6.28319, 0, OuterRadius, Width, Height, Width, Height, 'nearest_neighbor')
- *7.提取边缘区域骨架
- connection (XYTransRegion, ConnectedRegions)
- skeleton (ConnectedRegions, Skeleton)
- *8.区域转轮廓
- gen_contour_region_xld (Skeleton, Contours, 'center')
- *9.轮廓拟合椭圆
- fit_ellipse_contour_xld (Contours, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row1, Column1, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
- gen_ellipse (Ellipse, Row1, Column1, Phi, Radius1, Radius2)
- *8.筛选两个圆
- select_shape (Ellipse, SelectedRegions1, 'outer_radius', 'and', 95, 105)
- select_shape (Ellipse, SelectedRegions2, 'outer_radius', 'and', 70, 80)
- concat_obj (SelectedRegions1, SelectedRegions2, ObjectsConcat)
- *--------------------------------------------------------
- *9.求圆心并显示
- area_center (ObjectsConcat, Area2, Row2, Column2)
- gen_cross_contour_xld (Cross1, Row2, Column2, 36, 0.785398)
- dev_display (Image1)
- dev_set_draw ('margin')
- dev_display (ObjectsConcat)
- dev_display (Cross1)
复制代码 |