-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvirtual_cam_test.py
More file actions
72 lines (57 loc) · 1.6 KB
/
virtual_cam_test.py
File metadata and controls
72 lines (57 loc) · 1.6 KB
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
from __future__ import print_function
import time
import numpy as np
from numpy import int16, uint8
DTYPE = int16
import cv2
from pydvs.virtual_cam import VirtualCam
#BEHAVE_MICROSACCADE = "SACCADE"
#BEHAVE_ATTENTION = "ATTENTION"
#BEHAVE_TRAVERSE = "TRAVERSE"
#BEHAVE_FADE = "FADE"
fps = 120
max_cycles = 1
max_frame_time = 1./fps
resolution=32
behaviour = VirtualCam.BEHAVE_MICROSACCADE
on_ms = 1000.
off_ms = on_ms*2.
vcam = VirtualCam("./mnist/t10k/", fps=fps, resolution=resolution, behaviour=behaviour,
image_on_time_ms = on_ms, inter_off_time_ms = off_ms, max_cycles=max_cycles)
valid_img = True
img = np.zeros((resolution, resolution), dtype=uint8)
ref = np.zeros((resolution, resolution), dtype=int16)
# print(vcam.image_filenames)
frame_count = 0
start_time = time.time()
prev_time = time.time()
wait_time = 0.
WINDOW_NAME = 'MNIST Images'
cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)
cv2.startWindowThread()
while True:
valid_img, img[:] = vcam.read(ref)
#ref[:] = img
if not valid_img:
if max_cycles == 1:
print("Finished the specified single cycle")
else:
print("Finished the specified %i cycles" %max_cycles)
break
cv2.imshow(WINDOW_NAME, img)
key = cv2.waitKey(10) & 0xFF
if key == ord('q') or key == ord('Q'):
break
frame_count += 1
now = time.time()
wait_time = max_frame_time - (now - prev_time)
if wait_time > 0:
time.sleep(wait_time)
if now - start_time >= 1.:
print("FPS: %d"%frame_count)
frame_count = 0
start_time = now
prev_time = time.time()
vcam.stop()
cv2.destroyAllWindows()
cv2.waitKey(1)