HDupObj (see figure 6.8) is a combination/simplification of HGetObj (see section “HGetObj”) and HCopyObj (see section “HCopyObj”). It duplicates iconic input objects (images, regions, XLD) in order to pass them directly to the first output object parameter. The objects to be duplicated are specified by their index obj_index within the first input object parameter. Note, that this index corresponds to obj_index as defined for the loop macros (HAll*) in section “Loop Macros”. HDupObj is typically used for operators that examine objects and select them by a given criterion. Some HALCON operators of this kind are select_shape or select_gray.
Note that HDupObj automatically checks the result state of the underlying procedure with the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HDupObj yourself.
Figure 6.11 shows an application of HDupObj: CIPUserSelect computes the length of the contour of each input region (in parameter 1). All regions with a contour of at least the minimal length min are passed to the output.
Herror CIPUserSelect(Hproc_handle proc_handle) { Hrlregion *region; Hrlregion *region_new; double length; Hcpar min; INT4_8 i; HGetSPar(proc_handle,1,DOUBLE_PAR,&min,1); /* get min. length */ HAllReg(proc_handle,®ion,i) { /* all regions */ HCkP(HRLContLength(proc_handle,region,&length)); /* length */ if (length >= min.par.f) /* length o.k. ? */ HDupObj(proc_handle,i); /* duplicate object*/ } return(H_MSG_TRUE); }
Figure 6.11: A typical application of HDupObj: Duplicate input regions that fulfill a specific criteria (length of contour).
Since HDupObj only increases the number of references to a database object instead of copying it physically, its memory costs and computational costs are neglectable. In contrast, e.g., HNewRegion and HAllFilter always allocate new memory for the output objects. So whenever possible, HDupObj should be used.