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