3 echelle, a module for pymecavideo:
4 a program to track moving points
in a video frameset
6 Copyright (C) 2007 Jean-Baptiste Butet <ashashiwa
@gmail.com>
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/>.
25from PyQt6.QtCore import QThread, pyqtSignal, QLocale, QTranslator, Qt, QSize, QTimer, QObject, QRect
26from PyQt6.QtGui import QKeySequence, QIcon, QPixmap, QImage, QPainter, QShortcut, QColor, QCursor
27from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QLayout, QFileDialog, QTableWidgetItem, QInputDialog, QLineEdit, QMessageBox, QTableWidgetSelectionRange
29from vecteur import vecteur
30from globdef import cible_icon
32class echelle(QObject):
33 def __init__(self, p1=vecteur(0, 0), p2=
vecteur(0, 0)):
34 self.p1, self.
p2 = p1, p2
41 donne une vision partielle de l'instance courante
43 return f
"echelle(p1 = {self.p1}, p2 = {self.p2}, longueur_reelle_etalon = {self.longueur_reelle_etalon})"
47 @return vrai si l
'échelle a été faite
49 return self.p1 != self.
p2 and (self.p1 - self.
p2).norme > 1
54 def longueur_pixel_etalon(self):
55 return (self.p1 - self.
p2).norme
59 Vrai si l'échelle n'est pas définie, c
'est à dire si
60 p1 et p2 sont confondus.
65 """renvoie le nombre de mètre par pixel"""
72 """renvoie le nombre de pixel par mètre"""
80 Définit la longueur en mètre de l'étalon
81 @param l longueur en mètre
89 Widget qui permet de définir l'échelles
91 Paramètres du constructeur :
92 @param parent le widget video
93 @param pw widget principal de l
'onglet pointage
94 @param app pointeur vers l
'application
101 def __init__(self, parent, pw):
102 QWidget.__init__(self, parent)
108 QRect(0, 0, self.
video.image_w, self.
video.image_h))
111 self.setAutoFillBackground(
False)
115 cible_pix = QPixmap(cible_icon).scaledToHeight(32)
116 cible_cursor = QCursor(cible_pix)
117 self.setCursor(cible_cursor)
119 self.setMouseTracking(
True)
123 def paintEvent(self, event):
124 if self.
p1.x <= 0
or self.
p2.x <= 0:
return
128 painter.setPen(QColor(
"red"))
129 painter.drawLine(round(self.
p1.x), round(self.
p1.y),
130 round(self.
p2.x), round(self.
p2.y))
134 def mousePressEvent(self, event):
135 if event.button() != Qt.MouseButton.LeftButton:
138 self.
p1 =
vecteur(qPoint = event.position())
142 def mouseMoveEvent(self, event):
143 p =
vecteur(qPoint = event.position())
144 self.
pw.update_zoom.emit(p)
150 def mouseReleaseEvent(self, event):
151 p =
vecteur(qPoint = event.position())
153 if event.button() == Qt.MouseButton.LeftButton
and self.
p1.x >= 0:
155 self.
pw.echelle_image.p1 = self.
p1.copy()
156 self.
pw.echelle_image.p2 = self.
p2.copy()
158 self.
pw.affiche_echelle()
159 self.
app.affiche_statut.emit(self.tr(
"Échelle définie"))
160 self.
pw.echelle_modif.emit(self.tr(
"Refaire l'échelle"),
"background-color:orange;")
161 self.
pw.index_du_point = 0
163 self.
pw.feedbackEchelle()
164 self.
app.stopRedimensionnement.emit()
166 self.
app.affiche_statut.emit(self.tr(
167 "Vous pouvez continuer votre acquisition"))
168 self.
app.coord.recalculLesCoordonnees()
171 self.
pw.apres_echelle.emit()
176 Un widget transparent qui sert seulement à tracer l'échelle
178 Paramètres du constructeur :
179 @param parent un videoWidget
180 @param p1 origine de l
'étalon
181 @param p2 extrémité de l
'étalon
183 def __init__(self, parent, p1, p2):
184 QWidget.__init__(self, parent)
188 QRect(0, 0, self.
video.image_w, self.
video.image_h))
189 self.setAutoFillBackground(
False)
192 self.setMouseTracking(
True)
196 QRect(0, 0, self.
video.image_w, self.
video.image_h))
198 def paintEvent(self, event):
199 if self.
p1.x <= 0
or self.
p2.x <= 0:
return
203 painter.setPen(QColor(
"green"))
204 painter.drawLine(round(self.
p1.x), round(self.
p1.y),
205 round(self.
p2.x), round(self.
p2.y))
def pxParM(self)
renvoie le nombre de pixel par mètre
def longueur_pixel_etalon(self)
def etalonneReel(self, l)
Définit la longueur en mètre de l'étalon.
def __str__(self)
donne une vision partielle de l'instance courante
def mParPx(self)
renvoie le nombre de mètre par pixel
def isUndef(self)
Vrai si l'échelle n'est pas définie, c'est à dire si p1 et p2 sont confondus.
une classe pour des vecteurs 2D ; les coordonnées sont flottantes, et on peut accéder à celles-ci par...