From f1a4f4dc84c3c9248094f89dc49600f1df5e2a25 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Tue, 25 Feb 2025 09:15:10 +0100 Subject: [PATCH] [tracks] disentanglement --- fixtracks/utils/signals.py | 1 + fixtracks/utils/trackingdata.py | 9 ++++----- fixtracks/widgets/classifier.py | 11 ++++++++-- fixtracks/widgets/detectiontimeline.py | 10 ++++----- fixtracks/widgets/tracks.py | 28 ++++++++++++++------------ 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/fixtracks/utils/signals.py b/fixtracks/utils/signals.py index 4346f83..d62a04c 100644 --- a/fixtracks/utils/signals.py +++ b/fixtracks/utils/signals.py @@ -22,6 +22,7 @@ class DetectionSceneSignals(QObject): class DetectionTimelineSignals(QObject): windowMoved = Signal() + manualMove = Signal() class DetectionSignals(QObject): hover = Signal((int, QPointF)) diff --git a/fixtracks/utils/trackingdata.py b/fixtracks/utils/trackingdata.py index df37168..4dcc3f0 100644 --- a/fixtracks/utils/trackingdata.py +++ b/fixtracks/utils/trackingdata.py @@ -57,7 +57,7 @@ class TrackingData(QObject): return self._selection def setSelectionRange(self, col, start, stop): - logging.debug("Trackingdata: set selection range based on column %s to %.2f - %.2f", col, start, stop) + logging.info("Trackingdata: set selection range based on column %s to %.2f - %.2f", col, start, stop) col_indices = np.where((self[col] >= start) & (self[col] < stop))[0] self._selection = self._indices[col_indices] if len(col_indices) < 1: @@ -77,10 +77,9 @@ class TrackingData(QObject): ids : array-like An array-like object containing the IDs to be set as user selections. """ - print(ids) + logging.debug("TrackingData.setSelection: %i number of ids", len(ids)) self._selection = self._find(ids) self._selected_ids = ids - print(self._selection, self._selected_ids) def setTrack(self, track_id:int, setUserLabeled:bool=True)-> None: """Assign a new track_id to the user-selected detections @@ -92,7 +91,7 @@ class TrackingData(QObject): setUserLabeled : bool Should the "userlabeled" state of the detections be set to True? Otherwise they will be left untouched. """ - print(self._selection) + logging.info("TrackingData: set track id %i for selection, set user-labeled status %s", track_id, str(setUserLabeled)) self["track"][self._selection] = track_id if setUserLabeled: self.setUserLabeledStatus(True, True) @@ -114,7 +113,7 @@ class TrackingData(QObject): else: self["userlabeled"][:] = new_status - def revertAssignmentStatus(self): + def revertUserLabeledStatus(self): logging.debug("TrackingData:Un-setting assignment status of all data!") self["userlabeled"][:] = False diff --git a/fixtracks/widgets/classifier.py b/fixtracks/widgets/classifier.py index edee355..c107d6f 100644 --- a/fixtracks/widgets/classifier.py +++ b/fixtracks/widgets/classifier.py @@ -119,6 +119,11 @@ class ConsistencyWorker(QRunnable): last_angle[assignments[i]-1] = self.orientations[idx] last_length[assignments[i]-1] += ((self.lengths[idx] - last_length[assignments[i]-1])/processed) + # self.userlabeled + + + + last_pos = [self.positions[(self.tracks == 1) & (self.frames <= self._startframe)][-1], self.positions[(self.tracks == 2) & (self.frames <= self._startframe)][-1]] last_frame = [self.frames[(self.tracks == 1) & (self.frames <= self._startframe)][-1], @@ -614,7 +619,9 @@ def main(): data = TrackingData() data.setData(as_dict(df)) coords = data.coordinates() - + cogs = data.centerOfGravity() + userlabeled = data["userlabeled"] + embed() app = QApplication([]) window = QWidget() window.setMinimumSize(200, 200) @@ -624,7 +631,7 @@ def main(): # else: w = ClassifierWidget() w.setData(data) - w.size_classifier.setCoordinates(coords) + # w.size_classifier.setCoordinates(coords) layout = QVBoxLayout() layout.addWidget(w) diff --git a/fixtracks/widgets/detectiontimeline.py b/fixtracks/widgets/detectiontimeline.py index 137d269..9b6277a 100644 --- a/fixtracks/widgets/detectiontimeline.py +++ b/fixtracks/widgets/detectiontimeline.py @@ -30,7 +30,7 @@ class Window(QGraphicsRectItem): def setWindowX(self, newx): logging.debug("timeline.window: set position to %.3f", newx) self.setX(newx) - self.signals.windowMoved.emit() + # self.signals.windowMoved.emit() def setWindowWidth(self, newwidth): logging.debug("timeline.window: update window width to %f", newwidth) @@ -38,7 +38,7 @@ class Window(QGraphicsRectItem): r = self.rect() r.setWidth(newwidth) self.setRect(r) - self.signals.windowMoved.emit() + # self.signals.windowMoved.emit() def setWindow(self, newx:float, newwidth:float): """ @@ -58,7 +58,7 @@ class Window(QGraphicsRectItem): r = self.rect() self.setRect(newx, r.y(), self._width, r.height()) self.update() - self.signals.windowMoved.emit() + # self.signals.windowMoved.emit() def mouseMoveEvent(self, event): super().mouseMoveEvent(event) @@ -77,7 +77,7 @@ class Window(QGraphicsRectItem): if r.y() != self._y: self.setY(self._y) super().mouseReleaseEvent(event) - self.signals.windowMoved.emit() + self.signals.manualMove.emit() def hoverEnterEvent(self, event): super().hoverEnterEvent(event) @@ -116,7 +116,7 @@ class DetectionTimeline(QWidget): font.setBold(True) self._window = Window(0, 0, 100, 60, window_pen, transparent_brush) - self._window.signals.windowMoved.connect(self.on_windowMoved) + self._window.signals.manualMove.connect(self.on_windowMoved) self._scene = QGraphicsScene(QRectF(0, 0, self._total_width, 85.)) self._scene.setBackgroundBrush(self._bg_brush) diff --git a/fixtracks/widgets/tracks.py b/fixtracks/widgets/tracks.py index b26d129..3cc2934 100644 --- a/fixtracks/widgets/tracks.py +++ b/fixtracks/widgets/tracks.py @@ -31,6 +31,7 @@ class FixTracks(QWidget): self._currentWindowPos = 0 # in frames self._currentWindowWidth = 0 # in frames self._maxframes = 0 + self._manualmove = False self._data = None self._detectionView = DetectionView() @@ -161,9 +162,10 @@ class FixTracks(QWidget): def update(self): start_frame = self._currentWindowPos stop_frame = start_frame + self._currentWindowWidth + self._timeline.setWindow(start_frame / self._maxframes, + self._currentWindowWidth/self._maxframes) logging.debug("Tracks:update: Updating View for detection range %i, %i frames", start_frame, stop_frame) self._data.setSelectionRange("frame", start_frame, stop_frame) - self._controls_widget.setWindow(start_frame, stop_frame) kp = self._keypointcombo.currentText().lower() kpi = -1 if "center" in kp else int(kp) @@ -208,11 +210,11 @@ class FixTracks(QWidget): self._saveBtn.setEnabled(True) self._currentWindowPos = 0 self._currentWindowWidth = self._windowspinner.value() - self._maxframes = self._data.max("frame") + self._maxframes = np.max(self._data["frame"]) self.populateKeypointCombo(self._data.numKeypoints()) self._timeline.setData(self._data) - self._timeline.setWindow(self._currentWindowPos / self._maxframes, - self._currentWindowWidth / self._maxframes) + # self._timeline.setWindow(self._currentWindowPos / self._maxframes, + # self._currentWindowWidth / self._maxframes) self._detectionView.setData(self._data) self._classifier.setData(self._data) self.update() @@ -276,7 +278,7 @@ class FixTracks(QWidget): def on_revertUserFlags(self): logging.debug("Tracks:revert ALL UserFlags and track assignments") - self._data.revertAssignmentStatus() + self._data.revertUserLabeledStatus() self._data.revertTrackAssignments() self._timeline.update() self.update() @@ -289,8 +291,10 @@ class FixTracks(QWidget): def on_windowChanged(self): logging.debug("Tracks:Timeline reports window change ") - self._currentWindowPos = np.round(self._timeline.rangeStart * self._maxframes) - self.update() + if not self._manualmove: + self._currentWindowPos = np.round(self._timeline.rangeStart * self._maxframes) + self.update() + self._manualmove = False def on_windowSizeChanged(self, value): """Reacts on the user window-width selection. Selection is done in the unit of frames. @@ -306,8 +310,7 @@ class FixTracks(QWidget): self._controls_widget.setSelectedTracks(None) def on_detectionsSelected(self, detections): - logging.debug("Tracks: Detections selected") - print(detections) + logging.debug("Tracks: %i Detections selected", len(detections)) tracks = np.zeros(len(detections), dtype=int) ids = np.zeros_like(tracks) frames = np.zeros_like(tracks) @@ -325,12 +328,11 @@ class FixTracks(QWidget): self._controls_widget.setSelectedTracks(tracks) self._skeleton.clear() self._skeleton.addSkeletons(coordinates, ids, frames, tracks, QBrush(QColor(10, 255, 65, 255))) - self.update() def moveWindow(self, stepsize): - step = np.round(stepsize * (self._currentWindowWidth)) - new_start_frame = self._currentWindowPos + step - self._timeline.setWindowPos(new_start_frame / self._maxframes) + logging.info("Tracks.moveWindow: move window with stepsize %.2f", stepsize) + self._manualmove = True + new_start_frame = self._currentWindowPos + np.round(stepsize * self._currentWindowWidth) self._currentWindowPos = new_start_frame self._controls_widget.setSelectedTracks(None) self.update()