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)//使用完成后,关闭文件,释放资源

你可能感兴趣的:(环境安装与配置,软件开发,每日学习--python,halcon)