直接在hdevelop创建一个整体模块函数 我这里是 将get_image_size (Image, Width, Height)这个整体模块(可多选中几行创建成一个函数) 自定义设置成了test1 (Image, Width, Height)函数(含义很简单,输入Image 输出是Width, Height) 保存生成333.hdev文件 将这个文件放入python项目的对应文件夹里 调用如下: from datetime import datetime import halcon as ha class halcon0: def __init__(self): program = ha.HDevProgram('333.hdev') # 测试方法绑定 hdev文件中已经构建了一个名称为test1的函数 proc = ha.HDevProcedure.load_local(program, 'test1') self.test1_method = ha.HDevProcedureCall(proc) # test1 (Image, Width, Height) def getResult(Image): ha0.test1_method.set_input_iconic_param_by_name('Image', Image) ha0.test1_method.execute() # 执行 result_width = ha0.test1_method.get_output_control_param_by_name('Width') result_height = ha0.test1_method.get_output_control_param_by_name('Height') return result_width, result_height if __name__ == '__main__': ha0 = halcon0() Image = ha.read_image('img.png') start = datetime.now() print(start) print(getResult(Image)) end = datetime.now() print(end)
python 调用halcon的hdev文件获取函数
于 2025-06-18 11:10:46 首次发布