设置首页收藏本站
开启左侧

halcon 给图片下方添加信息栏技巧

[复制链接]
HappySaturday 发表于 2025-4-22 17:30:56 | 显示全部楼层 |阅读模式
处理显微镜图片时,有时候会需要在图片下方添加信息栏,标注图片的名字,比例尺,放大倍率等。
可将信息栏生成为一张与原图等宽的图片高度为原图10%的图片,在上面显示文字,使用dump_window_image截取信息栏图像。
使用图片拼接的方式将原图和信息栏拼接在一起。可使用算子tile_images_offset拼接图片。
  1. read_image (Image0, 'Test.png')
  2. Filename:='Test'
  3. Scale:=100
  4. Resolution:=0.175
  5. RulerInUm:=20
  6. *生成信息栏
  7. get_image_size (Image0, Width, Height)
  8. gen_image_const (NullImage, 'byte', Width, Height/10.0)
  9. get_image_size (NullImage, Width2, Height2)
  10. paint_region (NullImage, NullImage, NullImage, 255, 'fill')

  11. *生成比例尺
  12. gen_rectangle2 (Rectangle,Height2/2.0, Width2/2.0, 0, RulerInUm/Resolution, Height2/50.0)
  13. paint_region (Rectangle, NullImage, NullImage, 0, 'fill')

  14. *显示文本
  15. dev_open_window (0, 0, Width2, Height2, 'black', WindowHandle)
  16. dev_set_part (0, 0, Height2-1, Width2-1)
  17. dev_display (NullImage)
  18. FontSize:=Height2/4.0
  19. set_display_font (WindowHandle, FontSize, 'mono', 'true', 'false')
  20. set_tposition (WindowHandle, 0, 0)
  21. dev_disp_text (Filename, 'window', 'center', 'left', 'black', 'box', 'false')
  22. dev_disp_text (Scale+'x', 'window', 'center', 'right', 'black', 'box', 'false')
  23. dev_disp_text (RulerInUm+' um', 'window', 'top', 'center', 'black', 'box', 'false')

  24. *截取文字图像
  25. dump_window_image (DumpImage, WindowHandle)
  26. rgb1_to_gray (DumpImage, GrayImage)
  27. dev_close_window ()

  28. *把信息栏加进去
  29. concat_obj (Image0, GrayImage, imgs)
  30. tile_images_offset (imgs, TiledImage, [0, Height], [0,0], [-1,-1], [-1,-1], [-1,-1], [-1,-1], Width, Height *1.1)
  31. dev_display (TiledImage)
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
gungun 发表于 2025-4-23 08:09:06 | 显示全部楼层
很聪明的想法,赞赞赞赞赞
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表