博主写作不容易,孩子需要您鼓励 万水千山总是情 , 先点个赞行不行
处理要求
查找圆环缺陷
处理源码
read_image ( Image , 'F:/HALCON/圆环划痕处理/10_33221_ba4582f0e88ec79.bmp' )
rgb3_to_gray ( Image , Image , Image , ImageGray )
dev_close_window ( )
dev_open_window_fit_image ( ImageGray , 0 , 0 , - 1 , - 1 , WindowHandle )
get_image_size ( ImageGray , Width , Height )
auto_threshold ( ImageGray , Regions , 2 )
select_obj ( Regions , ObjectSelected , 1 )
complement ( ObjectSelected , RegionComplement )
fill_up ( RegionComplement , RegionFillUp )
difference ( RegionFillUp , RegionComplement , RegionDifference )
smallest_circle ( RegionDifference , Row , Column , RadiusIn )
boundary ( RegionFillUp , RegionBorder , 'outer' )
dilation_circle ( RegionBorder , RegionDilation , 3.5 )
reduce_domain ( ImageGray , RegionDilation , ImageReduced )
edges_sub_pix ( ImageReduced , Edges , 'canny' , 0.5 , 20 , 40 )
segment_contours_xld ( Edges , ContoursSplit , 'lines_circles' , 5 , 4 , 2 )
union_cocircular_contours_xld ( ContoursSplit , UnionContours , 0.9 , 0.5 , 0.5 , 200 , 50 , 50 , 'true' , 1 )
length_xld ( UnionContours , Length )
select_obj ( UnionContours , LongestContour , sort_index ( Length ) [ | Length | - 1 ] + 1 )
fit_circle_contour_xld ( LongestContour , 'algebraic' , - 1 , 0 , 0 , 3 , 2 , Row1 , Column1 , RadiusOUT , StartPhi , EndPhi , PointOrder )
gen_circle ( Circle , Row1 , Column1 , RadiusOUT )
dilation_circle ( Circle , RegionDilation , 5 )
erosion_circle ( Circle , RegionErosion , RadiusOUT-RadiusIn + 5 )
difference ( RegionDilation , RegionErosion , RegionDifference1 )
erosion_circle ( RegionDifference1 , RegionErosion1 , 8 )
reduce_domain ( ImageGray , RegionDifference1 , ImageReduced1 )
polar_trans_image_ext ( ImageReduced1 , PolarTransImage , Row1 , Column1 , 0 , rad ( 360 ) , RadiusIn , RadiusOUT , 6.28 * RadiusOUT , RadiusOUT-RadiusIn , 'nearest_neighbor' )
dev_open_window_fit_image ( PolarTransImage , 0 , 0 , - 1 , - 1 , WindowHandle1 )
mean_image ( PolarTransImage , ImageMean , 100 , 3 )
dyn_threshold ( PolarTransImage , ImageMean , RegionDynThresh , 10 , 'dark' )
connection ( RegionDynThresh , ConnectedRegions )
select_shape ( ConnectedRegions , SelectedRegions , 'area' , 'and' , 5 , 99999 )
polar_trans_region_inv ( SelectedRegions , XYTransRegion , Row1 , Column1 , 0 , rad ( 360 ) , RadiusIn , RadiusOUT , 6.28 * RadiusOUT , RadiusOUT-RadiusIn , Width , Height , 'nearest_neighbor' )
intersection ( RegionErosion1 , XYTransRegion , RegionIntersection )
dev_set_window ( WindowHandle )
dev_display ( ImageGray )
dev_display ( RegionIntersection )
处理效果
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 分割线
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
博主简介: 工业自动化上位机软件工程师、机器视觉算法工程师、运动控制算法工程师。目前从业于智能制造自动化行业。 博主邮箱:2296776525@qq.com