查看: 18|回复: 0

halcon 几何图形匹配(模板,模型匹配)

[复制链接]

255

主题

1

回帖

1300

积分

管理员

积分
1300
QQ
发表于 2025-7-10 06:58:27 | 显示全部楼层 |阅读模式
  1. gen_region_runs (ROI_0, [104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249], [163,160,156,153,150,146,143,140,136,133,130,126,123,120,116,113,110,106,103,101,101,102,102,102,103,103,103,104,104,105,105,105,106,106,106,107,107,107,108,108,108,109,109,109,110,110,110,111,111,112,112,112,113,113,113,114,114,114,115,115,115,116,116,116,117,117,117,118,118,119,119,119,120,120,120,121,121,121,122,122,122,123,123,123,124,124,124,125,125,126,126,126,127,127,127,128,128,130,132,134,136,138,140,143,145,147,149,151,153,156,158,160,162,164,166,169,171,173,175,177,179,181,184,186,188,190,192,194,197,199,201,203,205,207,210,212,214,216,218,220,223,225,227,229,231,233], [164,163,162,164,165,167,169,170,172,173,175,177,178,180,181,183,184,186,188,189,191,192,194,195,197,199,200,202,203,205,207,208,210,211,213,214,216,218,219,221,222,224,225,227,229,230,232,233,235,237,238,240,241,243,244,246,248,249,251,252,254,255,257,259,260,262,263,265,267,268,270,271,271,270,270,269,269,268,268,267,267,266,266,265,265,264,264,263,263,262,262,261,261,260,260,259,259,258,258,257,257,256,256,255,255,254,254,253,253,252,252,251,251,250,250,249,249,248,248,247,247,246,246,245,245,244,244,243,243,242,242,241,241,240,240,239,239,238,238,237,237,236,236,235,235,234])

  2. *平移

  3. hom_mat2d_identity (HomMat2DIdentity)

  4. hom_mat2d_translate (HomMat2DIdentity, 164, 164, HomMat2DTranslate)

  5. affine_trans_region (ROI_0, RegionAffineTrans, HomMat2DTranslate, 'nearest_neighbor')

  6. *缩放

  7. hom_mat2d_identity (HomMat2DIdentity1)

  8. area_center (ROI_0, Area, Row, Column)

  9. hom_mat2d_scale (HomMat2DIdentity1, 2, 2, Row, Column, HomMat2DScale)

  10. affine_trans_region (ROI_0, RegionAffineScale, HomMat2DScale, 'nearest_neighbor')

  11. *旋转
  12. hom_mat2d_identity (HomMat2DIdentity2)

  13. area_center (ROI_0, Area1, Row1, Column1)

  14. hom_mat2d_rotate (HomMat2DIdentity2, -0.78, Row1, Column1, HomMat2DRotate)

  15. affine_trans_region (ROI_0, RegionAffineRotate, HomMat2DRotate, 'nearest_neighbor')

复制代码
  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. vector_angle_to_rigid (0, 0, 0, RefRow, RefColumn, 0, HomMat2D)
  25. affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
  26. *
  27. * Matching 01: Display the model contours
  28. dev_display (Image)
  29. dev_set_color ('green')
  30. dev_set_draw ('margin')
  31. dev_display (ModelRegion)
  32. dev_display (TransContours)
  33. stop ()
  34. *
  35. * Matching 01: END of generated code for model initialization
  36. * Matching 01:  * * * * * * * * * * * * * * * * * * * * * * *
  37. * Matching 01: BEGIN of generated code for model application
  38. *
  39. * Matching 01: Loop over all specified test images
  40. TestImages := ['C:/Users/thinger.cn/Desktop/第5章:Halcon快速入门及联合编程/5.24 Halcon创建模板参数说明/套环/1.BMP']
  41. for T := 0 to 0 by 1
  42.     *
  43.     * Matching 01: Obtain the test image
  44.     read_image (Image, TestImages[T])
  45.     *
  46.     * Matching 01: Find the model
  47.     find_shape_model (Image, ModelID, rad(0), rad(360), 0.5, 0, 0.5, 'least_squares', [3,1], 0.75, Row, Column, Angle, Score)
  48.     *
  49.     * Matching 01: Transform the model contours into the detected positions
  50.     dev_display (Image)
  51.     for I := 0 to |Score| - 1 by 1
  52.         hom_mat2d_identity (HomMat2D)
  53.         hom_mat2d_rotate (HomMat2D, Angle[I],0,0, HomMat2D)
  54.         hom_mat2d_translate (HomMat2D, Row[I], Column[I], HomMat2D)
  55.         
  56.         vector_angle_to_rigid (0, 0, 0, Row[I], Column[I], Angle[I], HomMat2D1)
  57.         
  58.   
  59.         affine_trans_contour_xld (ModelContours, TransContours, HomMat2D1)
  60.         dev_set_color ('green')
  61.         dev_display (TransContours)
  62.         stop ()
  63.     endfor
  64. endfor
  65. *
  66. * Matching 01: *******************************************
  67. * Matching 01: END of generated code for model application
  68. * Matching 01: *******************************************
  69. *
复制代码


高级模式
B Color Image Link Quote Code Smilies

本版积分规则

关于我们

企业文化

人才招聘

常见问题

建议反馈

合作伙伴

商务合作

新闻媒体

产品服务

客户案例

联系我们

联系电话:14776878570(同VX号)

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

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

关注微信公众号

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

GMT+8, 2025-8-6 00:50 , Processed in 0.064164 second(s), 18 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.