-
Notifications
You must be signed in to change notification settings - Fork 0
/
BandFactory.py
42 lines (31 loc) · 1.19 KB
/
BandFactory.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
from threading import Thread
import numpy as np
from time import sleep
from ImageProcessor import getDominantColor, resizeImage
class BandFactory:
def __init__(self, maxIndex, frames = {}):
self.frames = frames
self.maxIndex = maxIndex
self.band = np.empty((1, maxIndex + 1, 3))
self.thread = None
def start(self):
self.thread = Thread(target=self.processFrames)
self.thread.start()
return self
def processFrames(self):
index = 0
while True:
print('index: ', index)
# If we're past the duration of the video, we end the method
if (index >= self.maxIndex):
break
# If frames aren't available, wait a short time before trying again
if (index not in self.frames):
sleep(0.02)
continue
frame = self.frames[index]
dominantColor = getDominantColor(resizeImage(frame, 50))
# Hydrate one column of pixel in the band with the current frame's dominant color
self.band[0, index] = np.full((1, 1, 3), dominantColor)
del self.frames[index]
index += 1