halcon 例程学习(方法--深度学习 异常值检 全局异常...)

该文展示了如何在Halcon环境下使用MVTecDeepLearningTool训练模型,并进行推理。通过读取图像,应用预处理参数,设置硬件(如GPU)和阈值,对图像进行分类检测。文章还涉及了异常值分类和显示检测结果的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

下面是在halcon上的推理示例

训练使用 MVTec Deep Learning Tool 22.10 (user) 工具,最后导出推理模型.

*读取图像
* Image Acquisition 02: Code generated by Image Acquisition 02
list_files ('E:/tu_en/halcon/混合', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
*for Index := 0 to |ImageFiles| - 1 by 1
*   read_image (Image, ImageFiles[Index])
    * Image Acquisition 02: Do something
*endfor


*读取训练模型

read_dl_model ('E:/tu_en/halcon/shi_li/demo1.hdl', DLModelHandle)


*设置硬件
query_available_dl_devices (['runtime', 'runtime', 'id'], ['gpu', 'cpu', 0], DLDeviceHandle)

*设置参数
set_dl_model_param (DLModelHandle, 'device', DLDeviceHandle[1])
*设置预处理参数
create_dl_preprocess_param_from_model (DLModelHandle, 'none', 'full_domain', [], [], [], DLPreprocessParam)

MaxNumInferenceImages := 10
*获取模型参数
get_dl_model_param (DLModelHandle, 'meta_data', MetaData)

*异常值 分类阈值
InferenceClassificationThreshold := number(MetaData.anomaly_classification_threshold)
*阈值下线
InferenceSegmentationThreshold := number(MetaData.anomaly_segmentation_threshold)

*分类字典
DLDatasetInfo := dict{class_names: ['ok', 'nok'], class_ids: [0, 1]}

*窗体字典
WindowDict := dict{}
*循环读取并检测
for IndexInference := 0 to |ImageFiles| - 1 by 1
    * 读取图像
    read_image (Image, ImageFiles[IndexInference])
    gen_dl_samples_from_images (Image, DLSample)
    preprocess_dl_samples (DLSample, DLPreprocessParam)
    * 分类检测
    apply_dl_model (DLModelHandle, DLSample, [], DLResult)
    * 判断阈值
    threshold_dl_anomaly_results (InferenceSegmentationThreshold, InferenceClassificationThreshold, DLResult)
    * 
    * 显示结果
    dev_display_dl_data (DLSample, DLResult, DLDatasetInfo, ['anomaly_result', 'anomaly_image'], [], WindowDict)
    dev_disp_text ('Press F5 (continue)', 'window', 'bottom', 'center', 'black', [], [])
    stop ()
endfor
dev_close_window_dict (WindowDict)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

默执_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值