该例程是blob识别的内容,目的是识别出图片中的硬币。
*blob识别 2020/03/04
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Image, 'C:/硬币5.jpg')
rgb1_to_gray (Image, GrayImage)
*中值滤波
median_image (GrayImage, ImageMedian, 'circle', 1, 'mirrored')
*均值滤波
mean_image (ImageMedian, ImageMean, 9, 9)
threshold (ImageMean, Regions, 0, 121)
*开运算(腐蚀)
opening_circle (Regions, RegionOpening, 3.5)
*腐蚀
erosion_circle (RegionOpening, RegionErosion, 2)
*孔洞填充(不指定面积)
fill_up (RegionErosion, RegionFillUp)
connection (Regions, ConnectedRegions)
*特征选择
select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [73028.7,0.8378], [81630.8,1])
*求面积 行列坐标
area_center (SelectedRegions, Area, Row, Column)
*文字显示:'window'指在窗口上显示,0,0指显示位置
disp_message (WindowHandle, '面积:'+Area+' 中心坐标:'+Row+','+Column, 'window', 0,0, 'blue', 'true')
代码书写的不是很标准啦,因为是我刚开始学的时候写的,看重要算子就行啦。
识别结果
原图