fixes
This commit is contained in:
parent
1668299bcf
commit
bbd9afe841
@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
from PySide6.QtCore import Qt
|
from PySide6.QtCore import Qt
|
||||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QGraphicsView, QGraphicsScene, QGraphicsItem, QGraphicsRectItem, QGraphicsLineItem
|
from PySide6.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QGraphicsView, QGraphicsScene, QGraphicsItem, QGraphicsRectItem, QGraphicsLineItem
|
||||||
from PySide6.QtCore import Qt, QPointF, QRectF, QPointF, QRectF
|
from PySide6.QtCore import Qt, QPointF, QRectF, QPointF, QRectF
|
||||||
@ -59,14 +60,14 @@ class DetectionTimeline(QWidget):
|
|||||||
self._tracktwo = tracktwo_id
|
self._tracktwo = tracktwo_id
|
||||||
self._data = detectiondata
|
self._data = detectiondata
|
||||||
self._rangeStart = 0.0
|
self._rangeStart = 0.0
|
||||||
self._rangeStop = 1.0
|
self._rangeStop = 0.005
|
||||||
self._width = 2000
|
self._width = 2000
|
||||||
self._stepCount = 200
|
self._stepCount = 200
|
||||||
self._bg_brush = QBrush(QColor(20, 20, 20, 255))
|
self._bg_brush = QBrush(QColor(20, 20, 20, 255))
|
||||||
transparent_brush = QBrush(QColor(200, 200, 200, 64))
|
transparent_brush = QBrush(QColor(200, 200, 200, 64))
|
||||||
self._white_pen = QPen(QColor.fromString("white"))
|
self._white_pen = QPen(QColor.fromString("white"))
|
||||||
self._white_pen.setWidth(0.1)
|
self._white_pen.setWidth(0.1)
|
||||||
self._t1_pen = QPen(QColor.fromString("white"))
|
self._t1_pen = QPen(QColor.fromString("orange"))
|
||||||
self._t1_pen.setWidth(2)
|
self._t1_pen.setWidth(2)
|
||||||
self._t2_pen = QPen(QColor(0, 255, 0, 255))
|
self._t2_pen = QPen(QColor(0, 255, 0, 255))
|
||||||
self._t2_pen.setWidth(2)
|
self._t2_pen.setWidth(2)
|
||||||
@ -78,13 +79,16 @@ class DetectionTimeline(QWidget):
|
|||||||
font.setPointSize(15)
|
font.setPointSize(15)
|
||||||
font.setBold(False)
|
font.setBold(False)
|
||||||
|
|
||||||
self._scene = QGraphicsScene(QRectF(0, 0, self._width, 50.))
|
self._window = Window(self._width//2, 0, 100, 60, axis_pen, transparent_brush)
|
||||||
|
self._window.signals.windowMoved.connect(self.on_windowMoved)
|
||||||
|
|
||||||
|
self._scene = QGraphicsScene(QRectF(0, 0, self._width+1, 55.))
|
||||||
self._scene.setBackgroundBrush(self._bg_brush)
|
self._scene.setBackgroundBrush(self._bg_brush)
|
||||||
|
self._scene.addItem(self._window)
|
||||||
|
|
||||||
self._view = QGraphicsView()
|
self._view = QGraphicsView()
|
||||||
self._view.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform);
|
# self._view.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform);
|
||||||
self._view.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
self._view.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||||
self._view.fitInView(self._scene.sceneRect(), aspectRadioMode=Qt.AspectRatioMode.KeepAspectRatio)
|
|
||||||
|
|
||||||
t1_label = self._scene.addText("track 1", font)
|
t1_label = self._scene.addText("track 1", font)
|
||||||
t1_label.setDefaultTextColor(self._t1_pen.color())
|
t1_label.setDefaultTextColor(self._t1_pen.color())
|
||||||
@ -93,37 +97,51 @@ class DetectionTimeline(QWidget):
|
|||||||
t2_label.setFont(font)
|
t2_label.setFont(font)
|
||||||
t2_label.setDefaultTextColor(self._t2_pen.color())
|
t2_label.setDefaultTextColor(self._t2_pen.color())
|
||||||
t2_label.setPos(0, 17)
|
t2_label.setPos(0, 17)
|
||||||
other_label = self._scene.addText("other", font)
|
other_label = self._scene.addText("unassigned", font)
|
||||||
other_label.setFont(font)
|
other_label.setFont(font)
|
||||||
other_label.setDefaultTextColor(self._other_pen.color())
|
other_label.setDefaultTextColor(self._other_pen.color())
|
||||||
other_label.setPos(0, 30)
|
other_label.setPos(0, 30)
|
||||||
line = self._scene.addLine(0, 50, self._width, 50)
|
|
||||||
line.setPen(axis_pen)
|
|
||||||
|
|
||||||
self._window = Window(self._width//2, -5, 100, 60, axis_pen, transparent_brush)
|
|
||||||
self._window.signals.windowMoved.connect(self.on_windowMoved)
|
|
||||||
self._scene.addItem(self._window)
|
|
||||||
self._view.setScene(self._scene)
|
self._view.setScene(self._scene)
|
||||||
|
self._view.fitInView(self._scene.sceneRect(), aspectRadioMode=Qt.AspectRatioMode.KeepAspectRatio)
|
||||||
|
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
layout.addWidget(self._view)
|
layout.addWidget(self._view)
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
if self._data is not None:
|
if self._data is not None:
|
||||||
self.draw_coverage()
|
self.draw_coverage()
|
||||||
|
self.fit_scene_to_view()
|
||||||
|
self.setMaximumHeight(100)
|
||||||
|
# self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||||
|
|
||||||
def setDetectionData(self, data):
|
def setDetectionData(self, data):
|
||||||
self._data = data
|
self._data = data
|
||||||
|
for i in self._scene.items():
|
||||||
|
if isinstance(i, QGraphicsLineItem):
|
||||||
|
self._scene.removeItem(i)
|
||||||
self.draw_coverage()
|
self.draw_coverage()
|
||||||
|
|
||||||
def draw_coverage(self):
|
def draw_coverage(self):
|
||||||
|
if isinstance(self._data, pd.DataFrame):
|
||||||
maxframe = np.max(self._data.frame.values)
|
maxframe = np.max(self._data.frame.values)
|
||||||
|
|
||||||
bins = np.linspace(0, maxframe, self._stepCount)
|
bins = np.linspace(0, maxframe, self._stepCount)
|
||||||
pos = np.linspace(0, self._scene.width(), self._stepCount)
|
pos = np.linspace(0, self._scene.width(), self._stepCount)
|
||||||
track1_frames = self._data.frame.values[self._data.track == self._trackone]
|
track1_frames = self._data.frame.values[self._data.track == self._trackone]
|
||||||
track2_frames = self._data.frame.values[self._data.track == self._trackone]
|
track2_frames = self._data.frame.values[self._data.track == self._tracktwo]
|
||||||
other_frames = self._data.frame.values[(self._data.track != self._trackone) & (self._data.track != self._tracktwo)]
|
other_frames = self._data.frame.values[(self._data.track != self._trackone) &
|
||||||
|
(self._data.track != self._tracktwo)]
|
||||||
|
elif isinstance(self._data, dict):
|
||||||
|
maxframe = np.max(self._data["frame"])
|
||||||
|
bins = np.linspace(0, maxframe, self._stepCount)
|
||||||
|
pos = np.linspace(0, self._scene.width(), self._stepCount)
|
||||||
|
track1_frames = self._data["frame"][self._data["track"] == self._trackone]
|
||||||
|
track2_frames = self._data["frame"][self._data["track"] == self._tracktwo]
|
||||||
|
other_frames = self._data["frame"][(self._data["track"] != self._trackone) &
|
||||||
|
(self._data["track"] != self._tracktwo)]
|
||||||
|
else:
|
||||||
|
return
|
||||||
t1_coverage, _ = np.histogram(track1_frames, bins=bins)
|
t1_coverage, _ = np.histogram(track1_frames, bins=bins)
|
||||||
t1_coverage = t1_coverage > 0
|
t1_coverage = t1_coverage > 0
|
||||||
t2_coverage, _ = np.histogram(track2_frames, bins=bins)
|
t2_coverage, _ = np.histogram(track2_frames, bins=bins)
|
||||||
|
@ -102,7 +102,7 @@ class DetectionView(QWidget):
|
|||||||
del it
|
del it
|
||||||
|
|
||||||
def addDetections(self, coordinates:np.array, track_ids:np.array, detection_ids:np.array, brush:QBrush):
|
def addDetections(self, coordinates:np.array, track_ids:np.array, detection_ids:np.array, brush:QBrush):
|
||||||
logging.info("DetectionView: add %i detections with color %s", coordinates.shape[0], brush.color.__str__())
|
logging.debug("DetectionView: add %i detections with color", coordinates.shape[0])
|
||||||
image_rect = self._pixmapitem.boundingRect()
|
image_rect = self._pixmapitem.boundingRect()
|
||||||
for i in range(coordinates.shape[0]):
|
for i in range(coordinates.shape[0]):
|
||||||
x = coordinates[i, 0]
|
x = coordinates[i, 0]
|
||||||
@ -111,7 +111,6 @@ class DetectionView(QWidget):
|
|||||||
item.setData(0, track_ids[i])
|
item.setData(0, track_ids[i])
|
||||||
item.setData(1, detection_ids[i])
|
item.setData(1, detection_ids[i])
|
||||||
item = self._scene.addItem(item)
|
item = self._scene.addItem(item)
|
||||||
logging.info("View contains %i items", 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."""
|
||||||
|
Loading…
Reference in New Issue
Block a user