-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayFrames.py
executable file
·51 lines (36 loc) · 1.35 KB
/
DisplayFrames.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
#!/usr/bin/env python3
import cv2
import time
# globals
outputDir = 'frames'
frameDelay = 42 # the answer to everything
# initialize frame count
count = 0
startTime = time.time()
# Generate the filename for the first frame
frameFileName = "{}/grayscale_{:04d}.jpg".format(outputDir, count)
# load the frame
frame = cv2.imread(frameFileName)
while frame is not None:
print("Displaying frame {}".format(count))
# Display the frame in a window called "Video"
cv2.imshow("Video", frame)
# compute the amount of time that has elapsed
# while the frame was processed
elapsedTime = int((time.time() - startTime) * 1000)
print("Time to process frame {} ms".format(elapsedTime))
# determine the amount of time to wait, also
# make sure we don't go into negative time
timeToWait = max(1, frameDelay - elapsedTime)
# Wait for 42 ms and check if the user wants to quit
if cv2.waitKey(timeToWait) and 0xFF == ord("q"):
break
# get the start time for processing the next frame
startTime = time.time()
# get the next frame filename
count += 1
frameFileName = "{}/grayscale_{:04d}.jpg".format(outputDir, count)
# Read the next frame file
frame = cv2.imread(frameFileName)
# make sure we cleanup the windows, otherwise we might end up with a mess
cv2.destroyAllWindows()