import cv2,os
import json
def openimg():
path = '/home/yang/Documents/data/ali/SVHN/mchar_train/mchar_train/021207.png'
img = cv2.imread(path)
cv2.imshow("t",img)
cv2.waitKey(0)
def saveannotrain():
path = "mchar_train.json"
file = open(path, "r", encoding='utf-8')
fileJson = json.load(file)
lexicon_file = open("lexicon.txt", 'w')
path = '/home/yang/Documents/data/ali/SVHN/mchar_train/mchar_train/'
file = open("annotation_train.txt",'w')
index = 0
for filename in os.listdir(path):
savestr = path+filename+" "+str(index)+"\n"
file.write(savestr)
lexicon_label = map(str,fileJson[str(filename)]['label'])
lexicon_str = ''.join(lexicon_label)+"\n"
lexicon_file.write(lexicon_str)
index = index + 1
def saveannoval():
path = "val.json"
file = open(path, "r", encoding='utf-8')
fileJson = json.load(file)
lexicon_file = open("lexicon2.txt", 'w')
path = '/home/yang/Documents/data/ali/SVHN/mchar_val/mchar_val/'
file = open("annotation_val.txt",'w')
index = 30000
for filename in os.listdir(path):
savestr = path+filename+" "+str(index)+"\n"
file.write(savestr)
lexicon_label = map(str,fileJson[str(filename)]['label'])
lexicon_str = ''.join(lexicon_label)+"\n"
lexicon_file.write(lexicon_str)
index = index + 1
# saveannotrain()
# openimg()
saveannoval()