[tracks] allow jumping to a given frame

This commit is contained in:
Jan Grewe 2025-02-27 16:14:48 +01:00
parent 9d38421e02
commit 15264dbe48

View File

@ -55,12 +55,21 @@ class FixTracks(QWidget):
self._keypointcombo = QComboBox() self._keypointcombo = QComboBox()
self._keypointcombo.currentIndexChanged.connect(self.on_keypointSelected) self._keypointcombo.currentIndexChanged.connect(self.on_keypointSelected)
self._gotoframe = QSpinBox()
self._gotoframe.setSingleStep(1)
self._gotobtn = QPushButton("go!")
self._gotobtn.setToolTip("Jump to a given frame")
self._gotobtn.clicked.connect(self.on_goto)
combo_layout = QHBoxLayout() combo_layout = QHBoxLayout()
combo_layout.addWidget(QLabel("Window width:")) combo_layout.addWidget(QLabel("Window width:"))
combo_layout.addWidget(self._windowspinner) combo_layout.addWidget(self._windowspinner)
combo_layout.addWidget(QLabel("frames")) combo_layout.addWidget(QLabel("frames"))
combo_layout.addWidget(QLabel("Keypoint:")) combo_layout.addWidget(QLabel("Keypoint:"))
combo_layout.addWidget(self._keypointcombo) combo_layout.addWidget(self._keypointcombo)
combo_layout.addWidget(QLabel("Jump to frame:"))
combo_layout.addWidget(self._gotoframe)
combo_layout.addWidget(self._gotobtn)
combo_layout.addItem(QSpacerItem(100, 10, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)) combo_layout.addItem(QSpacerItem(100, 10, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed))
timelinebox = QVBoxLayout() timelinebox = QVBoxLayout()
@ -210,6 +219,7 @@ class FixTracks(QWidget):
self._currentWindowPos = 0 self._currentWindowPos = 0
self._currentWindowWidth = self._windowspinner.value() self._currentWindowWidth = self._windowspinner.value()
self._maxframes = np.max(self._data["frame"]) self._maxframes = np.max(self._data["frame"])
self._gotoframe.setMaximum(self._maxframes)
self.populateKeypointCombo(self._data.numKeypoints()) self.populateKeypointCombo(self._data.numKeypoints())
self._timeline.setData(self._data) self._timeline.setData(self._data)
# self._timeline.setWindow(self._currentWindowPos / self._maxframes, # self._timeline.setWindow(self._currentWindowPos / self._maxframes,
@ -333,6 +343,16 @@ class FixTracks(QWidget):
self._timeline.setWindowWidth(self._currentWindowWidth / self._maxframes) self._timeline.setWindowWidth(self._currentWindowWidth / self._maxframes)
self._controls_widget.setSelectedTracks(None) self._controls_widget.setSelectedTracks(None)
def on_goto(self):
target = self._gotoframe.value()
if target > self._maxframes - self._currentWindowWidth:
target = self._maxframes - self._currentWindowWidth
logging.info("Jump to frame %i", target)
self._currentWindowPos = target
self._timeline.setWindow(self._currentWindowPos / self._maxframes,
self._currentWindowWidth / self._maxframes)
self.update()
def on_detectionsSelected(self, detections): def on_detectionsSelected(self, detections):
logging.debug("Tracks: %i Detections selected", len(detections)) logging.debug("Tracks: %i Detections selected", len(detections))
tracks = np.zeros(len(detections), dtype=int) tracks = np.zeros(len(detections), dtype=int)
@ -357,6 +377,10 @@ class FixTracks(QWidget):
logging.info("Tracks.moveWindow: move window with stepsize %.2f", stepsize) logging.info("Tracks.moveWindow: move window with stepsize %.2f", stepsize)
self._manualmove = True self._manualmove = True
new_start_frame = self._currentWindowPos + np.round(stepsize * self._currentWindowWidth) new_start_frame = self._currentWindowPos + np.round(stepsize * self._currentWindowWidth)
if new_start_frame < 0:
new_start_frame = 0
elif new_start_frame + self._currentWindowWidth > self._maxframes:
new_start_frame = self._maxframes - self._currentWindowWidth
self._currentWindowPos = new_start_frame self._currentWindowPos = new_start_frame
self._controls_widget.setSelectedTracks(None) self._controls_widget.setSelectedTracks(None)
self.update() self.update()