本节演示如何使用 Python 创建一个简单的 HALCON 应用程序。有关更全面的描述,参见 "使用 HALCON/Python 创建应用程序" 一章 。
任务是读取图像并计算其中的连接区域数,如 图 13.1 所示
mkdir region_example cd region_example pip install mvtec-halcon==23050
import halcon as ha if __name__ == '__main__': img = ha.read_image('pcb') region = ha.threshold(img, 0, 122) num_regions = ha.count_obj(ha.connection(region)) print(f'Number of Regions: {num_regions}')
python program.py
结果,您将看到以下输出 'Number of Regions: 43'。