-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaybackScreenThread.py
78 lines (66 loc) · 3.23 KB
/
PlaybackScreenThread.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
import os
import glob
import cv2
# from frame_num import number
from MainScreenThread import Thread
from PySide6.QtCore import Qt, QThread, Signal, Slot,QAbstractTableModel, QPoint, QRect, QSize
from PySide6.QtGui import QAction, QImage, QKeySequence, QPixmap, QScreen
from PySide6.QtWidgets import (QApplication, QComboBox, QGroupBox,
QHBoxLayout, QLabel, QMainWindow, QPushButton,
QSizePolicy, QVBoxLayout, QWidget,QTableView,QTableWidget,
QScrollArea,QFrame, QTableWidgetItem,QProgressDialog,QRubberBand)
def number(f):
return(int(f[5:-4]))
class ScrollThread(QThread):
updatescroll = Signal(list)
def __init__(self, parent=None):
QThread.__init__(self, parent)
self.image_source = None
self.status = True
self.cap = True
self.img_formats = ('.jpg','.bmp','.jpe','.jpeg','.tif','.tiff')
self.vid_formats = ('.mp4','.avi','.mov','.wmv')
self.glob_formats = ['*.jpg','*.bmp','*.jpe','*.jpeg','*.tif','*.tiff']
def set_file(self, fname):
self.image_source = fname.text()
def run(self):
if self.image_source.lower().endswith(self.vid_formats):
cap = cv2.VideoCapture(self.image_source)
total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
for i in range(int(total_frames)):
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
ret, frame = cap.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# cv2.putText(frame,"frame #"+str(i+1),(75,75),cv2.FONT_HERSHEY_COMPLEX,4,(255,255,255),6)
frame = cv2.resize(frame,(160,120))
h, w, ch = frame.shape
img = QImage(frame.data, w, h, ch * w, QImage.Format_RGB888)
self.updatescroll.emit([img,i,total_frames])
else:
self.quit()
self.quit()
elif os.path.isdir(self.image_source):
total_frames = len([f for f_ in [glob.glob(os.path.join(self.image_source,e)) for e in self.glob_formats] for f in f_])
i = 0
try:
frames = sorted(os.listdir(self.image_source),key=number)
except ValueError:
frames = os.listdir(self.image_source)
for file in frames:
path = os.path.join(self.image_source,file)
cap = cv2.VideoCapture(path)
if file.lower().endswith(self.img_formats):
cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
ret,frame = cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# cv2.putText(frame,"frame #"+str(i+1),(75,75),cv2.FONT_HERSHEY_COMPLEX,4,(255,255,255),6)
frame = cv2.resize(frame,(160,120))
h, w, ch = frame.shape
img = QImage(frame.data, w, h, ch * w, QImage.Format_RGB888)
self.updatescroll.emit([img,i,total_frames])
i += 1
cap.release()
else:
self.quit()
self.quit()