3D拟合测量水杯半径

article/2025/8/24 4:24:11

1,目的。

测量水杯的半径

如图所示:
在这里插入图片描述


2,原理。

3D 点云对象 进行圆柱体拟合,获取拟合后的半径。


3,注意事项。

  1. 在Halcon中使用fit_primitives_object_model_3d进行圆柱体拟合时,输出的primitive_parameter包含以下7个参数:
    1. 参数构成
      ​ - 轴线方向向量
      3个数值:(a, b, c)
      描述圆柱体轴线的空间方向,满足归一化条件 a² + b² + c² = 1
      . - 轴线上基准点坐标
      3个数值:(x0, y0, z0)
      表示轴线上的一个参考点,通常靠近点云的重心
      . - ‌圆柱半径
      1个数值:R
      单位为点云的原始坐标系单位(如毫米)

    2. 数学验证

      圆柱表面点需满足方程:
      ( x − x p ) 2 + ( y − y p ) 2 + ( z − z p ) 2 − [ ( x − x p ) a + ( y − y p ) b + ( z − z p ) c ] 2 = R \sqrt{(x-x_p)^2+(y-y_p)^2+(z-z_p)^2-[(x-x_p)a+(y-y_p)b+(z-z_p)c]^2}=R (xxp)2+(yyp)2+(zzp)2[(xxp)a+(yyp)b+(zzp)c]2 =R
      其中(x_p, y_p, z_p)为轴线上任意一点


  1. 在Halcon中使用fit_primitives_object_model_3d对三维点云进行球体拟合时,输出的primitive_parameter包含以下4个关键参数:

    1. 参数构成
      球心坐标
      包含3个数值:(x, y, z)
      表示拟合球体的中心点在三维空间中的位置
      球体半径
      单个数值:R
      单位为点云的原始坐标系单位(如毫米或米)

    2. 参数验证方法
      数学验证‌:球面点需满足方程 ( x − x 0 ) 2 + ( y − y 0 ) 2 + ( z − z 0 ) 2 = R 2 (x-x_0)^2+(y-y_0)^2+(z-z_0)^2=R^2 (xx0)2+(yy0)2+(zz0)2=R2
      其中(x_0, y_0, z_0)为球心坐标

    3. 与其他几何体的区别

    • 圆柱体‌:输出7个参数(轴线方向、基准点、半径)68
    • 平面‌:输出4个参数(法向量、偏移量)

4,代码。

