http://blog.sina.com.cn/s/blog_442bfe0e01011d86.html 关于xlds的几点说明: Philosophy: XLD is the abbreviation for eXtended Line Description and comprises all contour and polygon based data.(XLD是扩展的线类型,他由所有轮廓和多边形基本数组构成) XLDs belong to the iconic data.(属于图形数据) Subpixel-accurate operators like edges_sub_pix return the contours as XLD data. A contour is a sequence of 2D control points, which are connected by lines. Typically, the distance between control points is about one pixel.(控制点之间的距离是一个像素) XLD objects contain, besides the control points, so-called local and global attributes. Typical examples for these are, e.g., the edge amplitude of a control point or the regression parameters of a contour segment. Besides the extraction of XLD objects, HALCON supports further processing. Examples for this are the selection of contours based on given feature ranges or the segmentation of a contour into lines, arcs, polygons or parallels. 一.基本概念与流程: STEP1:创建XLD(可是是像素精度或者是亚像素精度,标准的方法是用亚像素边缘提取算子进行轮廓提取;如果是像素精度的可以通过阈值和滤波以及细化骨架,然后转化到XLD;当然XLD也可以通过CAD等其他软件的数据转化而来,还可以用鼠标画出来。 STEP2:对XLD轮廓进行分割,可以是线段分割、圆弧分割、椭圆弧分割等。select_obj选择分割的轮廓,为拟合做准备。 STEP3:执行拟合,可以用三种形状进行拟合。 STEP4:将前三步的结果转化成世界坐标。 Step5:提取轮廓特征。 STEP6:获得轮廓的原始数据或将其转化成其他的数据类型。 STEP7:结果可视化。 二.常用算子: 1. edges_sub_pix(Image : Edges : Filter, Alpha, Low, High : ) 提取亚像素边缘。 2.segment_contours_xld(Contours : ContoursSplit : Mode, SmoothCont, MaxLineDist1, MaxLineDist2 : ) 把轮廓分割成线段、圆和椭圆。 Contours :输入的轮廓。 ContoursSplit : 输出的分割结果。 Mode:用于分割的方式。 SmoothCont:用来平滑轮廓的像素数。 MaxLineDist1:第一次插值时和轮廓之间的最大距离。 MaxLineDist2 :第二次插值和轮廓之间的最大距离。 3. sort_contours_xld(Contours : SortedContours : SortMode, Order, RowOrCol : ) 依据轮廓的相对位置,把轮廓分类,输出分类后的轮廓。 4.count_obj(Objects : : : Number) 返回Objecets的元素个数。 5.select_obj(Objects : ObjectSelected : Index : ) 根据索引复制选择输入对象为输出图形对象。 6. get_contour_global_attrib_xld(Contour : : Name : Attrib) 返回轮廓的全局特性值。 Name :'regr_norm_row', 'regr_norm_col', 'regr_mean_dist', 'regr_dev_dist', 'cont_approx' 回归直线的行列坐标,平均距离等,拟合形式代码,0为直线拟合,1为圆弧拟合。 7. fit_line_contour_xld(Contours : : Algorithm, MaxNumPoints, ClippingEndPoints, Iterations, ClippingFactor : RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist) 利用线段拟合轮廓。 Algorithm:进行直线拟合时的最小二乘法的种类,给了5种。后四种都带有权重和拟合阈值。-1代表所有点。 ClippingFactor (input_control):去除奇异值的因数。 RowBegin ,ColBegin ,RowEnd ,ColEnd:拟合线段的起点和中点行列坐标。 8. gen_contour_polygon_xld( : Contour : Row, Col : ) 产生行列多边形轮廓,返回轮廓的行列坐标。 9. fit_circle_contour_xld(Contours : : Algorithm, MaxNumPoints, MaxClosureDist, ClippingEndPoints, Iterations, ClippingFactor : Row, Column, Radius, StartPhi, EndPhi, PointOrder) 利用圆弧拟合一个轮廓。不执行对输入轮廓的分割,所以必须保证每个轮廓对应唯一的一个圆。 10. gen_ellipse_contour_xld( : ContEllipse : Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, Resolution : ) 生成椭圆轮廓。 三.例子: * measure_metal_part.hdev: inspects metal part by fitting lines and circles//利用直线和圆弧拟合测量零件// * dev_close_window () dev_update_window ('off') * **** * step: acquire image * **** read_image (Image, 'metal-parts/metal-parts-01') get_image_size (Image, Width, Height) dev_open_window_fit_image (Image, 0, 0, Width, Width, WindowID) set_display_font (WindowID, 14, 'Courier', 'true', 'false') dev_set_draw ('margin') dev_set_line_width (3) dev_display (Image) disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: create contours * **** edges_sub_pix (Image, Edges, 'lanser2', 0.5, 40, 90) //提取边缘幅度在40-60的亚像素边缘// dev_display (Edges) disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: process contours * **** segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 6, 4, 4) //利用线和圆分割抽取的轮廓// sort_contours_xld (ContoursSplit, SortedContours, 'upper_left', 'true', 'column') dev_clear_window () dev_set_colored (12) dev_display (SortedContours) disp_continue_message (WindowID, 'black', 'true') stop () * **** * step: perform fitting * **** ROI := [115,225,395,535] dev_open_window (0, round(Width/2), (ROI[3]-ROI[1])*2, (ROI[2]-ROI[0])*2, 'black', WindowHandleZoom) dev_set_part (round(ROI[0]), round(ROI[1]), round(ROI[2]), round(ROI[3])) set_display_font (WindowHandleZoom, 14, 'courier', 'true', 'false') count_obj (SortedContours, NumSegments) dev_display (Image) NumCircles := 0 NumLines := 0 for i := 1 to NumSegments by 1
endfor disp_continue_message (WindowID, 'black', 'true') stop () dev_set_window (WindowHandleZoom) dev_close_window () dev_clear_window () |
|