halcon edges_image算子分析

边缘检测技术详解
本文详细介绍了一种使用Deriche、Lanser、Shen或Canny滤波器进行边缘提取的算法。通过调整参数,如边缘算子、过滤器参数、非最大抑制及滞后阈值等,可以精确控制边缘检测的效果。示例中展示了如何读取图像,并运用Lanser2滤波器进行边缘检测。

edges_image(Image : ImaAmp, ImaDir : Filter, Alpha, NMS, Low, High : ):使用Deriche, Lanser, Shen或者Canny 滤波器进行边缘提取

参数:

Image :输入图像

ImaAmp:边缘振幅(梯度大小)图像

ImaDir :图像边缘方向

Filter:边缘算子

Alpha:过滤器参数,小的值导致强平滑,但是更少的细节(canny算子相反)

NMS:非最大抑制(设置为none,表示不需要使用该值)

Low:滞后阈值操作的下阈值(如果不需要阈值设置,则为负值)

High :滞后阈值操作的上阈值(如果不需要阈值设置,则为负值)

示例:

算子:

read_image (Image, 'fabrik')
edges_image (Image, ImaAmp, ImaDir, 'lanser2', 0.5, 'nms', 12, 22)
threshold (ImaAmp, Edges, 1, 255)
skeleton (Edges, Skeleton)
gen_contours_skeleton_xld (Skeleton, Contours, 1, 'filter')

<think>Hmm, the user is asking specifically about Halcon's measure_pos operator after providing several reference materials. Interesting that they jumped straight into technical details - probably an engineer or machine vision technician working on a real project. Looking at their request, they want a practical guide: usage, functionality, and examples. The references mention it extracts straight edges perpendicular to rectangles/annular arcs, which matches my knowledge. Reference [3] shows it's typically used in calibrated measurement workflows after gen_measure_rectangle2. Wait... the user didn't specify if they're using Halcon/HDevelop or the library bindings (C++, C#, etc.). I should emphasize the core parameters first since they're language-agnostic. The key points to cover would be ROI generation, transition parameters, and how to interpret the (Row,Column) results. Oh! Must remember their system-level instruction about LaTeX formatting. For parameters like Sigma or Threshold, I'll wrap them properly as $Sigma$. And the coordinate pairs in the output should be like $(Row_Edge, Column_Edge)$. The examples are crucial here. Since they referenced a positioning+measurement workflow in [3], I'll include a complete code snippet showing shape model-based ROI transformation - that's industry best practice. Should mention that affine_trans_contour_xld tip since it's not obvious to beginners. Better warn about common pitfalls too. The "MinScore" trap is notorious - users often set it too high and miss edges. And the ROI size effect! Novices constantly make ROIs too large and get multiple edges. Maybe add a troubleshooting table... For related questions: the pairing/fuzzy variants are natural extensions, and clarifying the object lifecycle (create/close) would prevent memory leaks. The projection/threshold ops in [2] are adjacent topics too. </think>以下为Halcon中`measure_pos`算子的详细指南,结合核心功能、参数说明及典型应用示例: --- ### **一、算子功能** `measure_pos`用于**精确提取垂直于矩形或环形弧的直边位置**,通过灰度值过渡分析实现亚像素精度检测。主要应用场景包括: - 工业零件尺寸测量(如边缘间距、角度) - 定位标记点坐标获取 - 高精度轮廓分析 --- ### **二、关键参数说明** | 参数 | 类型 | 说明 | |------|------|------| | `MeasureHandle` | Input | 测量对象句柄(由`gen_measure_rectangle2`或`gen_measure_arc`生成) | | `Sigma` | Input | 高斯滤波系数(推荐1.0),值越大抗噪性越强但边缘精度降低 | | `Threshold` | Input | 边缘对比度阈值(灰度差最小值),值越高筛选越严格 | | `Transition` | Input | 边缘方向:`'positive'`(亮→暗)、`'negative'`(暗→亮)、`'all'`(双向) | | `Select` | Input | 边缘选择:`'first'`/`'last'`(首末边缘)、`'all'`(全部边缘) | | `RowEdge, ColumnEdge` | Output | 边缘中心点坐标(亚像素精度) | | `Amplitude` | Output | 边缘强度(灰度变化幅度) | | `Distance` | Output | 连续边缘间距(需配合`measure_pairs`使用) | --- ### **三、使用流程** #### **步骤1:创建测量对象** ```cpp * 生成矩形ROI(中心(200,300),方向0°,半宽50px,半高100px) gen_measure_rectangle2(200, 300, 0, 50, 100, Width, Height, 'nearest_neighbor', MeasureHandle) ``` #### **步骤2:执行边缘检测** ```cpp * 检测ROI内所有暗→亮边缘(阈值=30,抗噪系数=1) measure_pos(Image, MeasureHandle, 1.0, 30, 'negative', 'all', RowEdges, ColEdges, Amplitude, Distance) ``` #### **步骤3:可视化结果** ```cpp * 标记边缘位置 dev_display(Image) for i := 0 to |RowEdges|-1 by 1 set_color('red') disp_cross(RowEdges[i], ColEdges[i], 20, 0) endfor ``` #### **步骤4:释放资源** ```cpp close_measure(MeasureHandle) // 必须手动释放句柄! ``` --- ### **四、典型应用示例** **案例:芯片引脚间距测量** ```cpp * 1. 定位芯片位置(基于模板匹配) find_shape_model(Image, ModelID, ..., Row, Column, Angle) * 2. 根据位姿生成测量ROI vector_angle_to_rigid(..., HomMat2D) affine_trans_contour_xld(OriginalROI, TransROI, HomMat2D) // 变换ROI[^3] * 3. 创建测量对象 gen_measure_rectangle2(TransROI, ..., MeasureHandle) * 4. 检测引脚边缘 measure_pos(Image, MeasureHandle, 1.0, 25, 'all', 'all', Rows, Cols, Amp, _) * 5. 计算相邻边缘距离 edges_distance(Rows, Cols, Distances) // 自定义函数计算间距 ``` --- ### **五、注意事项** 1. **ROI方向优化**:矩形ROI的长边需**垂直于目标边缘**(通过`gen_measure_rectangle2`的`Angle`参数调整) 2. **抗噪与精度平衡**:`Sigma`值推荐范围 $[0.4, 2.0]$,过高会导致边缘模糊 3. **边缘遗漏处理**:若未检测到边缘: - 检查`Threshold`是否过高(降低10-20%重试) - 确认`Transition`方向设置正确 - 增大ROI高度(需不超过目标区域) > ⚠️ 多次调用时需及时用`close_measure`释放句柄,否则引发内存泄漏[^2] --- ### **六、扩展算子推荐** | 算子 | 功能 | 适用场景 | |------|------|----------| | `measure_pairs` | 提取成对边缘 | 卡尺测量、宽度计算 | | `fuzzy_measure_pos` | 模糊逻辑边缘检测 | 低对比度图像 | | `measure_thresh` | 基于灰度阈值的点提取 | 二值化特征点 | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乌里随记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值