街景字符-数据准备

  1. 根据https://tianchi.aliyun.com/notebook-ai/detail?postId=107990 链接下载数据集
  2. 利用json库读取json文件,得到如下结果
with open('./dataset/mchar_val.json','r',encoding='utf8')as fp: 
    json_data = json.load(fp) print('这是文件中的json数据:',json_data)

   3.利用opencv库函数实现数据的可视化。

全部代码如下:

import json
import cv2
img_path="./dataset/mchar_val/"
with open('./dataset/mchar_val.json','r',encoding='utf8')as fp:
    json_data = json.load(fp)
    print('这是文件中的json数据:',json_data)
    cnt=0
    #得到前5条数据并利用matplot可视化数据集
    for tmp in json_data:
        if cnt >5:
            break;
        temp_path=img_path+tmp
        img = cv2.imread(temp_path)
        cv2.namedWindow('test', cv2.WINDOW_NORMAL)
        cv2.resizeWindow('test', 1000, 1000)
        print(json_data[tmp]['label'])
        label_len=len(json_data[tmp]['label'])
        print("xxx:",json_data[tmp]['top'][0])
        for i in range(0,label_len):
            y=int(json_data[tmp]['top'][i])
            x=int(json_data[tmp]['left'][i])
            w=int(json_data[tmp]['width'][i])
            h=int(json_data[tmp]['height'][i])
            cv2.rectangle(img, (x,y),(x+w,y+h), (0, 0, 255), 1)
            cv2.putText(img, str(json_data[tmp]['label'][i]), (x-3,y-3), cv2.FONT_HERSHEY_COMPLEX_SMALL, 0.3, (255, 0, 0))
        cv2.imshow("test",img)
        key = cv2.waitKey(0)
        # if key == ord('m'):
        #     continue

        cnt+=1
    # train_label = [json_data[x]['label'] for x in json_data]
    # print(train_label)
    # print('这是读取到文件数据的数据类型:', type(json_data))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值