边缘测量

1. 边缘定义

灰度明暗变化产生边缘,如何量化边缘的定义呢?

一维边缘的定义:图像中的点,其一阶导数绝对值是局部最大值,也被称为非最大抑制。一阶导数大于0是正边缘,小于0是负边缘。

等价定义:二阶导数过零的点。

按照上述定义,一维边缘就是点。与此相对应,二维边缘就是线,由一维边缘点组合而成的线(直线、曲线)。

二维边缘的定义:图像中的若干点组合成的线,这些点的方向导数在垂直于边缘的方向上局部最大的。或者说在这些点上梯度值在梯度方向上局部最大。

类似于一维边缘的定价定义:拉普拉斯算子过零的那些点。

但是,对于二维边缘来说,拉普拉斯和梯度计算出来的边缘位置通常是不同的,通过梯度计算二维边缘是首选。

2. HALCON 1D测量

HALCON一维测量的步骤如下:

1) 生成测量矩形或者测量弧形。算子有:

gen_measure_rectangle2 

gen_measure_arc

2)执行测量。算子有:

measure_pos: extracts straight edges perpendicular to the main axis of the measure object and returns the positions of the edge centers, the edge amplitudes, and the distances between consecutive edges.

measure_pairs: extracts straight edge pairs perpendicular to the main axis of the measure object and returns the positions of the edge centers of the edge pairs, the edge amplitudes for the edge pairs, the distances between the edges of an edge pair, and the distances between consecutive edge pairs.

fuzzy_measure_pos: extracts straight edges perpendicular to the main axis of the measure object and returns the positions of the edge centers, the edge amplitudes, the fuzzy scores, and the distances between consecutive edges.

fuzzy_measure_pairs: extracts straight edge pairs perpendicular to the main axis of the measure object and returns the positions of the first and second edges of the edge pairs, the edge amplitudes for the edge pairs, the positions of the centers of the edge pairs, the fuzzy scores, the distances between the edges of an edge pair, and the distances between consecutive edge pairs.

3)释放测量矩形或者测量弧形。算子有:

close_measure

一维测量的准确度依赖于测量矩形或者测量弧形。因为一维测量认为:待测量的边缘垂直于测量矩形或者测量弧形的主轴。所以一旦测量矩形或者测量弧形的主轴定位发生较大的偏差,意味着找到的边缘也发生较大的变差。实际执行时,往往通过形状匹配来准确定位测量矩形或者测量弧形。

下图故意将测量矩形倾斜,导致找出的边缘也跟着倾斜,计算出来的边缘位置和距离都与实际发生较大偏差。

3. 2D测量

二维测量的步骤如下:

1)创建测量模型。算子为:

create_metrology_model

2)为测量模型设置图像尺寸。算子为

set_metrology_model_image_size

3)添加测量物。算子有:

add_metrology_object_circle_measure:添加圆

add_metrology_object_ellipse_measure :添加椭圆

add_metrology_object_rectangle2_measure:添加带方向矩形

add_metrology_object_line_measure:添加线.

add_metrology_object_generic :添加其他形状

如下图,测量物(红色)定义了图像中待测物体的大概位置、方向和形状。HALCON自动沿着测量物边界定义了一圈垂直于边界的矩形组,作为测量区域。实际边缘(绿色)就是在这些测量区域内找到的。

查看测量物,可以用算子 get_metrology_object_model_contour。查看测量区域,可以用算子 get_metrology_object_measures

4)设置模型参数。算子为:

set_metrology_model_param

可以设置相机的标定参数,从而直接得到世界坐标的测量值。也可以重新设置坐标系的原点和角度。

5)设置测量物参数。算子为:

set_metrology_object_param

可以在第三步添加测量物时设置参数,也可以在此单独设置。主要参数有控制测量区域尺寸、分布的,有控制边缘判断的,...

6) 测量模型定位。算子为:

align_metrology_model

旋转、平移测量模型,以匹配待测物位置的改变。

7)测量。算子为:

apply_metrology_model

Halcon内部执行了一些列 measure_pos or fuzzy_measure_pos。获得一些列边缘点,然后进行优化拟合,返回结果给用户。

所以,二维测量基于一维测量,但是相较一维测量,二维测量更加复杂,返回的数据也更加准确。

8)获取结果。算子为:

get_metrology_object_result 

get_metrology_object_measures 返回测量区域

get_metrology_object_result_contour 返回最终得到的边缘

9)释放测量模型。算子为:

clear_metrology_model

把一维测量的那副图像,应用二维测量:

红色的测量物的两条直线,故意倾斜一定角度。但仍然准确地识别出边缘(绿色)。灰色矩形框是测量区域。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值