查看: 16|回复: 0

halcon 几何定位实现跟随效果

[复制链接]

255

主题

1

回帖

1300

积分

管理员

积分
1300
QQ
发表于 2025-7-12 17:08:29 | 显示全部楼层 |阅读模式
  1. *几何定位加仿射变换的联合应用

  2. *读取图像
  3. read_image (Image, '图片/1-1.bmp')

  4. *绘制圆和矩形
  5. gen_circle (Circle, 621.442, 867.321, 60.3191)
  6. gen_rectangle2 (Rectangle, 202.659, 391.7, rad(12.5414), 91.8371, 23.2433)

  7. *创建模板区域
  8. gen_rectangle2 (ModelRegion, 329.79, 653.167, rad(31.9349), 155.516, 153.043)

  9. *减小定义域
  10. reduce_domain (Image, ModelRegion, ImageReduced)

  11. *创建模板
  12. create_shape_model (ImageReduced, 'auto', rad(-90), rad(180), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)

  13. *获取模板轮廓
  14. get_shape_model_contours (ModelContours, ModelID, 1)

  15. *获取模板中心
  16. area_center (ModelRegion, Area, Row, Column)

  17. *显示模板轮廓
  18. dev_display_shape_matching_results (ModelID, 'red', Row, Column, 0, 1, 1, 0)

  19. * Image Acquisition 01: Code generated by Image Acquisition 01
  20. list_files ('图片', ['files','follow_links'], ImageFiles)
  21. tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
  22. for Index := 0 to |ImageFiles| - 1 by 1
  23.     read_image (Image, ImageFiles[Index])
  24.    
  25.     *查找模板
  26.     find_shape_model (Image, ModelID,  rad(-90), rad(180), 0.8, 1, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle, Score)
  27.    
  28.     *计算仿射变换矩阵
  29.     vector_angle_to_rigid (Row, Column, 0, Row1, Column1, Angle, HomMat2D)
  30.      
  31.      affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2D)

  32.     *显示模板匹配结果
  33.     dev_display_shape_matching_results (ModelID, 'red', Row1, Column1, Angle, 1, 1, 0)
  34.    
  35.     *实现跟随
  36.     affine_trans_region (Circle, RegionAffineTrans1, HomMat2D, 'nearest_neighbor')
  37.     affine_trans_region (Rectangle, RegionAffineTrans2, HomMat2D, 'nearest_neighbor')

  38. *显示跟随
  39.      dev_display (RegionAffineTrans1)
  40.      dev_display (RegionAffineTrans2)
  41.    
  42.     stop ()     
  43. endfor
复制代码


图片.zip

1.03 MB, 下载次数: 8

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

关于我们

企业文化

人才招聘

常见问题

建议反馈

合作伙伴

商务合作

新闻媒体

产品服务

客户案例

联系我们

联系电话:14776878570(同VX号)

邮箱:14776878570@163.com(同VX号)

工作时间:周一至周六(早上8点至下午10点)

关注微信公众号

QQ|Archiver|手机版|小黑屋|鸿翔机器人

GMT+8, 2025-8-6 00:48 , Processed in 0.064784 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.