【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:\Users\Public\Documents\MVTec\HALCON-12.0\examples\hdevelop路徑下)
2. 參考reference_hdevelop文檔。(更多幫助文檔可在安裝路徑下doc文件夾中找到,本人幫助文檔在D:\ProgramFiles\MVTec\HALCON-12.0\doc下)
算子、外部函數查找及學習
1. 百度HALCON實現某功能的函數或者算子;
2. 猜測算子可能包含的單詞,在算子窗口中輸入檢索詞,查看檢索結果中的算子或者函數。
3. 進一步了解算子或者函數的具體功能及參數意義:算子詳解可以參照reference_hdevelop文檔,函數詳解可以在程序編輯器函數列表中找到相應函數,然后進入該函數。