zoukankan      html  css  js  c++  java
  • halcon分离路径名称

    用haclon程序将目录名分离的算法。

    ParseFileName:='F:/D705/4-20/缺陷/81.bmp'

     parse_filename(ParseFileName, BaseName, Extension, Directory)

    * This procedure gets a filename (with full path) as input
    * and returns the directory path, the base filename and the extension
    * in three different strings.
    * 
    * In the output path the path separators will be replaced
    * by '/' in all cases.
    * 
    * The procedure shows the possibilities of regular expressions in HALCON.
    * 
    * 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
    * 
    * Example:
    * basename('C:/images/part_01.png',...) returns
    * BaseName = 'part_01'
    * Extension = 'png'
    * Directory = 'C:\images\' (on Windows systems)
    * 
    * Explanation of the regular expressions:
    * 
    * '([^\\/]*?)(?:\.[^.]*)?$':
    * To start at the end, the '$' matches the end of the string,
    * so it is best to read the expression from right to left.
    * The part in brackets (?:\.[^.}*) denotes a non-capturing group.
    * That means, that this part is matched, but not captured
    * in contrast to the first bracketed group ([^\\/], see below.)
    * \.[^.]* matches a dot '.' followed by as many non-dots as possible.
    * So (?:\.[^.]*)? matches the file extension, if any.
    * The '?' at the end assures, that even if no extension exists,
    * a correct match is returned.
    * The first part in brackets ([^\\/]*?) is a capture group,
    * which means, that if a match is found, only the part in
    * brackets is returned as a result.
    * Because both HDevelop strings and regular expressions need a '\'
    * to describe a backslash, inside regular expressions within HDevelop
    * a backslash has to be written as '\\'.
    * [^\\/] matches any character but a slash or backslash ('\' in HDevelop)
    * [^\\/]*? matches a string od 0..n characters (except '/' or '\')
    * where the '?' after the '*' switches the greediness off,
    * that means, that the shortest possible match is returned.
    * This option is necessary to cut off the extension
    * but only if (?:\.[^.]*)? is able to match one.
    * To summarize, the regular expression matches that part of
    * the input string, that follows after the last '/' or '\' and
    * cuts off the extension (if any) after the last '.'.
    * 
    * '\.([^.]*)$':
    * This matches everything after the last '.' of the input string.
    * Because ([^.]) is a capturing group,
    * only the part after the dot is returned.
    * 
    * '.*[\\/]':
    * This matches the longest substring with a '/' or a '\' at the end.
    * 
    tuple_regexp_match (FileName, '.*[\\/]', DirectoryTmp)
    tuple_substr (FileName, strlen(DirectoryTmp), strlen(FileName) - 1, Substring)
    tuple_regexp_match (Substring, '([^\\/]*?)(?:\.[^.]*)?$', BaseName)
    tuple_regexp_match (Substring, '\.([^.]*)$', Extension)
    * 
    * 
    * Finally all found backslashes ('\') are converted
    * to a slash to get consistent paths
    tuple_regexp_replace (DirectoryTmp, ['\\','replace_all'], '/', Directory)
    return ()
  • 相关阅读:
    How to run a batch file each time the computer loads Windows
    go.mod file not found in current directory or any parent directory; see 'go help modules'
    xshell 所选的用户密钥未在远程主机上注册;无法加载密钥
    群起Hadoop的一个错误
    ssh: connect to host hadoop102 port 22: No route to host
    VMware下centos7配置静态ip并解决ping不通百度的问题
    虚拟机CentOS 7 网络连接显示"以太网(ens33,被拔出)"
    Rust-线程:使用消息传递在线程间传送数据
    Rust-线程,使用线程同时运行代码
    Rust-智能指针:RefCell<T>和内部可变性模式
  • 原文地址:https://www.cnblogs.com/supercxm/p/8966813.html
Copyright © 2011-2022 走看看