From 2afa69a2e4c7b5979dbac62c2ff435c6e62445ca Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Fri, 28 Mar 2014 16:25:34 +0100 Subject: [PATCH] Make image filenames relative to the label file The image filenames written to the label files were absolute pathnames. Change this to use filenames relative to the label file. --- sloth/annotations/container.py | 6 ------ sloth/gui/labeltool.py | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sloth/annotations/container.py b/sloth/annotations/container.py index da423f5..8c33bfd 100644 --- a/sloth/annotations/container.py +++ b/sloth/annotations/container.py @@ -204,7 +204,6 @@ class PickleContainer(AnnotationContainer): """ Overwritten to write pickle files. """ - # TODO make all image filenames relative to the label file f = open(fname, "wb") pickle.dump(annotations, f) @@ -292,7 +291,6 @@ class OkapiAnnotationContainer(AnnotationContainer): fileitem.frames().push_back(frameitem) container.files().push_back(fileitem) - # TODO make all image filenames relative to the label file container.WriteToFile(fname) @@ -312,7 +310,6 @@ class JsonContainer(AnnotationContainer): """ Overwritten to write JSON files. """ - # TODO make all image filenames relative to the label file f = open(fname, "w") json.dump(annotations, f, indent=4, sort_keys=True) @@ -333,7 +330,6 @@ class YamlContainer(AnnotationContainer): """ Overwritten to write YAML files. """ - # TODO make all image filenames relative to the label file f = open(fname, "w") yaml.dump(annotations, f) @@ -398,8 +394,6 @@ class FeretContainer(AnnotationContainer): """ Not implemented yet. """ - # TODO make sure the image paths are - # relative to the label file's directory raise NotImplemented( "FeretContainer.serializeToFile() is not implemented yet." ) diff --git a/sloth/gui/labeltool.py b/sloth/gui/labeltool.py index 16ab069..036838c 100644 --- a/sloth/gui/labeltool.py +++ b/sloth/gui/labeltool.py @@ -384,6 +384,9 @@ class MainWindow(QMainWindow): fname = str(fname) + if os.path.isabs(fname): + fname = os.path.relpath(fname, str(path)) + for pattern in image_types: if fnmatch.fnmatch(fname, pattern): return self.labeltool.addImageFile(fname)