*参考案例库:fit_primitives_object_model_3d.hdev* ***********************************************************************
* 将输入的 2.5D 图像拟合成圆柱体,并计算显示拟合后的圆柱体半径* 2.5D 图像:在常规二维图像基础上叠加‌**高度或深度数据**‌,形成半三维表达(如灰度值隐含高度信息或直接存储深度通道)*
* ***********************************************************************
dev_update_off ()
dev_close_window ()
* Input: 2.5D image
* tif图像:是HALCON支持的‌高精度图像格式‌,专门用于存储包含复杂信息的图像数据,如3D深度图、工业相机采集的点云数据等*
* 一般由结构光相机,3D扫描仪提供
read_image (XYZ, '3d_machine_vision/segmentation/3d_primitives_xyz_02.tif')
dev_open_window_fit_image (XYZ, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
* Access to (x-, y-, z-)coordinates
access_channel (XYZ, X, 1)
access_channel (XYZ, Y, 2)*  提取第三通道作为深度
access_channel (XYZ, Z, 3)
* Segment cylinder manually
threshold (Z, Region, 0.0, 0.83)reduce_domain (X, Region, XTmp)dev_display (Z)
dev_set_draw ('margin')
dev_set_line_width (2)
dev_set_color ('green')
dev_display (Region)
disp_message (WindowHandle, 'Segment cylinder with a simple threshold', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
xyz_to_object_model_3d (XTmp, Y, Z, ObjectModel3DID)* 指定 3D 对象的原始类型,拟合算法,输出类型
ParFitting := ['primitive_type','fitting_algorithm','output_xyz_mapping']
ValFitting := ['cylinder','least_squares_huber','true']
* 对 原始对象进行 3D 拟合fit_primitives_object_model_3d (ObjectModel3DID, ParFitting, ValFitting, ObjectModel3DOutID)
* Clear the object model that is no longer used
clear_object_model_3d (ObjectModel3DID)
* Display the result of the fitting
dev_display (Z)
dev_set_draw ('fill')
dev_display_fitting_results (RegionCylinder, RegionSphere, RegionPlane, RegionNone, ObjectModel3DOutID, WindowHandle, [])
dev_update_on ()
clear_object_model_3d (ObjectModel3DOutID)

本地函数:dev_display_fitting_results

* This procedure displays the results of a fitting operation.
* Additionally to the primitive regions, the radius of
* cylinders and spheres is displayed.
* The colors can be specified with the parameter Colors
* in the following manner:
* Color[0] is used for objects which could not be fitted
* Color[1] is used for cylinders:用于圆柱体
* Color[2] is used for spheres:用于球体
* Color[3] is used for planes:用于平面
* 
if (Colors == [])Colors := ['dim gray','forest green','red','slate blue']
endif
NumNone := 0
* 圆柱体数量
NumCylinders := 0
* 球体数量
NumSpheres := 0
* 平面数量
NumPlanes := 0
for Index := 0 to |ObjectModel3DOutID| - 1 by 1object_model_3d_to_xyz (XTmp, YTmp, ZTmp, ObjectModel3DOutID[Index], 'from_xyz_map', [], [])get_domain (XTmp, DomainTmp)* 是否存在原始数据get_object_model_3d_params (ObjectModel3DOutID[Index], 'has_primitive_data', ParamValue)if (ParamValue == 'true')get_object_model_3d_params (ObjectModel3DOutID[Index], 'primitive_parameter', GenParamValuesP)get_object_model_3d_params (ObjectModel3DOutID[Index], 'primitive_type', ParamValue)if (ParamValue == 'cylinder')if (NumCylinders == 0)*-1:表示复制从索引开始剩余的所有对象,注意这里是浅复制copy_obj (DomainTmp, RegionCylinder, 1, -1)* 从拟合的原始数据中获取拟合的圆柱体半径值RadiusCylinder := GenParamValuesP[6]elseconcat_obj (RegionCylinder, DomainTmp, RegionCylinder)RadiusCylinder := [RadiusCylinder,GenParamValuesP[6]]endifNumCylinders := NumCylinders + 1elseif (ParamValue == 'sphere')* 球体情况if (NumSpheres == 0)copy_obj (DomainTmp, RegionSphere, 1, -1)RadiusSphere := GenParamValuesP[3]elseconcat_obj (RegionSphere, DomainTmp, RegionSphere)RadiusSphere := [RadiusSphere,GenParamValuesP[3]]endifNumSpheres := NumSpheres + 1else* 平面情况if (NumPlanes == 0)copy_obj (DomainTmp, RegionPlane, 1, -1)elseconcat_obj (RegionPlane, DomainTmp, RegionPlane)endifNumPlanes := NumPlanes + 1endifelseif (NumNone == 0)copy_obj (DomainTmp, RegionNone, 1, -1)elseconcat_obj (RegionNone, DomainTmp, RegionNone)endifNumNone := NumNone + 1endif
endfor
* 
NumColors := |Colors|
if (NumNone > 0)dev_set_color (Colors[0 % NumColors])dev_display (RegionNone)
endif
if (NumCylinders > 0)dev_set_color (Colors[1 % NumColors])dev_display (RegionCylinder)
endif
if (NumSpheres > 0)dev_set_color (Colors[2 % NumColors])dev_display (RegionSphere)
endif
if (NumPlanes > 0)dev_set_color (Colors[3 % NumColors])dev_display (RegionPlane)
endif
disp_message (WindowHandle, '3D Fitting', 'window', -1, -1, 'black', 'true')
Message := 'Cylinders: ' + NumCylinders
Message[1] := 'Spheres: ' + NumSpheres
Message[2] := 'Planes: ' + NumPlanes
Message[3] := 'Undefined: ' + NumNone
disp_message (WindowHandle, Message, 'window', 40, 12, 'black', 'true')
if (NumCylinders > 0)* Display radius for each cylinderarea_center (RegionCylinder, Area, Row, Column)for Index := 0 to NumCylinders - 1 by 1Radius := int(RadiusCylinder[Index] * 1000)disp_message (WindowHandle, 'Cylinder\nr = ' + Radius + ' mm', 'image', Row[Index], Column[Index], 'white', 'false')endfor
endif
if (NumSpheres > 0)* Display radius for each cylinder spherearea_center (RegionSphere, Area, Row, Column)for Index := 0 to NumSpheres - 1 by 1Radius := int(RadiusSphere[Index] * 1000)disp_message (WindowHandle, 'Sphere\nr = ' + Radius + ' mm', 'image', Row[Index], Column[Index], 'white', 'false')endfor
endif
return ()

http://www.hkcw.cn/article/mELXiNOqWZ.shtml

相关文章

数据可视化(第4、5、6次课)

Matplotlib 折线图 import numpy as np import matplotlib.pyplot as plt import matplotlib # 配置中文格式——保证图中出现中文的时候不会乱码 matplotlib.rcParams[font.sans-serif][SimHei] matplotlib.rcParams[axes.unicode_minus]False # 绘图 x np.linspace(0,2*np…

SpringBoot(五)--- 异常处理、JWT令牌、拦截技术

目录 一、异常处理 1. 问题分析 2. 全局异常处理器 二、登录校验技术 1.会话技术 1.1 Cookie 1.2 Session 2. JWT令牌 2.1 介绍 2.2 生成与校验 2.3 登录时下发令牌 3. 过滤器Filter 3.1 概述 3.2 登录校验过滤器 3.3 Filter详解 4. 拦截器interceptor 4.1 令…

springboot面试题

SpringBoot注解 SpringBootApplication EnableAutoConfiguration springboot自动配置原理 SpringBootApplication 是一个复合注解,结合了以下三个核心注解的功能,用于简化 Spring Boot 应用的启动类配置: SpringBootConfiguration Enabl…

架构意识与性能智慧的双重修炼

架构意识与性能智慧的双重修炼 ——现代软件架构师的核心能力建设指南 作者:蓝葛亮 🎯引言 在当今快速发展的技术环境中,软件架构师面临着前所未有的挑战。随着业务复杂度的不断增长和用户对性能要求的日益严苛,如何在架构设计中平衡功能实现与性能优化,已成为每个技术…

STM32G4 电机外设篇(一) GPIO+UART

目录 一、STM32G4 电机外设篇(一) GPIOUART1 GPIO1.1 STM32CUBEMX 配置以及Keil代码1.2 代码和实验现象 2 UART2.1 STM32CUBEMX 配置以及Keil代码2.2 代码和实验现象 附学习参考网址欢迎大家有问题评论交流 (* ^ ω ^) 一、STM32G4 电机外设篇&#xff0…

小型语言模型:为何“小”才是“大”?

当说到人工智能(AI)的时候,大家通常会想到那些拥有数十亿参数的超大型语言模型,它们能做出一些令人惊叹的事情。 厉害不厉害?绝对厉害! 但对于大多数企业和开发者来说,实用吗?可能…

痉挛性斜颈介绍

痉挛性斜颈是一种局限性肌张力障碍性疾病,主要表现为颈部肌肉不自主收缩,导致头部向一侧扭转、倾斜或后仰,可伴有颈部疼痛或姿势异常。该病多在成年后起病,男女均可发病,具体病因尚未完全明确,可能与神经调…

【笔记】suna部署之获取 OpenRouter API key

#工作记录 OpenRouter 注册 OpenRouter 账号: 打开浏览器,访问OpenRouter 官网。点击页面右上角的 “Sign in” 按钮。选择注册方式,可使用 Google 账户、GitHub 账户、Discord 账户登录,也可使用电子邮件注册。若使用邮箱注册&am…

最优控制:从变分法到庞特里亚金原理

典型问题 根据系统的建模可以划分为: 线性系统: x ˙ A x B u \mathbf{\dot{x}} \boldsymbol{A}\mathbf{x}\boldsymbol{B}\mathbf{u} x˙AxBu非线性系统 x ˙ ( t ) f ( x ( t ) , u ( t ) , t ) \dot{\mathbf{x}}(t) \mathbf{f}(\mathbf{x}(t)…

R²AIN SUITE 驱动制造业变革:从灯塔实践到企业级落地方案

一、全球制造业的AI革命浪潮 世界经济论坛《全球灯塔网络》报告揭示,AI在制造业的应用正呈现指数级增长。最新数据显示,入选灯塔工厂的企业中,AI技术渗透率已从早期的不足20%跃升至60%左右,推动生产系统实现2-3倍效率提升、质量缺…

全球全能邮箱:如何选适合的全能邮件服务?

全球全能邮箱:如何选适合的全能邮件服务? 全球全能邮箱怎么选?烽火域名邮箱的优势特点有哪些? 全球全能邮箱不仅仅是一个简单的邮箱工具,更是集成多种功能,支持多语言、多终端、跨区域使用的全能邮件解决…

抖音、快手无水印福音开源下载器之蓝猫 BlueCatKoKo

之前分享过闪豆视频下载器https://pan.quark.cn/s/8e262bd6e130(自行保存下载),它支持抖音,快手,B站,有管,可以批量下载。 蓝猫下载器链接:夸克网盘分享(自行保存下载&a…

嵌入式学习笔记 - freeRTOS同优先级任务时间片抢占的实现

已经知道freeRTOS的任务切换函数发生在systick中断中,如下图 由上图可见,任务切换有个先决条件TaskIncrementTick()函数返回为1,这个函数如下图, 第564行是判断如果延时时间到的任务比当前任务优先级高&am…

Cisco Packer Tracer 中 VLAN 与三层交换机

一、实验目的 1)掌握 VLAN 的基本配置方法, 理解 VLAN 的功能和作用; 2)掌握三层交换机的基本配置方法。 3)理解三层网络的路由转发 二、实验环境 1)运行 Windows 2008 Server/XP/7 /10操作系统的 PC …

