-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProgressBar.py
120 lines (97 loc) · 4.6 KB
/
ProgressBar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#
# version 1.2 -- 2019-05-07 -- JLC --
# revision from "tracker video JLC solution".
#
# version 1.3 -- 2020-04-30 -- JLC --
# revision for using firt, last and step to loop into the images to process
#
import os
import cv2
from PyQt5.Qt import (QDialog, QLabel, QProgressBar, QPushButton,
QVBoxLayout, QHBoxLayout, QMessageBox)
from PyQt5.QtCore import Qt
from ThreadedWork import SplitVideoInImagesThread, ExtractTargetFomImagesThread
class ProgressBar(QDialog):
def __init__(self, __images_dir, parent=None):
QDialog.__init__(self, parent=parent)
self.__thread = None # l'objet QThread qui fera le calcul
self.__images_dir = __images_dir # le dossier des images
self.__images_list = None # la liste des images *.png à traiter
self.__vMin = None # la valeur min de la barre
self.__vMax = None # la valeur max de la barre
self.title = QLabel("",self)
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 250, 25)
self.btnOk = QPushButton('OK', self)
self.btnOk.clicked.connect(self.close)
self.btnOk.setEnabled(False)
self.btnCancel = QPushButton('Cancel', self)
self.btnCancel.clicked.connect(self.Cancel)
self.btnCancel.setEnabled(True)
vbox = QVBoxLayout()
vbox.addWidget(self.title)
vbox.addWidget(self.pbar)
hbox = QHBoxLayout()
hbox.addWidget(self.btnOk)
hbox.addWidget(self.btnCancel)
vbox.addLayout(hbox)
self.setLayout(vbox)
self.setModal(True)
self.setWindowModality(Qt.ApplicationModal)
self.show()
def configure_for_video_extraction(self, videoCapture, imagesFormat):
self.__vMin = 1
self.__vMax = int(videoCapture.get(cv2.CAP_PROP_FRAME_COUNT))
self.pbar.setRange(self.__vMin, self.__vMax)
self.pbar.setValue(self.__vMin)
self.setWindowTitle('Découpage de la vidéo')
self.title.setText("Extraction images : ")
self.__thread = SplitVideoInImagesThread(videoCapture,
self.__images_dir,
imagesFormat)
self.__thread.ImageExtractedSig.connect(self.updateProgressBar)
self.__thread.ImageProblemSig.connect(self.updateProgressBar)
self.__thread.start()
def configure_for_target_extraction(self,
target_RGB,
algo,
marge_couleur,
target_pos,
first_last_step):
self.__images_list = [ f for f in os.listdir(self.__images_dir) if f.endswith(".png")]
self.__images_list.sort()
self.__vMin, self.__vMax, _ = first_last_step
self.pbar.setRange(self.__vMin, self.__vMax)
self.pbar.setValue(self.__vMin)
self.setWindowTitle('Traitement des images du dossier {}'\
.format(self.__images_dir))
# Lancer un __thread pour le travil d'extraction des images de la vidéo :
self.__thread = ExtractTargetFomImagesThread(self.__images_dir,
self.__images_list,
target_RGB,
algo,
marge_couleur,
target_pos,
first_last_step)
self.__thread.TargetExtractedSig.connect(self.updateProgressBar)
self.__thread.TargetProblemSig.connect(self.updateProgressBar)
self.__thread.start()
def Cancel(self):
# Appui sur le bouton Cancel.
# Arrêter le Thread en cours :
self.__thread.quit()
# Fermer la fenêtre QDialog avec un code retour à -1 :
self.done(-1)
def updateProgressBar(self, value):
if value >= 0:
# l'image N° <value> vient d'être traitée avec succès :
self.pbar.setValue(value)
self.btnOk.setEnabled(True)
if value == 0 or value == self.pbar.maximum():
self.btnOk.setEnabled(True)
mess = "{:3d}/{:3d}".format(value,self.__vMax)
else:
# l'image N° <value> a provoqué une erreur :
mess = self.title.text()
mess += '\n Erreur image {}'.format(-value)
self.title.setText("Extraction images : " + mess)