ソースを参照

Fix imagePath which should be relative to labelfile

Kentaro Wada 7 年 前
コミット
cc7ffeb84f
1 ファイル変更4 行追加4 行削除
  1. 4 4
      labelme/labelFile.py

+ 4 - 4
labelme/labelFile.py

@@ -43,12 +43,12 @@ class LabelFile(object):
         try:
             with open(filename, 'rb' if PY2 else 'r') as f:
                 data = json.load(f)
-                imagePath = data['imagePath']
                 if data['imageData'] is not None:
                     imageData = b64decode(data['imageData'])
                 else:
-                    imagePath = os.path.join(
-                        os.path.dirname(filename), data['imagePath'])
+                    # relative path from label file to relative path from cwd
+                    imagePath = os.path.join(os.path.dirname(filename),
+                                             data['imagePath'])
                     with open(imagePath, 'rb') as f:
                         imageData = f.read()
                 lineColor = data['lineColor']
@@ -57,7 +57,7 @@ class LabelFile(object):
                         for s in data['shapes'])
                 # Only replace data after everything is loaded.
                 self.shapes = shapes
-                self.imagePath = imagePath
+                self.imagePath = data['imagePath']
                 self.imageData = imageData
                 self.lineColor = lineColor
                 self.fillColor = fillColor