* 读取一张图像read_image ( Image, '原图.jpg' ) * 获取图像大小get_image_size ( Image, Width, Height) * 关闭已经打开的窗口dev_close_window ( ) * 打开新窗口dev_open_window ( 0 , 0 , Width, Height, 'black' , WindowHandle) * 对图像进行阈值操作threshold ( Image, Region, 0 , 50 ) * 对区域进行连通处理connection ( Region, ConnectedRegions) * 过滤出产品的外轮廓区域select_shape ( ConnectedRegions, SelectedRegions, 'ra' , 'and' , 10 , 200 ) * 对轮廓区域进行填充fill_up ( SelectedRegions, RegionFillUp) * 将区域转化为最小外接圆shape_trans ( SelectedRegions, RegionTrans, 'outer_circle' ) * 通过补集运算获取产品缺口区域difference ( RegionTrans, RegionFillUp, RegionDifference) * 对缺口区域进行腐蚀操作erosion_circle ( RegionDifference, RegionErosion, 1 ) * 把一个区域转变为一个二进制字节图像。region_to_bin ( RegionErosion, BinImage, 255 , 0 , 656 , 492 ) * 对图像进行阈值操作threshold ( BinImage, Region1, 255 , 255 ) * 对阈值区域连通处理connection ( Region1, ConnectedRegions1) * 设置输出对象显示颜色dev_set_color ( 'blue' ) * 过滤出想要的缺口区域select_shape ( ConnectedRegions1, SelectedRegions1, [ 'ra' , 'rb' ] , 'and' , [ 5 , 1 ] , [ 10 , 5 ] ) * 统计出缺口的数目count_obj ( SelectedRegions1, Number) * 显示图像dev_display ( Image) * 显示缺陷区域dev_display ( SelectedRegions1)