一.基本流程:
获取图像---矫正图像---确定ROI---提取边缘或直线---计算轮廓属性---处理多边形轮廓---转换到世界坐标系---结果可视化。
二.常用算子:
1. boundary(Region : RegionBorder : BoundaryType : )
利用形态学算子计算区域边缘并返回。
BoundaryType:'inner', 'outer', 'inner_filled'
原始区域内部;外部;内部填充,边缘皆是一个像素宽。
2. union1(Region : RegionUnion : : )
返回区域的并集。
3.edges_sub_pix(Image : Edges : Filter, Alpha, Low, High : )
利用Deriche, Lanser, Shen, or Canny filters滤波器提取亚像素边缘。
4. sort_contours_xld(Contours : SortedContours : SortMode, Order, RowOrCol : )
对输入轮廓进行分类。
SortMode:分类参考点位置。
Order:升序排列还是降序。
RowOrCol:行或者列作为分类的第一标准。
5. colored_display(Objects : : Colors : )
内部程序,用交替的颜色显示Objects.
6.fit_ellipse_contour_xld(Contours : : Algorithm, MaxNumPoints, MaxClosureDist, ClippingEndPoints, VossTabSize, Iterations, ClippingFactor : Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder)
用椭圆或椭圆弧拟合多边形轮廓,获得拟合数据。
Algorithm: 'fitzgibbon', 'fhuber', 'ftukey', 'geometric', 'geohuber', 'geotukey', 'voss', 'focpoints', 'fphuber', 'fptukey'
第一个算法:使得多边形上的点(Xi,Yi)到拟合椭圆的代数距离:a*Xi^2 + b*Xi*Yi + c*Yi^2 + d*Xi + e*Yi + f最小,已确定拟合椭圆。
MaxNumPoints:轮廓点上参与拟合的最大点数。
MaxClosureDist:作为封闭图像的端点间的最大距离。
ClippingEndPoints:拟合忽略的点数。
PointOrder:轮廓点序正负。
7. gen_ellipse_contour_xld( : ContEllipse : Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, Resolution : )
产生椭圆轮廓,Resolution轮廓点上相邻邻域点的最大欧氏距离。
三.例子分析
例1. * rim_simple.hdev: measures the diameter of drill-holes//测量钻孔直径//
*
dev_update_off ()
* ****
* step: acquire image
* ****
read_image (Image, 'rim')
get_image_size (Image, Width, Height)
dev_open_window_fit_image (Image, 0, 0, Width, Height, WindowID)
set_display_font (WindowID, 14, 'courier', 'true', 'false')
* ****
* step: determine region of interest (ROI)
* ****
threshold (Image, Dark, 0, 128)
connection (Dark, DarkRegions)
select_shape (DarkRegions, Circles, ['circularity','area'], 'and', [0.85,50], [1.0,99999])
boundary (Circles, RegionBorder, 'inner')
dilation_circle (RegionBorder, RegionDilation, 6.5)
union1 (RegionDilation, ROIEdges) //四个包括边界区域的ROI,形状接近椭圆环//
dev_display (Image)
dev_set_color ('yellow')
dev_set_draw ('margin')
dev_display (ROIEdges)
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: extract edges
* ****
reduce_domain (Image, ROIEdges, ImageROI)
edges_sub_pix (ImageROI, Edges, 'lanser2', 0.3, 10, 30)//提取亚像素边缘//
sort_contours_xld (Edges, SortedContours, 'upper_left', 'true', 'row')//对边缘进行编码//
dev_display (Image)
colored_display (SortedContours, ['cyan', 'white'])
disp_continue_message (WindowID, 'black', 'true')
stop ()
* ****
* step: process contours
* ****
fit_ellipse_contour_xld (Edges, 'ftukey', -1, 2, 0, 200, 3, 2, Row, Column, Phi, Ra, Rb, StartPhi, EndPhi, PointOrder))//产生椭圆弧拟合数据//
NumHoles := |Ra|//取长半轴数组的模//
gen_ellipse_contour_xld (ContEllipse, Row, Column, Phi, Ra, Rb, gen_tuple_const(NumHoles,0), gen_tuple_const(NumHoles,rad(360)), gen_tuple_const(NumHoles,'positive'), 1)//产生数据,前面是
数组的个数,后面为值,整体是赋值语句//
dev_display (Image)
sort_contours_xld (ContEllipse, SortedContEllipse, 'upper_left', 'true', 'row')
colored_display (SortedContEllipse, ['cyan', 'white'])
dev_set_color ('yellow')
for i := 0 to NumHoles-1 by 1
endfor
本文介绍了一种使用图像处理技术自动测量钻孔直径的方法,包括图像获取、区域识别、边缘提取、轮廓处理和结果可视化等关键步骤,实现钻孔尺寸的精确测量。



被折叠的 条评论
为什么被折叠?



