From 8d11958b4618cad6a41bdc4382f4b1963c30ca22 Mon Sep 17 00:00:00 2001 From: LaraStuStu Date: Sat, 28 Mar 2020 14:02:33 +0800 Subject: [PATCH] Create testing.py --- DataAnnotation/labelme/labelme/testing.py | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 DataAnnotation/labelme/labelme/testing.py diff --git a/DataAnnotation/labelme/labelme/testing.py b/DataAnnotation/labelme/labelme/testing.py new file mode 100644 index 0000000..587298e --- /dev/null +++ b/DataAnnotation/labelme/labelme/testing.py @@ -0,0 +1,25 @@ +import json +import os.path as osp + +import labelme.utils + + +def assert_labelfile_sanity(filename): + assert osp.exists(filename) + + data = json.load(open(filename)) + + assert 'imagePath' in data + imageData = data.get('imageData', None) + if imageData is None: + assert osp.exists(data['imagePath']) + img = labelme.utils.img_b64_to_arr(imageData) + + H, W = img.shape[:2] + assert 'shapes' in data + for shape in data['shapes']: + assert 'label' in shape + assert 'points' in shape + for x, y in shape['points']: + assert 0 <= x <= W + assert 0 <= y <= H -- GitLab