[detectionview] works on TrackingData now
This commit is contained in:
parent
2ff1af7c36
commit
0f1b1d6252
@ -3,12 +3,12 @@ import numpy as np
|
|||||||
|
|
||||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QGraphicsView, QGraphicsScene, QGraphicsEllipseItem, QGraphicsRectItem
|
from PySide6.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QGraphicsView, QGraphicsScene, QGraphicsEllipseItem, QGraphicsRectItem
|
||||||
from PySide6.QtCore import Qt, QPointF, QRectF, QPointF
|
from PySide6.QtCore import Qt, QPointF, QRectF, QPointF
|
||||||
from PySide6.QtGui import QPixmap, QBrush, QColor, QImage
|
from PySide6.QtGui import QPixmap, QBrush, QColor, QImage, QPen
|
||||||
|
|
||||||
from fixtracks.info import PACKAGE_ROOT
|
from fixtracks.info import PACKAGE_ROOT
|
||||||
from fixtracks.utils.signals import DetectionSignals, DetectionViewSignals, DetectionSceneSignals
|
from fixtracks.utils.signals import DetectionSignals, DetectionViewSignals, DetectionSceneSignals
|
||||||
from ..utils.enums import DetectionData
|
from fixtracks.utils.enums import DetectionData, Tracks
|
||||||
|
from fixtracks.utils.trackingdata import TrackingData
|
||||||
|
|
||||||
class Detection(QGraphicsEllipseItem):
|
class Detection(QGraphicsEllipseItem):
|
||||||
signals = DetectionSignals()
|
signals = DetectionSignals()
|
||||||
@ -79,6 +79,7 @@ class DetectionView(QWidget):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._img = None
|
self._img = None
|
||||||
|
self._data = None
|
||||||
self._pixmapitem = None
|
self._pixmapitem = None
|
||||||
self._scene = DetectionScene()
|
self._scene = DetectionScene()
|
||||||
# self.setRenderHint(QGraphicsView.RenderFlag.Ren Antialiasing)
|
# self.setRenderHint(QGraphicsView.RenderFlag.Ren Antialiasing)
|
||||||
@ -90,7 +91,6 @@ class DetectionView(QWidget):
|
|||||||
self._minZoom = 0.1
|
self._minZoom = 0.1
|
||||||
self._maxZoom = 10
|
self._maxZoom = 10
|
||||||
self._currentZoom = 1.0
|
self._currentZoom = 1.0
|
||||||
|
|
||||||
lyt = QVBoxLayout()
|
lyt = QVBoxLayout()
|
||||||
lyt.addWidget(self._view)
|
lyt.addWidget(self._view)
|
||||||
self.setLayout(lyt)
|
self.setLayout(lyt)
|
||||||
@ -116,6 +116,9 @@ class DetectionView(QWidget):
|
|||||||
self._view.setScene(self._scene)
|
self._view.setScene(self._scene)
|
||||||
self._view.fitInView(self._scene.sceneRect(), aspectRadioMode=Qt.AspectRatioMode.KeepAspectRatio)
|
self._view.fitInView(self._scene.sceneRect(), aspectRadioMode=Qt.AspectRatioMode.KeepAspectRatio)
|
||||||
|
|
||||||
|
def setData(self, data:TrackingData):
|
||||||
|
self._data = data
|
||||||
|
|
||||||
def clearDetections(self):
|
def clearDetections(self):
|
||||||
items = self._scene.items()
|
items = self._scene.items()
|
||||||
if items is not None:
|
if items is not None:
|
||||||
@ -124,23 +127,34 @@ class DetectionView(QWidget):
|
|||||||
self._scene.removeItem(it)
|
self._scene.removeItem(it)
|
||||||
del it
|
del it
|
||||||
|
|
||||||
def addDetections(self, coordinates:np.array, track_ids:np.array, detection_ids:np.array, frames: np.array,
|
def updateDetections(self, keypoint=-1):
|
||||||
keypoint:int, brush:QBrush):
|
self.clearDetections()
|
||||||
|
if self._data is None:
|
||||||
|
return
|
||||||
|
frames = self._data.selectedData("frame")
|
||||||
|
tracks = self._data.selectedData("track")
|
||||||
|
coordinates = self._data.coordinates(selection=True)
|
||||||
|
centercoordinates = self._data.centerOfGravity(selection=True)
|
||||||
|
userlabeled = self._data.selectedData("userlabeled")
|
||||||
|
indices = self._data.selectedData("index")
|
||||||
image_rect = self._pixmapitem.boundingRect() if self._pixmapitem is not None else QRectF(0,0,0,0)
|
image_rect = self._pixmapitem.boundingRect() if self._pixmapitem is not None else QRectF(0,0,0,0)
|
||||||
num_detections = coordinates.shape[0]
|
|
||||||
for i in range(num_detections):
|
for i, idx in enumerate(indices):
|
||||||
|
t = tracks[i]
|
||||||
|
c = Tracks.fromValue(t).toColor()
|
||||||
|
if keypoint >= 0:
|
||||||
x = coordinates[i, keypoint, 0]
|
x = coordinates[i, keypoint, 0]
|
||||||
y = coordinates[i, keypoint, 1]
|
y = coordinates[i, keypoint, 1]
|
||||||
c = brush.color()
|
else:
|
||||||
c.setAlpha(int(i * 255 / num_detections))
|
x = centercoordinates[i, 0]
|
||||||
brush.setColor(c)
|
y = centercoordinates[i, 1]
|
||||||
item = Detection(image_rect.left() + x, image_rect.top() + y, 20, 20, brush=brush)
|
|
||||||
item.setData(DetectionData.TRACK_ID.value, track_ids[i])
|
item = Detection(image_rect.left() + x, image_rect.top() + y, 20, 20, brush=QBrush(c))
|
||||||
item.setData(DetectionData.ID.value, detection_ids[i])
|
item.setData(DetectionData.TRACK_ID.value, tracks[i])
|
||||||
|
item.setData(DetectionData.ID.value, idx)
|
||||||
item.setData(DetectionData.COORDINATES.value, coordinates[i, :, :])
|
item.setData(DetectionData.COORDINATES.value, coordinates[i, :, :])
|
||||||
item.setData(DetectionData.FRAME.value, frames[i])
|
item.setData(DetectionData.FRAME.value, frames[i])
|
||||||
item = self._scene.addItem(item)
|
item = self._scene.addItem(item)
|
||||||
# logging.debug("DetectionView: Number of items in scene: %i", len(self._scene.items()))
|
|
||||||
|
|
||||||
def fit_image_to_view(self):
|
def fit_image_to_view(self):
|
||||||
"""Scale the image to fit the QGraphicsView."""
|
"""Scale the image to fit the QGraphicsView."""
|
||||||
@ -159,7 +173,7 @@ class DetectionView(QWidget):
|
|||||||
def main():
|
def main():
|
||||||
def items_selected(items):
|
def items_selected(items):
|
||||||
print("items selected")
|
print("items selected")
|
||||||
|
# FIXME The following code will no longer work...
|
||||||
import pickle
|
import pickle
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
|
Loading…
Reference in New Issue
Block a user