HGetObj (see figure 5.1) returns the database key (type: Hkey) of an iconic object corresponding to the input object parameter with the index par_num of the HALCON operator.
Note that HGetObj automatically checks the result state of the underlying procedure with the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HGetObj yourself.
int8_t inp_pars; int32_t num_objs; int p,o; Hkey key; ... /* get number of input iconic parameters: */ /* note: This number is known in general - it is specified by */ /* the operator header in the corresponding def-file of the */ /* operator */ HReadGV(proc_handle,HGinp_obj,&inp_pars); for (p=1; p<=inp_pars; p++) { /* get number of input iconic objects per input obj. parameter: */ HReadGVA(proc_handle,HGnum_obj,&num_objs,p); for (o=1; o<=num_objs; o++) { HGetObj(proc_handle,p,o,&key); /* get key of iconic object */ /* further processing ... */ } }
Figure 5.3: Example for HGetObj: Database keys of all iconic objects of all input object parameters.
The iconic object can either be a region (iconic object that contains only a region component), an image (iconic object that contains a region component and one or more image channels), or an XLD (iconic object that contains a contour or a polygon).
The parameters of a HALCON operator are numbered consecutively from 1 to n (not from 0 to n − 1) for each parameter class (input/output iconic object/control). The parameter par_num of HGetObj refers to this index, thus specifying the desired input iconic parameter. All objects passed within a single input iconic parameter are numbered from 1 to m, with the first iconic object in the list having the index 1. The parameter obj_num of HGetObj denotes the index of a desired iconic object within this list (1 ≤ obj_num ≤ m).
The total number of input iconic parameters for an operator is specified in the corresponding def-file 12), but the number of objects within an input iconic parameter is dynamic. This value is accessible via the Extension Package Interface routine HReadGVA:
where p denotes the parameter index and num_objs is the desired number of iconic objects. As an alternative for reading the number of iconic objects of an input iconic parameter without the routine HReadGVA, you can use the macro HGetObjNum (see section “HGetObjNum”).HReadGVA(proc_handle,HGnum_obj,&num_objs,p);
Note that a loop over all iconic objects passed to an operator within an input iconic object parameter is a very common task. Therefore, HALCON provides a macro for this problem: See HAllObj in section “HAllObj”.
| 12) So this number is actually known
by the programmer. However, using HReadGV it can be
read from the operator context as well, see
figure 5.3.
|