当前位置: 首页 > news >正文

Halcon 2D测量Metrology找线/圆/矩形/椭圆

       通过2D测量,可以获取物体的范围、方向、角度、位置、尺寸和个数等特征。其中,Halcon的2D Metrology模块提供了亚像素级别的卡尺测量功能,可以测量的几何形状包括直线、圆、椭圆、矩形等。对于2D度量,必须提供要测量的对象的位置,方向和几何形状的近似值。在显示对象的图像内,这些近似对象的边界用于定位对象的真实边缘以适应几何形状的参数,使得它们最佳地适合图像数据。测量结果是优化的参数。计量模型用于存储所有必要的信息,例如计量对象的位置和几何形状的初始参数,控制测量的参数以及测量结果。

     测量流程:

     创建模型:create_metrology_model
     设置图像大小:set_metrology_model_image_size
     添加测量模型:add_metrology_object_generic

                             add_metrology_object_rectangle2_measure

                             add_metrology_object_line_measure

                             add_metrology_object_circle_measure

                             add_metrology_object_ellipse_measure
     设置对象参数:set_metrology_object_param
     设置模型参数:set_metrology_model_param
     对齐测量模型:align_metrology_model
     应用测量模型:apply_metrology_model
     获取结果:get_metrology_object_result
     显示结果:get_metrology_object_result_contour、get_metrology_object_measures


代码案例

1):找线

read_image (Image, 'E:/数据/测量程序/找线找点/图片/33.bmp')
dev_set_draw('margin')
dev_set_line_width (1)
get_image_size (Image, Width, Height)
create_metrology_model (MetrologyHandle)
set_metrology_model_image_size (MetrologyHandle, Width, Height)
add_metrology_object_line_measure (MetrologyHandle, 69.1489, 137.685, 69.8938, 395.477,40, 10, 0.4, 20, [], [], Index1)
set_metrology_object_param (MetrologyHandle, 'all', 'measure_transition', 'negative')
set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'first')
set_metrology_object_param (MetrologyHandle, 'all', 'num_measures', 8)
dev_set_color ('blue')
apply_metrology_model (Image, MetrologyHandle)
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row, Column)
gen_contour_polygon_xld (Contour, Row, Column)
fit_line_contour_xld (Contour, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
gen_contour_polygon_xld (Contourline, [RowBegin,  RowEnd], [ColBegin,ColEnd])

2):找圆

    create_metrology_model (MetrologyHandle)set_metrology_model_image_size (MetrologyHandle, Width, Height)add_metrology_object_generic (MetrologyHandle, 'circle', [197, 778, 113.146], 30, 10, 0.4, 30, [], [], Index)set_metrology_object_param (MetrologyHandle, 'all', 'measure_transition', 'positive')set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'first')set_metrology_object_param (MetrologyHandle, 'all', 'num_measures', 15)dev_set_color ('blue')apply_metrology_model (Image, MetrologyHandle)get_metrology_object_measures (Contours1, MetrologyHandle, 'all', 'all', Row, Column)gen_contour_polygon_xld (Contour1, Row, Column)fit_circle_contour_xld (Contour1, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius, StartPhi, EndPhi, PointOrder)gen_circle_contour_xld (ContCircle, Row1, Column1, Radius, 0, 6.28, 'positive', 3)

3):找矩形

    create_metrology_model (MetrologyHandle)set_metrology_model_image_size (MetrologyHandle, Width, Height)add_metrology_object_generic (MetrologyHandle, 'rectangle2', [408.304, 273.611, rad(-0), 164, 129], 30, 10, 0.4, 20, [], [], Index)set_metrology_object_param (MetrologyHandle, 'all', 'measure_transition', 'positive')set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'first')set_metrology_object_param (MetrologyHandle, 'all', 'num_measures', 20)dev_set_color ('blue')apply_metrology_model (Image, MetrologyHandle)get_metrology_object_measures (Contours2, MetrologyHandle, 'all', 'all', Row, Column)gen_contour_polygon_xld (Contour2, Row, Column)fit_rectangle2_contour_xld (Contour2, 'regression', -1, 0, 0, 3, 2, Row2, Column2, Phi, Length1, Length2, PointOrder1)gen_rectangle2_contour_xld (Rectangle, Row2, Column2, Phi, Length1, Length2)

4):找椭圆   

    create_metrology_model (MetrologyHandle)set_metrology_model_image_size (MetrologyHandle, Width, Height)add_metrology_object_generic (MetrologyHandle, 'ellipse', [551.304, 772.611, rad(-90), 161, 90], 30, 10, 0.4, 20, [], [], Index)set_metrology_object_param (MetrologyHandle, 'all', 'measure_transition', 'positive')set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'first')set_metrology_object_param (MetrologyHandle, 'all', 'num_measures', 20)dev_set_color ('blue')apply_metrology_model (Image, MetrologyHandle)get_metrology_object_measures (Contours3, MetrologyHandle, 'all', 'all', Row, Column)gen_contour_polygon_xld (Contour3, Row, Column)fit_ellipse_contour_xld (Contour3, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row3, Column3, Phi1, Radius1, Radius2, StartPhi1, EndPhi1, PointOrder2)gen_ellipse_contour_xld (ContEllipse, Row3, Column3, Phi1, Radius1, Radius2, 0, 6.28, 'positive', 1.5)

            


http://www.mrgr.cn/news/63212.html

相关文章:

  • 性能测试|linux服务器搭建JMeter+Grafana+Influxdb监控可视化平台
  • C#入坑JAVA MyBatis入门 CURD 批量 联表分页查询
  • TDengine数据备份与恢复
  • 计算机系统结构为什么用architecture 而不是structure?
  • aab上架谷歌市场流程(apk)
  • Rust 力扣 - 643. 子数组最大平均数 I
  • Git进阶(十七):特性分支
  • 用二维码展示信息,有哪些常见应用场景
  • Idea常用插件
  • 2025 年IT技术人员关键技能(非常详细),零基础入门到精通,看这一篇就够了
  • Go使用SIMD指令——以string转为整数为例
  • netty之bootstrap源码分析
  • Android 中选择本地文件并获取文件路径
  • BC1 2充电协议简介
  • JS进阶级案例-----时钟
  • Python零基础 [2.3] if else 语句的详解与示例
  • 《PHP爬虫:当“购物狂”遇上“代码诗人”》
  • 算子级血缘助企业数据管理“自动化、精细化、智能化”
  • Redis 中的定期删除和惰性删除究竟是怎样实现的?
  • flutter报错‘/Users/xxx/.gradle/caches/journal-1/file-access.bin‘.
  • 用图像增强来充实训练数据集,算不算是一种‘摸鱼’的方法?
  • 大型语言模型如何影响就业?大模型入门到精通,收藏这篇就够了
  • 初学者如何对大模型进行微调?
  • Openlayers高级交互(14/20):汽车移动轨迹动画(开始、暂停、结束)
  • 页面跳转不刷新 histoy.go hisroty.back不生效
  • Consul 实战指南