本节演示如何使用 C 语言创建一个简单的 HALCON 应用程序,有关更全面的说明,参见 "使用 HALCON/C 创建应用程序" 一章。
任务是读取图像并计算其中的连接区域数,如 图 16.1 所示:
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); }
详情参见 Windows 的 "在 Windows 下创建应用程序" 一节 和 Linux 的 "在 Linux 下创建应用程序" 一节 。
./region_example
结果,您将看到以下输出 'Number of Regions: 43'。