halcon 获取轮廓

*读取图片
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 650, 485, 'black', WindowHandle)
read_image (Image, './3.bmp')
get_image_size (Image, Width, Height)
dev_set_part (0, 0, Height-1, Width-1)
binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
fill_up_shape (Region, RegionFillUp, 'area', 1, 7000)
closing_circle (RegionFillUp, RegionClosing, 10.5)
boundary (RegionClosing, RegionBorder, 'inner')
gen_contour_region_xld (RegionBorder, Contours, 'border')
*提取亚像素精密边缘轮廓
* edges_sub_pix (Image, Edges, 'canny', 2, 20, 60)
*将一个XLD轮廓分割为直线段、圆(圆弧)、椭圆弧
segment_contours_xld (Contours, ContoursSplit, 'lines_circles', 5, 10, 20)
*计算个数
count_obj (ContoursSplit, Number)
dev_set_line_width (2)
dev_display (Image)
dev_display (ContoursSplit)

*写入轮廓点数据
open_file ('轮廓数据.txt', 'append', FileHandle)
for I := 1 to Number by 1
    corx := []
    cory := []
    *选择一个元素
    select_obj (ContoursSplit, ObjectSelected, I)
    length_xld(ObjectSelected, len)
    *获取轮廓点的个数
    contour_point_num_xld(ObjectSelected, num_1)
    *获取轮廓点坐标
    get_contour_xld(ObjectSelected, Row1, Col1)
    
    fwrite_string (FileHandle, '轮廓'+I+'      长度:'+len+'     轮廓点的个数:'+num_1)
    fnew_line (FileHandle)
    fwrite_string (FileHandle, '轮廓点坐标如下:')
    fnew_line (FileHandle)
    fwrite_string (FileHandle, 'Row'+Row1+'   Col'+Col1+'\n')
endfor

close_file (FileHandle)
dev_disp_text ('轮廓数据写入成功!', 'window', 12, 12, 'black', [], [])

posted on   qq1151219115  阅读(375)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示