halcon圆查找

圆查找功能
本质上圆查找功能是由于大部分时候会出现的模板匹配的精度不佳,对实际的坐标有部分偏差的情况
这时候我们可以通过建立测量矩形的形式,对预估点进行多次测量以得到较为精确的轮廓
算子除了有圆查找,还有椭圆查找,直线查找,带角度的矩形查找四种方法

*创建测量模板
create_metrology_model (MetrologyHandle)
*向计量模型中添加计量对象。
*其中需要注意的是:'circle'*halcon的这个算子允许对4种计量对象:'circle'(圆形)ellipse(椭圆形)line(直线)rectangle2(带角度的矩形)
*[Row3, Column3, 195]对计量模型创建特征。当我们选择圆形的时候就会需要圆的中心XY坐标和半径
*50(高斯滤波的值)
*test1计量模型识别码
add_metrology_object_generic (MetrologyHandle, 'circle', [Row3, Column3, 195], 50, 5, 5, 30, [], [], test1)
*将句柄添加在图像中
apply_metrology_model (Image1, MetrologyHandle)
*获取到计量模型的结果
*输出不同类型'used_edges'(提取边缘) 'angle_direction'(提取角度) 'result_type'(结果类型)
*'row'(获取行坐标)【输出多种不同类型的数值】(实质上可以获取到测量举行的拟合中点)
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'used_edges', 'row', UsedRow)
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'used_edges', 'column', UsedColumn)
*生成测量矩形
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row1, Column1)
*创建测量矩形中点
gen_cross_contour_xld (UsedEdges, UsedRow, UsedColumn, 10, Angle)
*创建圆形
get_metrology_object_result_contour (ResultContours, MetrologyHandle, 'all', 'all', 1.5)
dev_display (Image1)
dev_display (UsedEdges)
dev_display (ResultContours)
*对结果类型进行获取,获取角度,中心X值和Y值
*RadiusC1角度值,Row9行坐标,column9纵坐标
get_metrology_object_result (MetrologyHandle, test1, 'all', 'result_type', 'radius', RadiusC1)
get_metrology_object_result (MetrologyHandle, test1, 'all', 'result_type', 'row', Row9)
get_metrology_object_result (MetrologyHandle, test1, 'all', 'result_type', 'column', column9)
*创建圆形轮廓
gen_circle_contour_xld (ContCircle2, Row9, column9, RadiusC1, rad(180), rad(360), 'positive', 1)
gen_circle_contour_xld (ContCircle3, Row9, column9, RadiusC1, rad(0), rad(-180), 'positive', 1)
gen_cross_contour_xld (Cross, Row9, column9, 100, Angle)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_51559565/article/details/128368683
今日推荐