关于halcon imageList排序问题

halcon中读取的图像列表是按照特有的顺序排列,有时候并不是我们想要的排序,因此有时候我们想按照数字的大小,从小到大 的顺序排列,那么就需要处理一些拍讯问题.

废话不多说,排序前左边显示,经过算法排序后,右边代码显示.在这里插入图片描述
直接上代码:
设计理论,对路径进行分割,获取有效数据,替换无效数据,最终得到数字的编号,然后我们对数字进行排序,最终完成按顺序排列的目的.

filepath:=‘Grub2/’
set_system (‘filename_encoding’, ‘utf8’)
list_files (filepath, [‘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)
Num:=|ImageFiles|-1

isCreateMode:=0

//Sort Imagelist number
Image1:=ImageFiles
for n:=0 to Num-1 by 1
for k:=0 to Num-1 by 1

    str1:=Image1[k]
    str2:=Image1[k+1]
    
    //路径分割
    tuple_split (str1, '\\', Substrings1)
    index1:=|Substrings1|
    tuple_length (Substrings1[index1-1], Length1)
   //替换文件后缀--可以不要
    tuple_replace (Substrings1[index1-1], 1, '.jpg', Replaced1)
    //字符转换成数字,计算数字长度,截取固定后缀长度,得到数字编号比较
    tuple_number(Replaced1[0],String1)
    tuple_strlen (String1, Length1)
    tuple_substr (Replaced1, 0,Length1-5,Difference1)   
    
    tuple_split (str2, '\\', Substrings2)
    index2:=|Substrings2|
    tuple_length (Substrings2[index2-1], Length2)
    tuple_replace (Substrings2[index2-1], Length2, '.jpg', Replaced2)
    
    tuple_number(Replaced2[0],String2)
    tuple_strlen (String2, Length2)
    
    tuple_substr (Replaced2, 0,Length2-5,Difference2)   

    st1:=Difference1[0]
    st2:=Difference2[0]
    
    tuple_number (st1, Number1)
    tuple_number (st2, Number2)
    //排序
    tuple_greater(Number1,Number2, Greater)
    if(Greater>=1)
        
        tempFile:=Image1[k+1]
        Image1[k+1]:=Image1[k]
        Image1[k]:=tempFile
        
    endif
endfor

endfor
stop()

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值