Created
October 20, 2020 21:49
-
-
Save savan77/9cdbdf94c3942cacf35b3738b9965310 to your computer and use it in GitHub Desktop.
Crop license plates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_crops(args): | |
| tree = ET.parse(args.xml_file) | |
| root = tree.getroot() | |
| count = 0 | |
| if not os.path.exists(args.output_dir): | |
| os.makedirs(args.output_dir) | |
| for image in root.iter('image'): | |
| img = Image.open(os.path.join(args.image_dir, image.attrib['name'])) | |
| for idx, box in enumerate(image.findall('box')): | |
| cropped = img.crop((float(box.attrib['xtl']), float(box.attrib['ytl']), float(box.attrib['xbr']), float(box.attrib['ybr']))) | |
| cropped.save(os.path.join(args.output_dir, image.attrib['name'][:-4]+'_'+str(idx)+image.attrib['name'][-4:])) | |
| _ = open(os.path.join(args.output_dir, image.attrib['name'][:-4]+'_'+str(idx)+'.txt'), 'w') #empty txt file to be filled with annotations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment