【1】文件夹遍历
list_image_files ( : : ImageDirectory, Extensions, Options : ImageFiles)
ImageDirectory: 文件夹路径
Extensions: 文件扩展名,如'.bmp' '.jpg'
Options: 搜索选项
‘recursive’ 指定可以遍历文件夹下的文件 ‘follow_links’ 'max_depth 5' 指定遍历的深度 ImageFiles: 文件名数组,包含路径
注:另有list_files为遍历文件夹算子,可参照reference_hdevelop文档。
【2】文件筛选
tuple_regexp_select( : : Data, Expression : Selection)
Data: 文件名数组,包含路径
Expression: 文件筛选规则表达式
//. 转义 (bmp|JPG) 筛选的文件格式 ‘ignore_case’ 忽略大小写 Selection: 筛选出的文件名数组
【3】文件名拆分
parse_filename( : : FileName : BaseName, Extension, Directory)
Input parameters:
FileName: The input filename
Output parameters:
BaseName: The filename without directory description and file extension
Extension: The file extension
Directory: The directory path
- * 遍历文件夹
- list_image_files ('D:/Prostore/HDevelop/HDevelopTmp/images', 'default', [], ImageFiles)
- * 筛选bmp及jmp格式的图片
- tuple_regexp_select(ImageFiles, ['\.(bmp|jpg)$','ignore_case'], ImageFiles)
- * 打开窗口
- dev_open_window (0, 0, 512, 512, 'black', WindowHandle1)
- * 依次读取所选图片并显示 在窗口中
- for Index := 0 to |ImageFiles| - 1 by 1
- read_image (Image, ImageFiles[Index])
- dev_display(Image)
- * 分割文件名
- parse_filename(ImageFiles[Index], BaseName, Extension, Directory)
- * 保存图片,给出路径及名称,新文件名为在原文件名后添加_adj
- dump_window(WindowHandle,'bmp',Directory + BaseName + '_adj')
- stop ()
- endfor
注:程序设计过程中所用的算子的详细解释可以参照reference_hdevelop文档,该文档在Halcon安装路径下的doc文件夹中,外部函数的详细解释可以在程序编辑器函数列表中找到,函数列表中默认是main函数。
编程学习步骤:
1. 学习HDevelop示例程序。(文件—浏览HDevelop示例程序,示例程序存储在C:UsersPublicDocumentsMVTecHALCON-12.0exampleshdevelop路径下)
2. 参考reference_hdevelop文档。(更多帮助文档可在安装路径下doc文件夹中找到,本人帮助文档在D:ProgramFilesMVTecHALCON-12.0doc下)
算子、外部函数查找及学习
1. 百度HALCON实现某功能的函数或者算子;
2. 猜测算子可能包含的单词,在算子窗口中输入检索词,查看检索结果中的算子或者函数。
3. 进一步了解算子或者函数的具体功能及参数意义:算子详解可以参照reference_hdevelop文档,函数详解可以在程序编辑器函数列表中找到相应函数,然后进入该函数。