This section demonstrates how to create a simple HALCON application with C. For a more comprehensive description, see chapter “Creating Applications With HALCON/C”.
The task is to read an image and compute the number of connected regions in it, as illustrated in figure 16.1
Figure 16.1: Left: Input image of a printed circuit board. Middle: Regions found by threshold, colored red. Right: Connected regions, a result of connection.
mkdir region_example cd region_example
#include <stdio.h> #include <inttypes.h> #include <HalconC.h> int main() { Hobject img; read_image(&img, "pcb"); Hobject region; threshold(img, ®ion, 0, 122); Hobject connected_regions; connection(region, &connected_regions); Hlong num_regions = 0; count_obj(connected_regions, &num_regions); printf("Number of Regions: \%" PRIdPTR "\n", num_regions); }
For details see section “Creating Applications Under Windows” for Windows and section “Creating Applications Under Linux” for Linux.
./region_example
As a result, you should see the following output 'Number of Regions: 43'.