-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread.py
61 lines (45 loc) · 1.8 KB
/
thread.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
import time
import unittest
import cv2
from capture import VideoCapture
class VideoCaptureTest(unittest.TestCase):
def setUp(self):
print("[i] Configurando o teste.")
def _run(self, width=1280, height=720, with_threading=False):
print(f"[i] Iniciando o teste com threading={with_threading}")
if with_threading:
cap = VideoCapture("pessoas1.mp4")
else:
cap = cv2.VideoCapture("pessoas1.mp4")
# Obtém o número total de quadros do vídeo
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print(f"[i] Número total de quadros: {total_frames}")
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
if with_threading:
cap.start()
t0 = time.time()
i = 0
while i < total_frames:
grabbed, frame = cap.read()
if not grabbed:
print("[i] Nenhum quadro capturado. Saindo do loop.")
break
if frame is not None:
cv2.imshow('Frame', frame)
cv2.waitKey(1) & 0xFF
else:
print("[i] Quadro vazio detectado.")
i += 1
print('[i] Frames por segundo: {:.2f}, com threading={}'.format(total_frames / (time.time() - t0), with_threading))
if with_threading:
cap.stop()
cv2.destroyAllWindows()
def test_video_capture(self):
print("[i] Executando teste sem threading.")
self._run(1280, 720, False)
def test_video_capture_threading(self):
print("[i] Executando teste com threading.")
self._run(1280, 720, True)
if __name__ == '__main__':
unittest.main()