数据结构——哈希表

一、概念 哈希表也叫做散列表。是根据关键码值(Key Value)直接进行访问的数据结构。 哈希表通过「键 key 」和「映射函数 Hash(key) 」计算出对应的「值 value」,把关键码值映射到表中一个位置来访问记录,以加快查找的速度。这个…

Kotlin中的::操作符详解

Kotlin提供了::操作符,用于创建对类或对象的成员(函数、属性)的引用。这种机制叫做成员引用(Member Reference)。这是Kotlin高阶函数和函数式编程的重要组成部分。 简化函数传递 在Java中,我们这样传方法: list.forEach(item -> System.…

K8S集群主机网络端口不通问题排查

一、环境: k8s: v1.23.6 docker: 20.10.14 问题和故障现象:devops主机集群主机节点到端口8082不通(网络策略已经申请,并且网络策略已经实施完毕),而且网络实施人员再次确认,网络策…

回调函数的理解

int yuxiangrousi 0; // 全局变量:鱼香肉丝(酱油量)// 回调函数:妈妈处理酱油(将酱油加入鱼香肉丝) void mother_callback(int new_jiangyou) {yuxiangrousi new_jiangyou; // 把酱油放进鱼香肉丝 }// 孩…

python字符重复一次 2023年信息素养大赛复赛/决赛真题 小学组/初中组 python编程挑战赛 真题详细解析

python字符重复一次 2023全国青少年信息素养大赛Python编程挑战赛复赛真题解析 博主推荐 所有考级比赛学习相关资料合集【推荐收藏】1、Python比赛 信息素养大赛Python编程挑战赛 蓝桥杯python选拔赛真题详解

【笔记】suna部署之获取 Supabase API key 和 project URL

#工作记录 Supabase | The Open Source Firebase Alternative 一、注册与登录 方式一:GitHub 授权登录 在登录页面选择 “继续使用 GitHub” ,跳转到 GitHub 授权页面(如图 5 所示)。确认 “Supabase 的想要访问您的 [账户名] 帐…