halcon选择图像中的物件最大外轮廓的通用办法
By
admin
at 2018-05-29 • 0人收藏 • 3994人看过
read_image (Tim20180528230437, 'C:/Users/popdes/Desktop/TIM图片20180528230437.jpg') *转化为灰度图 rgb3_to_gray (Tim20180528230437, Tim20180528230437, Tim20180528230437, ImageGray) *模糊图像 mean_image (ImageGray, ImageMean, 9, 9) *动态阈值处理 auto_threshold (ImageMean, Regions, 2) *排除其他干扰小面积 select_shape (Regions, SelectedRegions, 'area', 'and', 688.44, 16727.9) *分割图像区域 connection (SelectedRegions, ConnectedRegions) *再次筛选 select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 199.64, 20000) *填充所选区域 fill_up_shape (SelectedRegions1, RegionFillUp, 'area', 1, 1000000) *计算每个区域的面积(我只需要面积一项) area_center (RegionFillUp, Area, Row, Column) *对面积进行排序,后面的Indices保存的是面积对应的区域编号 tuple_sort_index (Area, Indices) *计算区域数量 count_obj (RegionFillUp, Number) *选中最大那个面积的区域 *这里写法请参考https://www.cnblogs.com/xh6300/p/6417801.html?utm_source=itdadao&utm_medium=referral select_obj (RegionFillUp, ObjectSelected, Indices[Number-1]+1) *计算外边界 boundary (ObjectSelected, RegionBorder1, 'outer') *设置为ROI区域,并截取 reduce_domain (ImageMean, RegionBorder1, ImageReduced)
登录后方可回帖