3 image_widget, a module for pymecavideo:
4 a program to track moving points
in a video frameset
6 Copyright (C) 2022 Georges Khaznadar <georgesk
@debian.org>
8 This program
is free software: you can redistribute it
and/
or modify
9 it under the terms of the GNU General Public License
as published by
10 the Free Software Foundation, either version 3 of the License,
or
11 (at your option) any later version.
13 This program
is distributed
in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License
for more details.
18 You should have received a copy of the GNU General Public License
19 along
with this program. If
not, see <http://www.gnu.org/licenses/>.
22from PyQt6.QtCore import QRect, Qt, QPointF
23from PyQt6.QtWidgets import QWidget
24from PyQt6.QtGui import QPixmap, QImage, QPainter, QPen, QColor
26class ImageWidget(QWidget):
28 Un widget contenant une image
30 Paramètres du constructeur :
31 @param parent le widget parent,
None par défaut
32 @param image une image,
None par défaut
35 def __init__(self, parent=None, image=None):
36 QWidget.__init__(self, parent)
41 définit l'image de fond
45 elif isinstance(image, QPixmap):
47 elif isinstance(image, QImage):
48 self.
image = QPixmap.fromImage(image)
54 classe dédiée, qui permet d'avoir un zoom de 100x100 px sur un détail
56 Paramètres du constructeur
57 @param app la fenêtre prncipale
58 @param parent le parent,
None par défaut
59 @param image l
'image de fonf, None par défaut
62 def __init__(self, app=None, parent=None, image=None):
63 ImageWidget.__init__(self, parent, image)
67 def setApp(self, app):
73 récupère une zone rectangulaire dans l'image affiché e
74 (dans le widget vidéo) et l'affiche grandie deux fois.
80 rect = QRect(round(p.x) - 25, round(p.y) - 25, 50, 50)
81 crop = image.copy(rect)
82 if isinstance(crop, QImage):
83 cropX2 = QPixmap.fromImage(
84 crop.scaled(100, 100, Qt.AspectRatioMode.KeepAspectRatio))
86 cropX2 = crop.scaled(100, 100, Qt.AspectRatioMode.KeepAspectRatio)
90 def paintEvent(self, event):
94 if self.
image !=
None:
95 painter.drawPixmap(0, 0, self.
image)
96 painter.setPen(QColor(
"red"))
97 painter.drawLine(50, 0, 50, 45)
98 painter.drawLine(50, 55, 50, 100)
99 painter.drawLine(0, 50, 45, 50)
100 painter.drawLine(55, 50, 100, 50)
103 painter.setPen(QPen(QColor(255, 64, 255), 1))
105 painter.drawEllipse(QPointF(50, 50), 5, 5)