Ver código fonte

Fixed bug in draw_json and json_to_dataset

Justin Ellis 7 anos atrás
pai
commit
7fcfe69e0d
2 arquivos alterados com 23 adições e 2 exclusões
  1. 13 1
      labelme/cli/draw_json.py
  2. 10 1
      labelme/cli/json_to_dataset.py

+ 13 - 1
labelme/cli/draw_json.py

@@ -2,8 +2,13 @@
 
 import argparse
 import json
+import os
+import sys
+import base64
 import matplotlib.pyplot as plt
 
+PY2 = sys.version_info[0] == 2
+
 from labelme import utils
 
 
@@ -16,7 +21,14 @@ def main():
 
     data = json.load(open(json_file))
 
-    img = utils.img_b64_to_arr(data['imageData'])
+    if data['imageData'] is not None:
+        imageData = data['imageData']
+    else:
+        imagePath = os.path.join(os.path.dirname(json_file), data['imagePath'])
+        with open(imagePath, 'rb') as f:
+            imageData = f.read()
+            imageData = base64.b64encode(imageData).decode('utf-8')
+    img = utils.img_b64_to_arr(imageData)
 
     label_name_to_value = {'_background_': 0}
     for shape in data['shapes']:

+ 10 - 1
labelme/cli/json_to_dataset.py

@@ -2,6 +2,7 @@ import argparse
 import json
 import os
 import os.path as osp
+import base64
 import warnings
 
 import PIL.Image
@@ -32,7 +33,15 @@ def main():
 
     data = json.load(open(json_file))
 
-    img = utils.img_b64_to_arr(data['imageData'])
+    if data['imageData'] is not None:
+        imageData = data['imageData']
+    else:
+        imagePath = os.path.join(os.path.dirname(json_file), data['imagePath'])
+        with open(imagePath, 'rb') as f:
+            imageData = f.read()
+            imageData = base64.b64encode(imageData).decode('utf-8')
+
+    img = utils.img_b64_to_arr(imageData)
 
     label_name_to_value = {'_background_': 0}
     for shape in data['shapes']: