halcon脚本-边缘及骨架的识别【附源码】


前言

本文实现基于图像进行边缘或者骨架的识别,可实现让机器人画画


一、原图

1.边缘图

在这里插入图片描述

2.骨架图

在这里插入图片描述


二、实现思路

1.边缘图

  • 提取边缘算子,edges_sub_pix
  • 二值化获取区域
  • 根据xld区域获取点

2.骨架图

  • 首先对图像进行二值化,区域筛选出需要的位置
  • 使用skeleton算子把区域变成了线条
  • 使用gen_contours_skeleton_xld算子把整个区域线条变成话比xld
  • 使用get_polygon_xld获取坐标

三、halcon脚本实现

1.边缘图

read_image (image, '1.jpg')   //读取图像
edges_sub_pix (image, Edges, 'canny', 1, 5, 40)
binary_threshold (image, Region, 'max_separability', 'dark', UsedThreshold)
gen_contour_region_xld (Region, Contours, 'border_holes')
gen_region_contour_xld(Contours,a,'margin')
union_cotangential_contours_xld (Contours, UnionContours1, 0, 30, 0.785398, 25, 10, 2, 'attr_forget')
count_obj (UnionContours1, Number1)
union_adjacent_contours_xld (Contours, UnionContours2, 10, 1, 'attr_keep')
count_obj (UnionContours2, Number2)
sort_contours_xld (Contours, SortedContours, 'upper_left', 'true', 'column')
count_obj (SortedContours, Number)
for Index := 1 to Number by 1
    select_obj (SortedContours, ObjectSelected, Index)
     *gen_region_contour_xld (ObjectSelected, Region1, 'filled')
     *get_region_points (Region1, Rows, Columns)
    gen_polygons_xld (ObjectSelected, Polygons, 'ramer', 1)
    get_polygon_xld (Polygons, Row, Col, Length, Phi)
    *stop ()
endfor

2.骨架图

read_image (Writing, '1.png')
binary_threshold (Writing, Region, 'max_separability', 'dark', UsedThreshold)
select_shape (Region, SelectedRegions, 'area', 'and', 20, 99999999)
skeleton (SelectedRegions, Skeleton)
gen_contours_skeleton_xld (Skeleton, Contours, 1, 'filter')
union_cotangential_contours_xld (Contours, UnionContours1, 0, 30, 0.785398, 25, 10, 2, 'attr_forget')
count_obj (UnionContours1, Number1)
union_adjacent_contours_xld (Contours, UnionContours2, 10, 1, 'attr_keep')
count_obj (UnionContours2, Number2)
sort_contours_xld (Contours, SortedContours, 'upper_left', 'true', 'column')
dev_clear_window ()
count_obj (SortedContours, Number)
for Index := 1 to Number by 1
    select_obj (SortedContours, ObjectSelected, Index)
    gen_polygons_xld (ObjectSelected, Polygons, 'ramer', 2)
    get_polygon_xld (Polygons, Row, Col, Length, Phi)
*    stop ()
endfor

四、实现效果

1.边缘图

在这里插入图片描述
从颜色上可区分出这里绘制需要4笔,
数据在变量:Row, Col, Length, Phi
如图:
在这里插入图片描述

2.骨架图

在这里插入图片描述
数据在变量:Row, Col, Length, Phi
如图:
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

爱学习的广东仔

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

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

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

打赏作者

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

抵扣说明:

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

余额充值