Created
July 5, 2018 07:23
-
-
Save yongjun823/a0eb816b75727d1aa4c621371d9a5efd to your computer and use it in GitHub Desktop.
obj bbox dataset slice
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
| from PIL import Image | |
| from pprint import pprint | |
| import xmltodict | |
| with open('pizza.xml') as fd: | |
| doc = xmltodict.parse(fd.read()) | |
| file_path = doc['annotation']['path'] | |
| main_img = Image.open(file_path) | |
| obj_arr = doc['annotation']['object'] | |
| for idx, obj in enumerate(obj_arr): | |
| pprint(obj) | |
| name_class = obj['name'] | |
| box = obj['bndbox'] | |
| img = main_img.crop((int(box['xmin']), int(box['ymin']), int(box['xmax']), int(box['ymax']))) \ | |
| .save('{}-{}.jpg'.format(name_class, idx)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment