项目需求:
此项目halcon检测钢珠的个数,并显示。
素材如下:
代码如下:
read_image (Image4, '扩视4.bmp') *********关闭窗口*********** dev_close_window () *********打开窗口*********** dev_open_window (0, 0, 900, 512, 'black', WindowHandle) *********显示原图*********** dev_display (Image4) *********设置字体大小*********** set_display_font (WindowHandle, 30, 'mono', 'true', 'false') *********二值化*********** binary_threshold (Image4, Region, 'max_separability', 'light', UsedThreshold) *********闭运算*********** closing_circle (Region, RegionClosing, 250.5) *********开运算*********** opening_circle (RegionClosing, RegionOpening, 100.5) *********测量圆的尺寸*********** smallest_circle (RegionOpening, Row, Column, Radius) *********生成一个圆*********** gen_circle (Circle, Row, Column, Radius) *********抠图*********** reduce_domain (Image4, Circle, ImageReduced) *********再二值化*********** binary_threshold (ImageReduced, Region1, \ 'max_separability', 'dark', UsedThreshold1) *********开运算*********** opening_circle (Region1, RegionOpening1, 103.5) *********断开*********** connection (RegionOpening1, ConnectedRegions) *********变形*********** shape_trans (ConnectedRegions, RegionTrans, 'inner_circle') dev_display (Image4) dev_display (RegionTrans) count_obj (RegionTrans, Number) disp_message (WindowHandle,'个数:'+ Number, 'Image4', 100, 100, 'green', 'false')
详细视频如下:
https://www.bilibili.com/video/BV1BQ4y1R71c?p=23
标签:48,RegionTrans,dev,Halcon,视觉,circle,扩视,display,Image4 From: https://www.cnblogs.com/DongGeVision/p/17233847.html