draw_json.py 701 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. import argparse
  3. import json
  4. import matplotlib.pyplot as plt
  5. from labelme import utils
  6. def main():
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument('json_file')
  9. args = parser.parse_args()
  10. json_file = args.json_file
  11. data = json.load(open(json_file))
  12. img = utils.img_b64_to_array(data['imageData'])
  13. lbl, lbl_names = utils.labelme_shapes_to_label(img.shape, data['shapes'])
  14. captions = ['%d: %s' % (l, name) for l, name in enumerate(lbl_names)]
  15. lbl_viz = utils.draw_label(lbl, img, captions)
  16. plt.subplot(121)
  17. plt.imshow(img)
  18. plt.subplot(122)
  19. plt.imshow(lbl_viz)
  20. plt.show()
  21. if __name__ == '__main__':
  22. main()