working left preview

This commit is contained in:
Jan Grewe 2024-12-22 00:06:14 +01:00
parent 5346e81ff6
commit 9449ad45ad

View File

@ -1,7 +1,7 @@
import logging import logging
from PyQt6.QtWidgets import QWidget, QGridLayout, QVBoxLayout, QLabel, QPushButton, QComboBox, QSizePolicy, QSpinBox, QGraphicsView, QGraphicsScene from PyQt6.QtWidgets import QWidget, QGridLayout, QVBoxLayout, QLabel, QPushButton, QComboBox, QSizePolicy, QSpinBox, QGraphicsView, QGraphicsScene, QGraphicsLineItem
from PyQt6.QtCore import QThreadPool, QLineF, QPointF from PyQt6.QtCore import QThreadPool, QLineF, QPointF, QRectF, Qt
from PyQt6.QtGui import QImage, QPixmap, QColor, QPen from PyQt6.QtGui import QImage, QPixmap, QColor, QPen
from fixtracks.util import ImageReader from fixtracks.util import ImageReader
@ -18,6 +18,8 @@ class MergeDetections(QWidget):
layout = QVBoxLayout() layout = QVBoxLayout()
layout.addWidget(QLabel("Merge Detections!")) layout.addWidget(QLabel("Merge Detections!"))
self.line_pen = QPen(QColor.fromString("red"), 4)
self.left_datacombo = QComboBox() self.left_datacombo = QComboBox()
self.left_videocombo = QComboBox() self.left_videocombo = QComboBox()
self.left_datacombo.addItems(self._files) self.left_datacombo.addItems(self._files)
@ -27,6 +29,7 @@ class MergeDetections(QWidget):
self.left_preview = QGraphicsView() self.left_preview = QGraphicsView()
self.left_preview.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.left_preview.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self.left_line = None self.left_line = None
self.scene = None
self.right_datacombo = QComboBox() self.right_datacombo = QComboBox()
self.right_videocombo = QComboBox() self.right_videocombo = QComboBox()
@ -45,7 +48,9 @@ class MergeDetections(QWidget):
splitter.setColumnStretch(0, 1) splitter.setColumnStretch(0, 1)
splitter.setColumnStretch(1, 1) splitter.setColumnStretch(1, 1)
layout.addLayout(splitter) layout.addLayout(splitter)
self.setLayout(layout) self.setLayout(layout)
def layout_controls(self): def layout_controls(self):
grd = QGridLayout() grd = QGridLayout()
@ -134,22 +139,33 @@ class MergeDetections(QWidget):
height, width, _ = frame.shape height, width, _ = frame.shape
bytesPerLine = 3 * width bytesPerLine = 3 * width
img = QImage(frame.data, width, height, bytesPerLine, QImage.Format.Format_BGR888).rgbSwapped() img = QImage(frame.data, width, height, bytesPerLine, QImage.Format.Format_BGR888).rgbSwapped()
scene = QGraphicsScene() self.scene = QGraphicsScene()
scene.addPixmap(QPixmap.fromImage(img).scaledToHeight(self.left_preview.height())) self._left_pixmap = self.scene.addPixmap(QPixmap.fromImage(img))
self.left_preview.setScene(scene) self.left_preview.setScene(self.scene)
self.left_preview.fitInView(self.scene.sceneRect(), mode=Qt.AspectRatioMode.KeepAspectRatio)
# self.left_preview.setPixmap(QPixmap.fromImage(img).scaledToHeight(self.left_preview.height())) # self.left_preview.setPixmap(QPixmap.fromImage(img).scaledToHeight(self.left_preview.height()))
self.left_posspinner.setMaximum(width-1) self.left_posspinner.setMaximum(width-1)
self.left_posspinner.setValue(width-1) self.left_posspinner.setValue(width-1)
origin = self.left_preview.mapToScene(int(width//2), 0) image_rect = self._left_pixmap.boundingRect()
destination = self.left_preview.mapToScene(width//2, height)
line = QLineF(origin, destination) x = self.left_posspinner.value()
p = QPen(5) start_x = image_rect.left() + x
c = QColor.fromString("red") start_y = image_rect.top()
p.setColor(c) end_y = image_rect.bottom()
self.left_line = scene.addLine(line, p)
self.left_line = self.scene.addLine(start_x, start_y, start_x, end_y, self.line_pen)
self.left_preview.show() self.left_preview.show()
def on_leftmergelinemove(self): def on_leftmergelinemove(self):
print(self.left_posspinner.value()) image_rect = self._left_pixmap.boundingRect()
if self.left_line is not None: for i in self.scene.items():
self.left_line.setX(self.left_posspinner.value()) if isinstance(i, QGraphicsLineItem):
self.scene.removeItem(i)
x = self.left_posspinner.value()
start_x = image_rect.left() + x
start_y = image_rect.top()
end_y = image_rect.bottom()
self.scene.addLine(start_x, start_y, start_x, end_y, self.line_pen)