查看: 17|回复: 0

halcon 模版匹配

[复制链接]

255

主题

1

回帖

1300

积分

管理员

积分
1300
QQ
发表于 2025-7-12 12:22:04 | 显示全部楼层 |阅读模式
  1. *
  2. * Matching 01: ************************************************
  3. * Matching 01: BEGIN of generated code for model initialization
  4. * Matching 01: ************************************************
  5. set_system ('border_shape_models', 'false')
  6. *
  7. * Matching 01: Obtain the model image
  8. read_image (Image, 'C:/Users/thinger.cn/Desktop/第5章:Halcon快速入门及联合编程/5.24 Halcon创建模板参数说明/套环/1.BMP')
  9. *
  10. * Matching 01: Build the ROI from basic regions
  11. gen_circle (ModelRegion, 233.558, 483.037, 35.9314)
  12. *
  13. * Matching 01: Reduce the model template
  14. reduce_domain (Image, ModelRegion, TemplateImage)
  15. *
  16. * Matching 01: Create the shape model
  17. create_shape_model (TemplateImage, 3, rad(0), rad(360), rad(3.4478), ['none','no_pregeneration'], 'use_polarity', [10,11,4], 4, ModelID)
  18. *
  19. * Matching 01: Get the model contour for transforming it later into the image
  20. get_shape_model_contours (ModelContours, ModelID, 1)
  21. *
  22. * Matching 01: Get the reference position
  23. area_center (ModelRegion, ModelRegionArea, RefRow, RefColumn)


  24. *输出仿射变换矩阵  原始点X  原始点Y  原始点A   目标点X  目标点Y  目标点A  支持平移和旋转
  25. vector_angle_to_rigid (0, 0, 0, RefRow, RefColumn, 0, HomMat2D)

  26. *对Xld进行仿射变换
  27. affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
  28. *
  29. * Matching 01: Display the model contours
  30. dev_display (Image)
  31. dev_set_color ('green')
  32. dev_set_draw ('margin')
  33. dev_display (ModelRegion)
  34. dev_display (TransContours)
  35. stop ()
  36. *
  37. * Matching 01: END of generated code for model initialization
  38. * Matching 01:  * * * * * * * * * * * * * * * * * * * * * * *
  39. * Matching 01: BEGIN of generated code for model application
  40. *
  41. * Matching 01: Loop over all specified test images
  42. TestImages := ['C:/Users/thinger.cn/Desktop/第5章:Halcon快速入门及联合编程/5.24 Halcon创建模板参数说明/套环/1.BMP']
  43. for T := 0 to 0 by 1
  44.     *
  45.     * Matching 01: Obtain the test image
  46.     read_image (Image, TestImages[T])
  47.     *
  48.     * Matching 01: Find the model
  49.     find_shape_model (Image, ModelID, rad(0), rad(360), 0.5, 27, 0.5, 'least_squares', [3,1], 0.75, Row, Column, Angle, Score)
  50.    
  51.    
  52.     *
  53.     * Matching 01: Transform the model contours into the detected positions
  54.     dev_display (Image)
  55.     for I := 0 to |Score| - 1 by 1
  56.         
  57.         *生成一个单元矩阵
  58.        * hom_mat2d_identity (HomMat2D)
  59.         *旋转
  60.        * hom_mat2d_rotate (HomMat2D, Angle[I], 0, 0, HomMat2D)
  61.         *平移
  62.         *hom_mat2d_translate (HomMat2D, Row[I], Column[I], HomMat2D)
  63.         
  64.         *输出仿射变换矩阵  原始点X  原始点Y  原始点A   目标点X  目标点Y  目标点A  支持平移和旋转
  65.         vector_angle_to_rigid (0, 0, 0, Row[I], Column[I], Angle[I], HomMat2D)
  66.         
  67.         
  68.         *对xld仿射变换      
  69.         affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
  70.         
  71.         dev_set_color ('green')
  72.         dev_display (TransContours)
  73.         stop ()
  74.     endfor
  75. endfor
  76. *
  77. * Matching 01: *******************************************
  78. * Matching 01: END of generated code for model application
  79. * Matching 01: *******************************************
  80. *

  81. *输出仿射变换矩阵  至少2个点   刚性仿射变换矩阵,支持旋转和平移
  82. vector_to_rigid (Column, Row, Column, Row, HomMat2D1)

  83. *柔性仿射变换矩阵,支持旋转和平移和缩放
  84. vector_to_similarity (Column, Row, Column, Row, HomMat2D2)

  85. *输出仿射变换矩阵  至少3个点   支持旋转和平移和缩放和斜切
  86. vector_to_hom_mat2d (Column, Row, Column, Row, HomMat2D3)

  87. *旋转 平移  缩放  斜切

  88. *仿射变换流程

  89. *1、获取特征点  坐标  角度

  90. *2、调用算子生成仿射变换矩阵

  91. *3、对图像、区域、Xld进行仿射变换
复制代码


高级模式
B Color Image Link Quote Code Smilies

本版积分规则

关于我们

企业文化

人才招聘

常见问题

建议反馈

合作伙伴

商务合作

新闻媒体

产品服务

客户案例

联系我们

联系电话:14776878570(同VX号)

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

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

关注微信公众号

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

GMT+8, 2025-8-6 00:51 , Processed in 0.059926 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.