lst文件转json

import os, sys
import json
from myutils import *

"""
    input: image list file
    output: fake json file
"""


def read_size_file(filename):
    img_sizes = {}
    with open(filename, 'r') as fr:
        for line in fr.readlines():
            img, size = line.strip().split()
            img_sizes[img] = size
    return img_sizes


if __name__ == '__main__':
    size_file = 'pothole/v1/txt/pos_withsize.lst'
    output_file = 'json_file/pos_v1.json'

    img_sizes = read_size_file(size_file)
    data = []
    for img, size in img_sizes.items():
        info = {'filename': img,
                'filesize': size,
                'tags': 'Pothole'}
        data.append(info)
    write_json(output_file, data)
    print(len(data))

 

posted @ 2022-04-25 10:54  Tomorrow1126  阅读(62)  评论(0编辑  收藏  举报