5.1.3   HGetRL

HGetRL (see figure 5.1) reads the runlength encoding of a region (type: Hrlregion, see section “Region Data (Hrlregion)”) denoted by the database key region_key (type Hkey) from the HALCON database.

Note that HGetRL automatically checks the result state of the underlying procedure with the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HGetRL yourself.

    Hrlregion  *region;
    Hkey       obj_key;
    Hkey       region_key;
    ...
    HCkP(HAllocRLTmp(proc_handle,&region));
    HGetObj(proc_handle,p,o,&obj_key);
    HGetComp(proc_handle,obj_key,REGION,&region_key);
    HGetRL(proc_handle,region_key,region);
    /* processing (in general this should be done calling an action proc.) */
    area = 0;
    for (i=0; i<region->num; i++)
      area += region->rl[i].ce - region->rl[i].cb + 1;
    HCkP(HFreeRLTmp(proc_handle,region));

Figure 5.6: Example for HGetRL: Calculate the area of a region.

Since the region data is copied to region, it might be overwritten with new values (in contrast to HGetImage and HGetFDRL, cf. section “HGetImage” and section “HGetFDRL”). However, this means that enough memory for region must be allocated before calling HGetRL, see section “Temporary Data”.

Figures 5.6 and figure 5.7 show example applications of HGetRL.