SynthText -datasets数据集解析(python实现)

这个数据集不用我多介绍了,(名气很大)但网上的却很少有这方面的资料(介绍数据集的格式)在这里推荐一下这位博主的解析(很感谢他的帮助)他的博客写的很详细,如果有对格式不懂的可以参考一下他的博文
链接:https://blog.csdn.net/nevergiveupyou/article/details/106438936#comments_12399162
下面是解析gt.mat的python代码:

def convert2txt(path):
    """
    :param path:
    :return:
    """
    # 该函数加载mat文件返回一个字典
    data = sio.loadmat(path)

    # # 图像的绝对地址
    # abs_path = data["imnames"][0]
    # # 获取bbox的位置信息(所有图片的)
    # coordinate = data["wordBB"][0]
    # # 获取注释(字符、文本标注)
    # string_anns = data["txt"][0]
    # print()
    # # 使用循环获取每一张图像以及其坐标信息核标注
    # for i in  range(len(data['txt'][0])):
    # 还需要一个循环,将所有的gt值遍历出来
    train_file = open('E:/download/datasets/data/train.txt', 'w')
    print("开始写入")
    for i in range(len(data['txt'][0])):

        for val in data['txt'][0][i]:
            # 去掉换行符号和空格
            v = [x.split("\n") for x in val.strip().split(" ")]

        # sys.stderr返回错误信息
        # print(sys.stderr, "No.{} data".format(i))
        rec = np.array(data['wordBB'][0][i], dtype=np.int32)
        if len(rec.shape) == 3:
            rec = rec.transpose([2, 1, 0])
        else:
            rec = rec.transpose([1, 0])[np.newaxis, :]
        # 将每一个矩形框的坐标值写入到txt文件
        for j in range(len(rec)):
            x1 = rec[j][0][0]
            y1 = rec[j][0][1]
            x2 = rec[j][1][0]
            y2 = rec[j][1][1]
            x3 = rec[j][2][0]
            y3 = rec[j][2][1]
            x4 = rec[j][3][0]
            y4 = rec[j][3][1]

            train_file.write(str(data['imnames'][0][i][0]) + "," + str(x1) + "," + str(y1) + "," + str(x2) + "," + str(
                y2) + "," + str(x3) + "," + str(y3) + "," + str(x4) + "," + str(y4)
                             + "," + str(v[0][:]) + "\n")
convert2txt("E:/QLDownloadGame/SynthText -datasets/detection/gt.mat")

这里的坐标是按顺时针写入的

你可能感兴趣的:(深度学习,opencv,python,深度学习)