Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj authored and Anuj committed Aug 29, 2019
1 parent d795cff commit 3ee7c50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 13 additions & 3 deletions code/get_annot_xml.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import urllib
import json
import pandas as pd
import xml.etree.cElementTree as ET

file = '../data/indian_number_plates.json'
file = './data/indian_number_plates.json'
df = pd.read_json(file, lines=True)

df.dropna(subset=['annotation'], inplace=True)
Expand Down Expand Up @@ -32,6 +33,15 @@
ET.SubElement(bndbox, 'ymax').text = str(int(a['points'][1]['y'] * h))

tree = ET.ElementTree(root)
tree.write('../annotations/xmls/{}.xml'.format(i))

# urllib.urlretrieve(urls[i], '../images/{}.jpg'.format(i))
if not os.path.exists('./annotations/xmls'):
os.makedirs('./annotations/xmls')

file = './annotations/xmls/{}.xml'.format(i)
with open(file, 'wb') as f:
tree.write(f, encoding='utf-8')

# if not os.path.exists('./images'):
# os.makedirs('./images')

# urllib.urlretrieve(urls[i], './images/{}.jpg'.format(i))
6 changes: 3 additions & 3 deletions code/xml_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def keep_keys(old_dict):


parser = argparse.ArgumentParser(description='Convert xml Annotations to json annotations')
parser.add_argument('--xml', type=str, metavar='path/to/input/xml/', default='../annotations/xmls/', help='(default "annotations/xml/") path to xml annotations')
parser.add_argument('--json', type=str, metavar='path/to/output/json/', default='../annotations/json/', help='(default "annotations/json/") path to out json annotations')
parser.add_argument('--xml', type=str, metavar='path/to/input/xml/', default='./annotations/xmls/', help='(default "annotations/xml/") path to xml annotations')
parser.add_argument('--json', type=str, metavar='path/to/output/json/', default='./annotations/json/', help='(default "annotations/json/") path to out json annotations')

parser.print_help()
print("\n")
Expand All @@ -39,7 +39,7 @@ def keep_keys(old_dict):
json_output = json.dumps(json_dict["object"])
f.close()

f = open(os.path.join(output_directory, xml_file.replace(".xml",".json")),"wb")
f = open(os.path.join(output_directory, xml_file.replace(".xml",".json")),"w")
if json_output[0]!='[':
json_output = '['+json_output+']'
f.write(json_output)
Expand Down

0 comments on commit 3ee7c50

Please sign in to comment.