Halcon每日一练

## 寻找工件坐标

要求:

找到六边形螺母的角点坐标并输出

图片

在这里插入图片描述

*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

效果

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

火星wen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值