-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathanalyze.py
More file actions
executable file
·44 lines (42 loc) · 1.46 KB
/
analyze.py
File metadata and controls
executable file
·44 lines (42 loc) · 1.46 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
#!/usr/bin/env python
from argparse import ArgumentParser
import cv2
import matplotlib.pyplot as plt
import numpy as np
if __name__ == '__main__':
arg_parser = ArgumentParser(description='capture video')
arg_parser.add_argument('input', help='file to read from')
options = arg_parser.parse_args()
capture = cv2.VideoCapture(options.input)
counter = 0
try:
densities = []
while True:
status, frame = capture.read()
if not status:
break
counter += 1
nr_pixels = frame.shape[0]*frame.shape[1]
red_channel = frame[:, :, 0]
green_channel = frame[:, :, 1]
blue_channel = frame[:, :, 2]
densities.append((counter,
red_channel.sum()/nr_pixels,
green_channel.sum()/nr_pixels,
blue_channel.sum()/nr_pixels))
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
densities = np.array(densities).T
plt.plot(densities[0], densities[1], 'r')
plt.plot(densities[0], densities[2], 'g')
plt.plot(densities[0], densities[3], 'b')
plt.xlabel('frame')
plt.ylabel('RGB')
plt.ylim((0, 255))
plt.show()
except KeyboardInterrupt:
capture.release()
cv2.destroyAllWindows()