diff --git a/doc/api/inserters.rst b/doc/api/inserters.rst new file mode 100644 index 0000000..3752fc9 --- /dev/null +++ b/doc/api/inserters.rst @@ -0,0 +1,21 @@ +========= +Inserters +========= + +This details the default inserters that come with sloth. + +The following inserters are available in :mod:`sloth.items`: + +.. module:: sloth.items + +.. autoclass:: PointItemInserter + :members: + :undoc-members: + +.. autoclass:: RectItemInserter + :members: + :undoc-members: + +.. .. autoclass:: PolygonItemInserter + :members: + :undoc-members: diff --git a/doc/api/labeltool.rst b/doc/api/labeltool.rst index 830235f..af90b9d 100644 --- a/doc/api/labeltool.rst +++ b/doc/api/labeltool.rst @@ -11,4 +11,5 @@ It provides the following API: .. autoclass:: LabelTool :members: + :undoc-members: diff --git a/sloth/bin/sloth b/sloth/bin/sloth index fab991a..5000459 100755 --- a/sloth/bin/sloth +++ b/sloth/bin/sloth @@ -1,7 +1,6 @@ #!/usr/bin/env python import sys from PyQt4.QtGui import QApplication -from sloth.gui import MainWindow from sloth.core.labeltool import LabelTool from sloth import APP_NAME, ORGANIZATION_NAME, ORGANIZATION_DOMAIN @@ -14,9 +13,5 @@ if __name__ == '__main__': labeltool = LabelTool() labeltool.execute_from_commandline(sys.argv) - wnd = MainWindow(labeltool) - labeltool._mainwindow = wnd - wnd.show() - sys.exit(app.exec_()) diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 12c9245..e3f6f92 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -15,6 +15,7 @@ from sloth.core.cli import LaxOptionParser, BaseCommand from sloth.core.utils import import_callable from sloth import VERSION from sloth.core.commands import get_commands +from sloth.gui import MainWindow import logging LOG = logging.getLogger(__name__) @@ -156,6 +157,13 @@ class LabelTool(QObject): else: self.clearAnnotations() + # Setup GUI + self._mainwindow = MainWindow(self) + self._mainwindow.show() + + # Load plugins + self.loadPlugins(config.PLUGINS) + def fetch_command(self, subcommand): """ Tries to fetch the given subcommand, printing a message with the @@ -192,9 +200,6 @@ class LabelTool(QObject): # Instatiate container factory self.container_factory_ = AnnotationContainerFactory(config.CONTAINERS) - # Load plugins - self.loadPlugins(config.PLUGINS) - def loadPlugins(self, plugins): self.plugins_ = [] for plugin in plugins: @@ -339,6 +344,12 @@ class LabelTool(QObject): self._model._root.appendFileItem(fileitem) + ### + ### GUI functions + ###___________________________________________________________________________________________ + def mainWindow(self): + return self._mainwindow + ### ### PropertyEditor functions ###___________________________________________________________________________________________ diff --git a/sloth/items/factory.py b/sloth/items/factory.py index 0043be9..d3b8195 100644 --- a/sloth/items/factory.py +++ b/sloth/items/factory.py @@ -32,8 +32,6 @@ class Factory: item: python callable or string Reference to the callable which creates the new object. """ - _type = _type.lower() - if _type in self.items_ and not replace: raise Exception("Type %s already has an item: %s" % \ (_type, str(self.items_[_type]))) @@ -55,7 +53,6 @@ class Factory: if _type is None: self.items_ = {} else: - _type = _type.lower() if _type in self.items_: del self.items_[_type] @@ -76,8 +73,6 @@ class Factory: Newly created object. If for the given type no mapping exists, this function returns ``None``. """ - _type = str(_type).lower() - if _type not in self.items_: return None item = self.items_[_type] diff --git a/sloth/plugins/facedetector.py b/sloth/plugins/facedetector.py index 34647d9..5492dac 100644 --- a/sloth/plugins/facedetector.py +++ b/sloth/plugins/facedetector.py @@ -1,47 +1,47 @@ -from sloth.annotations.model import ImageRole from PyQt4.QtGui import * from PyQt4.QtCore import * +from sloth.annotations.model import ImageModelItem from okapy import BinaryPatternFaceDetector class Worker(QThread): valueChanged = pyqtSignal(int) - def __init__(self, n_images, model, det): + def __init__(self, labeltool, det): QThread.__init__(self) - self.n_images = n_images - self.model = model - self.det = det - self.canceled = False + self.labeltool = labeltool + self.model = labeltool.model() + self.det = det + self.canceled = False def cancel(self): self.canceled = True def run(self): - for i in range(self.n_images): - index = self.model.index(i, 0) - item = self.model.itemFromIndex(index) - img = item.data(index, ImageRole) + for i, item in enumerate(self.model.iterator(ImageModelItem)): + print i, item + img = self.labeltool.getImage(item) faces = self.det.detectFaces(img) + print faces for face in faces: ann = { - 'type': 'rect', - 'class': 'face', - 'x': face.box.x, - 'y': face.box.y, - 'width': face.box.width, - 'height': face.box.height, - 'confidence': face.conf, + 'class': 'face', + 'x': face.box.x, + 'y': face.box.y, + 'width': face.box.width, + 'height': face.box.height, + 'det_conf': face.conf, } - self.model.addAnnotation(index, ann) + item.addAnnotation(ann) self.valueChanged.emit(i+1) if self.canceled: return class FaceDetectorPlugin(QObject): - def __init__(self, wnd): - QObject.__init__(self, wnd) - self.wnd_ = wnd - self.sc_ = QAction("Detect faces", wnd) - self.sc_.triggered.connect(self.doit) + def __init__(self, labeltool): + QObject.__init__(self) + self._labeltool = labeltool + self._wnd = labeltool.mainWindow() + self._sc = QAction("Detect faces", self._wnd) + self._sc.triggered.connect(self.doit) self.progress = None self.thread = None @@ -54,21 +54,21 @@ class FaceDetectorPlugin(QObject): self.progress.hide() self.progress = None self.thread = None - self.sc_.setEnabled(True) + self._sc.setEnabled(True) def doit(self): det = BinaryPatternFaceDetector("/cvhci/data/mctcascades/new-detectors/face_frontal_new.xml") - self.sc_.setEnabled(False) - model = self.wnd_.model_ + self._sc.setEnabled(False) + model = self._labeltool.model() n_images = model.rowCount() - self.progress = QProgressDialog("Detecting faces...", "Abort", 0, n_images, self.wnd_); + self.progress = QProgressDialog("Detecting faces...", "Abort", 0, n_images, self._wnd); self.progress.setWindowModality(Qt.WindowModal) self.progress.show() - self.thread = Worker(n_images, model, det) + self.thread = Worker(self._labeltool, det) self.progress.canceled.connect(self.thread.cancel) self.thread.finished.connect(self.on_finished) self.thread.valueChanged.connect(self.on_valueChanged) self.thread.start() def action(self): - return self.sc_ + return self._sc