hdict文件转化为csv文件

  1. 由MVTec Deep Learning Tool工具生成hdict文件
  2. 打开Halcon:
fileName := 'D:/Data.csv'
file_exists(fileName,FileExists)//检查文件是否存在,1存在,0不存在
if(FileExists)
    delete_file (fileName)
endif
open_file(fileName,'append',FileHandle)
fwrite_string (FileHandle, 'image_id,label')
fwrite_string (FileHandle, '\n')//换行

**********【 读取标注数据:image_id、label 】***********
DLDatasetDict :='D:/4分类.hdict' //读取数据
read_dict(DLDatasetDict,[], [], DictHandle)
get_dict_tuple(DictHandle, 'samples',Tuple)

a:=|Tuple|//图像总数量
for Index := 0 to a-1 by 1
    *1.获取图像状态label
    get_dict_tuple(Tuple[Index],'image_label_id',image_label_id)
    if(image_label_id==1 or image_label_id==0)//label存在才将数据写入文件
        *2.获取图像名称
        get_dict_tuple(Tuple[Index],'image_file_name',image_id)
        tuple_split(image_id,'/', temp) //按照"/"划分数据
        image_id := temp[1] //取第二个数据作为id
        *4.写入每张图像对应的数据
        data:=image_id+','+image_label_id
        fwrite_string (FileHandle, data)
        fnew_line (FileHandle)//换行
     else
         a:=a-1//统计标注图像数量
    endif
endfor
close_file (FileHandle)//使用完成后,关闭文件,释放资源

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值