zoukankan      html  css  js  c++  java
  • HALCON初步:文件夹遍历,文件筛选,文件名拆分,图片读取及保存

    【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

    [plain] view plain copy
     
     print?
    1. * 遍历文件夹  
    2. list_image_files ('D:/Prostore/HDevelop/HDevelopTmp/images', 'default', [], ImageFiles)  
    3. * 筛选bmp及jmp格式的图片  
    4. tuple_regexp_select(ImageFiles, ['\.(bmp|jpg)$','ignore_case'], ImageFiles)  
    5. * 打开窗口  
    6. dev_open_window (0, 0, 512, 512, 'black', WindowHandle1)  
    7. * 依次读取所选图片并显示 在窗口中  
    8. for Index := 0 to |ImageFiles| - 1 by 1  
    9.     read_image (Image, ImageFiles[Index])  
    10.     dev_display(Image)  
    11.     * 分割文件名  
    12.     parse_filename(ImageFiles[Index], BaseName, Extension, Directory)  
    13.     * 保存图片,给出路径及名称,新文件名为在原文件名后添加_adj  
    14.     dump_window(WindowHandle,'bmp',Directory + BaseName + '_adj')  
    15.     stop ()  
    16. 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文档,函数详解可以在程序编辑器函数列表中找到相应函数,然后进入该函数。

  • 相关阅读:
    Lookup Method
    ReLocated Record in Grid
    Call Form By FormString
    Send Mail
    十大已亡或正在灭亡的电脑技术
    一个程序员的内心自白摘录
    数据库中null和''具体的区别
    gridview 横向显示
    Exchange2007获取OWA邮箱容量的代码
    owa实现清空邮箱的代码
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/7272149.html
Copyright © 2011-2022 走看看