首先看看要使用的图像(这是闲着无聊在halcon网上找的一张实际生产中的图):
read_image (Image, 'C:/Users/斌/Desktop/halcon-项目/颗粒/9_13810_03cee492a78b870.bmp') binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold) connection (Region, ConnectedRegions) *拿到其中一粒创建模板 select_obj (ConnectedRegions, ObjectSelected, 2) reduce_domain (Image, ObjectSelected, ImageReduced) create_ncc_model (ImageReduced, 'auto', rad(-180), rad(180), 'auto', 'use_polarity', ModelID) *匹配模板 find_ncc_model (Image, ModelID, rad(-180), rad(180), 0.6, 0, 0.5, 'true', 1, Row, Column, Angle, Score) clear_ncc_model (ModelID) gen_cross_contour_xld (Cross, Row, Column, 16, Angle) dev_clear_window () dev_display (Image) dev_display (Cross)
效果(注意,这里只识别了大颗粒没有识别小颗粒,若要继续识别小颗粒需另建模板):
其它一些关于粘连处理的贴子:
HALCON图像处理的粘连零件颗粒计数 http://47.98.154.65/?id=78
粘合度高的物体识别 http://47.98.154.65/?id=1449
halcon Blob分析--粘连颗粒检测 http://47.98.154.65/?id=1495
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


