From d463adaece39c1797d8d372790b5f2beff063224 Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Tue, 14 Jun 2011 09:23:57 +0200 Subject: [PATCH] Load images via LabelTool/Container --- sloth/annotations/container.py | 2 +- sloth/core/labeltool.py | 4 ++++ sloth/gui/annotationscene.py | 6 ++++-- sloth/gui/labeltool.py | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sloth/annotations/container.py b/sloth/annotations/container.py index 8f5e09a..577f355 100644 --- a/sloth/annotations/container.py +++ b/sloth/annotations/container.py @@ -14,7 +14,7 @@ try: import yaml except: pass - +import okapy class AnnotationContainerFactory: def __init__(self, containers): diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 2e8d549..763a854 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -172,6 +172,10 @@ class LabelTool(QObject): self._current_image = image self.currentImageChanged.emit(self._current_image.index()) + def getImage(self, item): + # TODO: Also handle video frames + self.container_.loadImage(item.filename()) + def getAnnotationFilePatterns(self): return self.container_factory_.patterns() diff --git a/sloth/gui/annotationscene.py b/sloth/gui/annotationscene.py index 5941198..234e4c7 100644 --- a/sloth/gui/annotationscene.py +++ b/sloth/gui/annotationscene.py @@ -13,7 +13,7 @@ class AnnotationScene(QGraphicsScene): # TODO signal itemadded - def __init__(self, items=None, inserters=None, parent=None): + def __init__(self, labeltool, items=None, inserters=None, parent=None): super(AnnotationScene, self).__init__(parent) self.model_ = None @@ -22,6 +22,7 @@ class AnnotationScene(QGraphicsScene): self.debug_ = True self.message_ = "" self.last_key_ = None + self.labeltool_ = labeltool self.itemfactory_ = Factory(items) self.inserterfactory_ = Factory(inserters) @@ -79,7 +80,8 @@ class AnnotationScene(QGraphicsScene): return assert self.root_.model() == self.model_ - self.image_ = self.root_.data(ImageRole).toPyObject() + item = self.model_.itemFromIndex(root) + self.image_ = self.labeltool_.getImage(item) self.pixmap_ = QPixmap(okapy.guiqt.toQImage(self.image_)) item = QGraphicsPixmapItem(self.pixmap_) item.setZValue(-1) diff --git a/sloth/gui/labeltool.py b/sloth/gui/labeltool.py index c7f3a25..0a8d25b 100755 --- a/sloth/gui/labeltool.py +++ b/sloth/gui/labeltool.py @@ -91,7 +91,7 @@ class MainWindow(QMainWindow): def setupGui(self): self.ui = uic.loadUi(os.path.join(GUIDIR, "labeltool.ui"), self) - self.scene = AnnotationScene(items=config.ITEMS, inserters=config.INSERTERS) + self.scene = AnnotationScene(self.labeltool, items=config.ITEMS, inserters=config.INSERTERS) self.view = GraphicsView(self) self.view.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.view.setScene(self.scene)