Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for switching image after annotation #156

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions sloth/gui/annotationscene.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, labeltool, items=None, inserters=None, parent=None):
self._scene_item = None
self._message = ""
self._labeltool = labeltool
self._switch_image_mode = False

self._itemfactory = Factory(items)
self._inserterfactory = Factory(inserters)
Expand Down Expand Up @@ -128,6 +129,11 @@ def onInserterFinished(self):
self._labeltool.exitInsertMode()
self._inserter = None

def onAnnotationFinished(self):
self._labeltool.currentImage().confirmAll()
self._labeltool.currentImage().setUnlabeled(False)
self._labeltool.gotoNext()

def onInsertionModeStarted(self, label_class):
# Abort current inserter
if self._inserter is not None:
Expand All @@ -141,6 +147,8 @@ def onInsertionModeStarted(self, label_class):
if inserter is None:
raise InvalidArgumentException("Could not find inserter for class '%s' with default properties '%s'" % (label_class, default_properties))
inserter.inserterFinished.connect(self.onInserterFinished)
if self._switch_image_mode:
inserter.annotationFinished.connect(self.onAnnotationFinished)
self._labeltool.currentImageChanged.connect(inserter.imageChange)
self._inserter = inserter
LOG.debug("Created inserter for class '%s' with default properties '%s'" % (label_class, default_properties))
Expand Down Expand Up @@ -492,3 +500,12 @@ def paint(self, painter, option, widget=None):
functools.update_wrapper(paint, oldpaint)
RectItem.paint = paint

# Switch image after annotation mode change
def switchImageMode(self, enabled):
self._switch_image_mode = enabled
if self._inserter is not None:
if enabled:
self._inserter.annotationFinished.connect(self.onAnnotationFinished)
else:
self._inserter.annotationFinished.disconnect(self.onAnnotationFinished)

11 changes: 11 additions & 0 deletions sloth/gui/labeltool.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ def onInterpolateRangeModeChanged(self):
self.interpolateRange.interpolateRange()
self.annotationMenu["Interpolate range"].setChecked(False)

def onSwitchImageModeChanged(self):
checked = self.annotationMenu["Switch image after annotation"].isChecked()
self.scene.switchImageMode(checked)

def onScaleChanged(self, scale):
self.zoominfo.setText("%.2f%%" % (100 * scale, ))

Expand Down Expand Up @@ -222,6 +226,12 @@ def initAnnotationMenu(self):
self.ui.menuAnnotation.addAction(action)
self.annotationMenu[a] = action

for a in ["Switch image after annotation"]:
action = QAction(a, self)
action.setCheckable(True)
self.ui.menuAnnotation.addAction(action)
self.annotationMenu[a] = action



###
Expand Down Expand Up @@ -343,6 +353,7 @@ def connectActions(self):
## annotation menu
self.annotationMenu["Copy from previous"].changed.connect(self.onCopyAnnotationsModeChanged)
self.annotationMenu["Interpolate range"].changed.connect(self.onInterpolateRangeModeChanged)
self.annotationMenu["Switch image after annotation"].changed.connect(self.onSwitchImageModeChanged)

def loadApplicationSettings(self):
settings = QSettings()
Expand Down