一、编写hdev的程序并建立函数get_image_size (Image, Width, Height) gen_dl_samples_from_images (Image, DLSampleBatch) preprocess_dl_samples (DLSampleBatch, DLPreprocessParam) apply_dl_model (DLModelHandle, DLSampleBatch, [segmentation_image], DLResultBatch) get_dict_object (SegImage, DLResultBatch[0], segmentation_image) get_image_size (SegImage, SegWidth, SegHeight) * 将分割图像缩放到原图尺寸 zoom_image_size (SegImage, SegImageScaled, Width, Height, constant) return ()点击程序-建立新程序设置函数名称然后在参数选项中选择图像参数和控制参数的输入、输出二、在hdev中部调用建立的函数在hdev中调用建立的函数需要将其输入参数补全read_image(Image, E:/projects/halcon_segmentation/image-2.png) PreprocessParamFileName : E:/projects/halcon_segmentation/models/model_opt_dl_preprocess_params.hdict RetrainedModelFileName : E:/projects/halcon_segmentation/models/model_opt.hdl BatchSizeInference : 1 query_available_dl_devices ([runtime, runtime], [gpu, cpu], DLDeviceHandles) if (|DLDeviceHandles| 0) throw (No supported device found to continue this example.) endif DLDevice : DLDeviceHandles[0] read_dl_model (RetrainedModelFileName, DLModelHandle) get_dl_model_param (DLModelHandle, class_names, ClassNames) get_dl_model_param (DLModelHandle, class_ids, ClassIDs) set_dl_model_param (DLModelHandle, batch_size, BatchSizeInference) set_dl_model_param (DLModelHandle, device, DLDevice) read_dict (PreprocessParamFileName, [], [], DLPreprocessParam) seg_infer(Image, SegImageScaled, DLPreprocessParam, DLModelHandle)在python中调用设置输入参数def main(): model_params { model_path: r../models/model_opt.hdl, preprocess_params_path: r../models/model_opt_dl_preprocess_params.hdict, hdev_program_path: segment_infer.hdev, proc_name: seg_infer } # 1. 图像转换 test_image_path rE:/projects/halcon_segmentation/image-80.png if isinstance(image, str): halcon_image ha.read_image(image) else: halcon_image image # 2. 使用预加载的过程调用对象设置输入参数 hdev_proc_call.set_input_iconic_param_by_name(Image, halcon_image) hdev_proc_call.set_input_control_param_by_name(DLPreprocessParam, dl_preprocess_param) hdev_proc_call.set_input_control_param_by_name(DLModelHandle, dl_model_handle) hdev_proc_call.execute() # 3. 获取分割结果、后处理等 SegImageScaled hdev_proc_call.get_output_iconic_param_by_name(SegImageScaled)