本节演示如何使用 C++ 创建一个简单的 HALCON 应用程序。有关更全面的描述,参见 "使用 HALCON/C++ 创建应用程序" 一章 。
任务是读取图像并计算其中的连接区域数,如 图 4.1 所示
mkdir region_example cd region_example
#include <iostream> #include <HalconCpp.h> using HalconCpp::HImage; using HalconCpp::HRegion; int main() { HImage img{"pcb"}; HRegion region = img.Threshold(0, 122); Hlong numRegions = region.Connection().CountObj(); std::cout << "Number of Regions: " << numRegions << '\n'; }
详情参见 Windows 下的 "在 Windows 下创建可执行文件" 一节 和 Linux 下的 "在 Linux 下创建可执行文件" 一节 。
./region_example
结果,您将看到以下输出 'Number of Regions: 43'。