halcon 3焊点查找
dev_update_off ()
imageList := 'die/' + ['die_02','die_03','die_04','die_07']
* 设置显示颜色
dev_set_colored (12)
* 读取一张图片获取尺寸显示
read_image (Image, imageList[0])
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* 设置字体
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
* 设置描边 描边宽度
dev_set_draw ('margin')
dev_set_line_width (3)
* 获取图片数量显示
* =======自己写的=========
ImageNum := |imageList|
for Index := 0 to ImageNum-1 by 1
* 读取图片
read_image (first_image,imageList[Index])
dev_display (first_image)
* 获取最大和最小灰度值 Range是最大和最小的差
min_max_gray (first_image, first_image, 0, Min, Max, Range)
* 二值化得到白色区域然后区域转换为长方形 这里的最大max就是我们需要的区域
threshold (first_image, whiteOut_threshold_region, Max-80, 255)
shape_trans (whiteOut_threshold_region, white_trans_rectangle, 'rectangle2')
dev_display (white_trans_rectangle)
* 步步逼近
reduce_domain (first_image, white_trans_rectangle, white_out_reduce_domain)
* 获取最大与最小灰度值
min_max_gray (white_trans_rectangle, white_out_reduce_domain, 0, Min1, Max1, Range1)
* 二值化获取黑色部分
threshold (white_out_reduce_domain, black_threshold_region, 0, Min1+30)
* 填充漏点
fill_up (black_threshold_region, black_fill_up_region)
* 开运算去除周边
opening_circle (black_fill_up_region, balck_opening_region, 10)
* 打散去除其他影响的黑色区域
connection (balck_opening_region, black_connection_regions)
* 使用圆度或者最小外接圆半径去除
* select_shape (black_connection_regions, black_select_region, 'outer_radius', 'and', 28, 99999)
select_shape_std (black_connection_regions, black_select_region, 'max_area', 90)
* 这里巩固知识复杂点 用差集得到
difference (black_connection_regions, black_select_region, black_region_result)
* demo使用了expand_gray 扩展灰度 我们这里用下膨胀就行了 然后用开运算计算就行
dilation_circle (black_region_result, result_dilation_region, 1)
opening_circle (result_dilation_region, result_opening_region, 15.5)
* 排序
sort_region (result_opening_region, result_sort_region, 'first_point', 'true', 'row')
* 画好看点 得到最小外接矩形
smallest_circle (result_sort_region, Row, Column, Radius)
gen_circle (Circle, Row, Column, Radius)
* 个数
ballNumber := |Radius|
* 直径
Diameter := 2*Radius
* 最小直径
mimDiameter := min(Diameter)
* 平均直径
meanDiameter := mean(mimDiameter)
* 判断如果图片是否读完
if (Index !=ImageNum)
disp_continue_message (WindowHandle, 'black', 'true')
endif
endfor
吾虽浪迹,却未迷失本心