|
29 | 29 | from labelme.widgets import ToolBar |
30 | 30 | from labelme.widgets import UniqueLabelQListWidget |
31 | 31 | from labelme.widgets import ZoomWidget |
| 32 | +from labelme.widgets import StepsizeWidget |
32 | 33 |
|
33 | 34 | from labelme.trackerre3 import Tracker, trackerAutoAnnotate, trackerInit, trackerDetectFlags, trackerFindGlobalOffset |
34 | 35 |
|
@@ -82,6 +83,7 @@ def __init__( |
82 | 83 | # Whether we need to save or not. |
83 | 84 | self.dirty = False |
84 | 85 | self.image_skip = int(self._config['image_skip']) |
| 86 | + self.autoMode = False |
85 | 87 |
|
86 | 88 | self._noSelectionSlot = False |
87 | 89 |
|
@@ -164,6 +166,7 @@ def __init__( |
164 | 166 | self.file_dock.setWidget(fileListWidget) |
165 | 167 |
|
166 | 168 | self.zoomWidget = ZoomWidget() |
| 169 | + self.stepsizeWidget = StepsizeWidget(value=self.image_skip) |
167 | 170 |
|
168 | 171 | self.canvas = self.labelList.canvas = Canvas( |
169 | 172 | epsilon=self._config['epsilon'], |
@@ -381,6 +384,12 @@ def __init__( |
381 | 384 | self.tr('Automatically annotate all object instances visible'), |
382 | 385 | enabled=False) |
383 | 386 |
|
| 387 | + startStopAutoMode = action(self.tr('StartStopAutoMode'), self.startStopAutoMode, |
| 388 | + shortcuts['startStopAutoMode'], 'icon', |
| 389 | + self.tr('Automatically annotate the whole video'), |
| 390 | + enabled=False, |
| 391 | + checkable=True) |
| 392 | + |
384 | 393 | undo = action(self.tr('Undo'), self.undoShapeEdit, |
385 | 394 | shortcuts['undo'], 'undo', |
386 | 395 | self.tr('Undo last add and edit of shape'), |
@@ -415,6 +424,15 @@ def __init__( |
415 | 424 | ) |
416 | 425 | self.zoomWidget.setEnabled(False) |
417 | 426 |
|
| 427 | + stepsize = QtWidgets.QWidgetAction(self) |
| 428 | + stepsize.setDefaultWidget(self.stepsizeWidget) |
| 429 | + self.stepsizeWidget.setWhatsThis( |
| 430 | + self.tr( |
| 431 | + 'Skip size for iteration through Image.' |
| 432 | + ) |
| 433 | + ) |
| 434 | + self.stepsizeWidget.setEnabled(True) |
| 435 | + |
418 | 436 | zoomIn = action(self.tr('Zoom &In'), |
419 | 437 | functools.partial(self.addZoom, 1.1), |
420 | 438 | shortcuts['zoom_in'], 'zoom-in', |
@@ -504,6 +522,8 @@ def __init__( |
504 | 522 | createLineStripMode=createLineStripMode, |
505 | 523 | zoom=zoom, zoomIn=zoomIn, zoomOut=zoomOut, zoomOrg=zoomOrg, |
506 | 524 | fitWindow=fitWindow, fitWidth=fitWidth, |
| 525 | + startStopAutoMode=startStopAutoMode, |
| 526 | + stepsize=stepsize, |
507 | 527 | zoomActions=zoomActions, |
508 | 528 | openNextImg=openNextImg, openPrevImg=openPrevImg, openseg=openseg, |
509 | 529 | increase_blend=increase_blend, decrease_blend=decrease_blend, |
@@ -553,6 +573,7 @@ def __init__( |
553 | 573 | createLineStripMode, |
554 | 574 | editMode, |
555 | 575 | autoAnnotate, |
| 576 | + startStopAutoMode, |
556 | 577 | ), |
557 | 578 | onShapesPresent=(saveAs, hideAll, showAll), |
558 | 579 | ) |
@@ -652,6 +673,8 @@ def __init__( |
652 | 673 | zoomOut, |
653 | 674 | fitWindow, |
654 | 675 | fitWidth, |
| 676 | + startStopAutoMode, |
| 677 | + stepsize, |
655 | 678 | ) |
656 | 679 |
|
657 | 680 | self.statusBar().showMessage(self.tr('%s started.') % __appname__) |
@@ -725,12 +748,16 @@ def __init__( |
725 | 748 |
|
726 | 749 | # Callbacks: |
727 | 750 | self.zoomWidget.valueChanged.connect(self.paintCanvas) |
| 751 | + self.stepsizeWidget.valueChanged.connect(self.stepsizeChanged) |
728 | 752 |
|
729 | 753 | self.populateModeActions() |
730 | 754 |
|
731 | 755 | # self.firstStart = True |
732 | 756 | # if self.firstStart: |
733 | 757 | # QWhatsThis.enterWhatsThisMode() |
| 758 | + if self._config['auto_run']: |
| 759 | + logger.info('Auto Run Engaged') |
| 760 | + self.queueEvent(functools.partial(self.autoRun)) |
734 | 761 |
|
735 | 762 | def menu(self, title, actions=None): |
736 | 763 | menu = self.menuBar().addMenu(title) |
@@ -799,6 +826,7 @@ def setClean(self): |
799 | 826 | self.actions.createPointMode.setEnabled(True) |
800 | 827 | self.actions.createLineStripMode.setEnabled(True) |
801 | 828 | self.actions.autoAnnotate.setEnabled(True) |
| 829 | + self.actions.startStopAutoMode.setEnabled(True) |
802 | 830 | title = __appname__ |
803 | 831 | if self.filename is not None: |
804 | 832 | title = '{} - {}'.format(title, self.filename) |
@@ -1508,6 +1536,17 @@ def loadFile(self, filename=None, reset=True): |
1508 | 1536 | flags.update(self.labelFile.flags) |
1509 | 1537 | self.loadFlags(flags) |
1510 | 1538 |
|
| 1539 | + if self.autoMode and self.tracker_dict and self._config['freeze_key_frames'] and len(self.canvas.shapes)>0: |
| 1540 | + #this frame has annotated labels - we treat it as a key frame and do not change it |
| 1541 | + self.stop_tracker() |
| 1542 | + if self.autoMode and self._config['freeze_key_frames'] and len(self.canvas.shapes)>0: |
| 1543 | + logger.info('Auto Run encountered keyframe %s'%self.filename) |
| 1544 | + selected_shapes=[] |
| 1545 | + for shape in self.canvas.shapes: |
| 1546 | + selected_shapes.append(shape) |
| 1547 | + self.canvas.selectShapes(selected_shapes) |
| 1548 | + self.start_tracker() |
| 1549 | + |
1511 | 1550 | if self.tracker_dict: |
1512 | 1551 | otrack_shapes=[] |
1513 | 1552 | for shape in prev_shapes: |
@@ -2098,3 +2137,44 @@ def autoAnnotate(self): |
2098 | 2137 | self.loadShapes(track_shapes, replace=False) |
2099 | 2138 | self.setDirty() |
2100 | 2139 |
|
| 2140 | + def startStopAutoMode(self): |
| 2141 | + if self.autoMode: |
| 2142 | + self.actions.startStopAutoMode.setChecked(False) |
| 2143 | + self.autoMode = False |
| 2144 | + logger.info('Auto Run Stopped') |
| 2145 | + else: |
| 2146 | + if not self.mayContinue(): |
| 2147 | + return |
| 2148 | + self.actions.startStopAutoMode.setChecked(True) |
| 2149 | + self.autoMode = True |
| 2150 | + logger.info('Auto Run Started') |
| 2151 | + self.queueEvent(functools.partial(self.autoStep)) |
| 2152 | + |
| 2153 | + def stepsizeChanged(self): |
| 2154 | + self.image_skip=int(self.stepsizeWidget.value()) |
| 2155 | + |
| 2156 | + def autoStep(self): |
| 2157 | + if self.autoMode: |
| 2158 | + if len(self.imageList) <= 0 or self.filename == self.imageList[-1]: |
| 2159 | + self.autoMode = False |
| 2160 | + self.actions.startStopAutoMode.setChecked(False) |
| 2161 | + if self._config['auto_run']: |
| 2162 | + self.queueEvent(functools.partial(self.autoRunFin)) |
| 2163 | + |
| 2164 | + else: |
| 2165 | + logger.info('Auto Run: %s'%self.filename) |
| 2166 | + self._openNextImg(skip=self.image_skip) |
| 2167 | + self.queueEvent(functools.partial(self.autoStep)) |
| 2168 | + |
| 2169 | + def autoRun(self): |
| 2170 | + selected_shapes=[] |
| 2171 | + for shape in self.canvas.shapes: |
| 2172 | + selected_shapes.append(shape) |
| 2173 | + if len(selected_shapes): |
| 2174 | + self.canvas.selectShapes(selected_shapes) |
| 2175 | + self.actions.toggle_tracker.toggle() |
| 2176 | + self.start_tracker() |
| 2177 | + self.startStopAutoMode() |
| 2178 | + |
| 2179 | + def autoRunFin(self): |
| 2180 | + self.close() |
0 commit comments