XLDs (eXtended Line Descriptions) are specific iconic HALCON objects to represent subpixel accurate contours and polygons. The corresponding data types Hcont and Hpoly are listed in figures 4.7 and figure 4.8.
typedef enum cont_class { cont_unknown, /* unknown */ cont_no_junc, /* neither start nor end point points */ /* are junctions */ cont_start_junc, /* start point is a junction */ cont_end_junc, /* end point is a junction */ cont_both_junc, /* both start and end point are junctions */ cont_closed /* closed contour */ } Hcont_class; typedef struct cont_attrib { char *name; /* name of the attribute */ HSUBATTR *val; /* value of the attribute (per point) */ } Hcont_attrib; typedef struct cont_global_attrib { char *name; /* name of the global attribute */ HSUBATTR val; /* value of the attribute (per contour) */ } Hcont_global_attrib; typedef struct cont_type { HITEMCNT num; /* number of points along the contour */ HSUBCOOR* row; /* points / row indices (y coordinates) */ HSUBCOOR* col; /* points / column indices (x coord.) */ Hcont_class cont_class; /* contour class */ int32_t num_attrib; /* number of additional attributes */ Hcont_attrib* attribs; /* additional attributes (for each point) */ int32_t num_global; /* number of additional global attributes */ Hcont_global_attrib* global;/* additional attributes (per contour) */ int32_t h; /* auxiliary (temporary) */ } Hcont;
Figure 4.7: The XLD data type Hcont for subpixel contours.
typedef struct lin_seg_type { HSUBCOOR row,col; /* a control point of the polygon: */ /* row (y) and column (x) coordinate */ HSUBATTR length; /* length of the line from the */ /* current to the next point */ HSUBATTR phi; /* orientation (rad) of this line */ Hkey ref; /* database key of the underlying */ /* contour */ HITEMCNT first; /* index of the first point of the */ /* underlying contour belonging to */ /* current side of the polygon */ HITEMCNT last; /* index of the last contour point */ } Hline_seg; typedef struct poly_type { HITEMCNT num_line; /* number of lines */ HITEMCNT len_line; /* maximum number of lines (size */ /* of the array lines) */ Hline_seg* lines; /* control points of the polygon */ } Hpoly;
Figure 4.8: The XLD data type Hpoly for subpixel polygons.
HALCON contours of type Hcont contain an array of subpixel points along a contour. A contour might be classified concerning to topological considerations (cont_class). Additionally, an arbitrary number of additional contour attributes for each point along the contour can be included (attribs), e.g., the edge amplitude of subpixel edge points or the orientation of the local gradient. Finally, an arbitrary number of additional global attributes, i.e., attributes valid for the entire contour, can be included (global), e.g., the individual parameters of a regression line to the contour or the parameters of an ellipse segment fitted to the contour.
Names
HCopyXLDCont, HCopyXLDContPart
Synopsis
#include "Halcon.h" Herror HCopyXLDCont( Hproc_handle proc_handle, Hcont* cont_in, bool preserve_attribs, bool preserve_global_attribs, Hcont** cont_out) Herror HCopyXLDContPart( Hproc_handle proc_handle, Hcont* cont_in, INT4_8 min_index, INT4_8 max_index, bool preserve_attribs, bool preserve_global_attribs, Hcont** cont_out)
Figure 4.9: Auxiliary routines for contours of type Hcont.
Names
HAddXLDContAttrib, HLookupXLDContAttrib, HAddXLDContGlobalAttrib, HLookupXLDContGlobalAttrib
Synopsis
#include "Halcon.h" HAddXLDContAttrib( Hproc_handle proc_handle, Hcont* cont, char* name, int32_t* index) HLookupXLDContAttrib( Hcont* cont, char* name, int32_t* index) HAddXLDContGlobalAttrib( Hproc_handle proc_handle, Hcont* cont, char* name, int32_t* indx); HLookupXLDContGlobalAttrib( Hcont* cont, char* name, int32_t* indx);
Figure 4.10: Handling contour attributes of contour pixels (within Hcont).
Please see section “Permanent Data” for routines to allocate/deallocate contours. Two important auxiliary routines to copy contours are listed in figure 4.9. HCopyXLDCont copies a complete contour, whereas HCopyXLDContPart copies only a part of the original contours specified by two indices min_index and max_index. They refer to the first and the last point along the contour to be copied (starting with index 0). For closed contours a negative value might be specified for min_index. This will lead to a “wrap-around”, that is the part of the contour to be copied starts at cont_in->num + min_index. Both HCopyXLDCont and HCopyXLDContPart allocate the output contour themselves. So just pass a pointer to a pointer to Hcont without allocating any memory for cont_out. Both routines provides two additional parameters, preserve_attribs and preserve_global_attribs, to control whether the non-global and the global contour attributes should be copied.
The routines provided for handling contour attributes of contour points are summarized in figure 4.10. HAddXLDContAttrib is used to add a new class of contour attributes to a given contour cont. Note, that this routine allocates memory for the attribute values, but it does not set the values themselves. An arbitrary name for the attribute can be specified by the parameter name. The index of the new attribute within the attribs array in cont is returned in index and can be used to address the values by cont->attribs[index].val[xxx]. The same holds for global attributes: HAddXLDContGlobalAttrib is used to add new global attributes, which can be accessed by cont->global[index].val. Note that these values can be accessed within the HALCON system (that is on the application layer) using the operators get_contour_attrib_xld and get_contour_global_attrib_xld. See the Reference Manuals for details. Within HALCON, a specific attribute of a contour can be accessed using HLookupXLDContAttrib, while a specific global attribute can be accessed using HLookupXLDContGlobalAttrib. These routines return the index of the desired attribute within attribs or global of cont, or the error code H_ERR_XLD_CAND as result of the procedure call, if no attribute with the specified name is defined.
The XLD data type Hpoly, displayed in figure 4.8, encodes subpixel accurate polygons. Basically it contains an array of control points. In many applications such polygons are derived from contours. Thus, the data structure can also hold a reference to the underlying part of a contour specified by a HALCON database key.