## 寻找工件坐标
要求:
找到六边形螺母的角点坐标并输出
图片
*version1.0
*function:找到工件的六个角点坐标并输出在窗口中
dev_update_off ()
dev_close_window ()
threshold_min:=150
threshold_max:=255
read_image (Image, 'F:/halcon学习/学习-halcon/1-算法入门作业培训阶段1/8/原图.bmp')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
rgb1_to_gray (Image, GrayImage)
dev_display (GrayImage)
*阈值分隔
threshold (GrayImage, Region, threshold_min, threshold_max)
*形态学和特征提取等操作
connection (Region, ConnectedRegions)
fill_up (ConnectedRegions, RegionFillUp)
select_shape (ConnectedRegions, SelectedRegions, ['area','anisometry'], 'and', [10000,1], [20000,2])
fill_up (SelectedRegions, RegionFillUp1)
*提取区域轮廓
gen_contour_region_xld (RegionFillUp1, Contours, 'border')
*分割轮廓(只用到直线)
segment_contours_xld (Contours, ContoursSplit, 'lines', 5, 4, 2)
*拟合直线
fit_line_contour_xld (ContoursSplit, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
count_obj (ContoursSplit, Number)
stop()
*显示顶点结果
for Index := 1 to Number by 1
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
disp_message (WindowHandle, '第'+Index+'个角点的坐标 :'+'ROW='+RowBegin[Index-1]+' ' +'COL='+ColBegin[Index-1], 'window', 10+30*[Index-1], 10, 'black', 'true')
if (Index>Number-1)
break
endif
endfor