|
@@ -17,10 +17,12 @@
|
|
# along with Labelme. If not, see <http://www.gnu.org/licenses/>.
|
|
# along with Labelme. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
#
|
|
|
|
|
|
|
|
+from base64 import b64encode, b64decode
|
|
import json
|
|
import json
|
|
import os.path
|
|
import os.path
|
|
|
|
|
|
-from base64 import b64encode, b64decode
|
|
|
|
|
|
+import six
|
|
|
|
+
|
|
|
|
|
|
class LabelFileError(Exception):
|
|
class LabelFileError(Exception):
|
|
pass
|
|
pass
|
|
@@ -40,7 +42,12 @@ class LabelFile(object):
|
|
with open(filename, 'rb') as f:
|
|
with open(filename, 'rb') as f:
|
|
data = json.load(f)
|
|
data = json.load(f)
|
|
imagePath = data['imagePath']
|
|
imagePath = data['imagePath']
|
|
- imageData = b64decode(data['imageData'])
|
|
|
|
|
|
+ if six.PY3:
|
|
|
|
+ imageData = b64decode(data['imageData']).decode('utf-8')
|
|
|
|
+ elif six.PY2:
|
|
|
|
+ imageData = b64decode(data['imageData'])
|
|
|
|
+ else:
|
|
|
|
+ raise RuntimeError('Unsupported Python version.')
|
|
lineColor = data['lineColor']
|
|
lineColor = data['lineColor']
|
|
fillColor = data['fillColor']
|
|
fillColor = data['fillColor']
|
|
shapes = ((s['label'], s['points'], s['line_color'], s['fill_color'])\
|
|
shapes = ((s['label'], s['points'], s['line_color'], s['fill_color'])\
|
|
@@ -58,11 +65,17 @@ class LabelFile(object):
|
|
lineColor=None, fillColor=None):
|
|
lineColor=None, fillColor=None):
|
|
try:
|
|
try:
|
|
with open(filename, 'wb') as f:
|
|
with open(filename, 'wb') as f:
|
|
|
|
+ if six.PY3:
|
|
|
|
+ imageData = b64encode(imageData.encode('utf-8'))
|
|
|
|
+ elif six.PY2:
|
|
|
|
+ imageData = b64encode(imageData)
|
|
|
|
+ else:
|
|
|
|
+ raise RuntimeError('Unsupported Python version.')
|
|
json.dump(dict(
|
|
json.dump(dict(
|
|
shapes=shapes,
|
|
shapes=shapes,
|
|
lineColor=lineColor, fillColor=fillColor,
|
|
lineColor=lineColor, fillColor=fillColor,
|
|
imagePath=imagePath,
|
|
imagePath=imagePath,
|
|
- imageData=b64encode(imageData)),
|
|
|
|
|
|
+ imageData=imageData),
|
|
f, ensure_ascii=True, indent=2)
|
|
f, ensure_ascii=True, indent=2)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
raise LabelFileError(e)
|
|
raise LabelFileError(e)
|
|
@@ -70,4 +83,3 @@ class LabelFile(object):
|
|
@staticmethod
|
|
@staticmethod
|
|
def isLabelFile(filename):
|
|
def isLabelFile(filename):
|
|
return os.path.splitext(filename)[1].lower() == LabelFile.suffix
|
|
return os.path.splitext(filename)[1].lower() == LabelFile.suffix
|
|
-
|
|
|