HNewRegion (see figure 6.8) is used to create a new image object in the HALCON database which is also added to the first output object parameter. It contains a copy of region. It is common to call an image object region, when only its region component is used.
Note that HNewRegion automatically checks the result state of the underlying procedure with the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HNewRegion yourself.
Herror CIPConvex(Hproc_handle proc_handle) { Hrlregion *region; Hrlregion *region_new; HCkP(HAllocRLTmp(proc_handle,®ion_new) /* allocate memory */ HAllReg(proc_handle,®ion,i) { /* all regions */ HCkP(HRLConvex2(proc_handle,region,region_new)); /* create an output region object (first output param.) */ HNewRegion(proc_handle,region_new); } HCkP(HFreeRLTmp(proc_handle,region_new)); /* free memory */ return(H_MSG_TRUE); }
Figure 6.9: A typical application of HNewRegion: The region transformation “convex hull”.
Typically, HNewRegion is used within segmentation procedures (see figure 6.4) and region transformation procedures such as the procedure CIPConvex shown in figure 6.9. CIPConvex corresponds to a hypothetical operator trans_convex which might be defined as
trans_convex <- CIPConvex[Region:RegionConvex::];
In the example, all regions within Region are provided in region by HAllReg (see section “HAllReg”) one after the other. The internal HALCON procedure HRLConvex2 computes the convex hull for each region and writes it to region_new. Furthermore, a new region object in the HALCON database is created and added to the output object parameter RegionConvex.
Note, that HNewRegion was also used in the example in figure 6.4.