-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputHandler.py
57 lines (40 loc) · 1.46 KB
/
InputHandler.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
import cv2 as cv
class InputHandler:
def __init__(self):
print("Created input handle")
def setInputFile(self,fileName):
self.inputSet=True
self.videoIn=cv.VideoCapture(fileName)
self.bufferZerothFrame=-1
self.buffer=[]
self.noConnectedComponents=0
self.connectedCoponentBlockSizes=[]
self.connectComponentNextFrame=[]
# readOneFrameToBuffer(self)
def readOneFrameToBuffer(self):
ret,fr=self.videoIn.read()
if ret:
self.buffer.append(fr)
self.bufferZerothFrame+=1
else:
print("ERROR!!!!")
def connectComponent(self,framesPerBlock):
#Returns the connected component ID
thisNNID=self.noConnectedComponents
self.noConnectedComponents+=1
self.connectedCoponentBlockSizes.append(framesPerBlock)
self.connectComponentNextFrame.append(0)
print("Connected NN {} with block size {}".format(thisNNID,self.connectedCoponentBlockSizes[thisNNID]))
return thisNNID
#Connected component ID
def cleanBuffer(self):
print("Dummy buffer cleaner")
def getFrameBlock(self,requesterID):
requestZerothFrame=self.connectComponentNextFrame[requesterID]
requestLastFrame=requestZerothFrame+self.connectedCoponentBlockSizes[requesterID]
while self.bufferZerothFrame+len(self.buffer) < requestLastFrame:
self.readOneFrameToBuffer()
self.cleanBuffer()
toReturn= self.buffer[requestZerothFrame-self.bufferZerothFrame:requestZerothFrame-self.bufferZerothFrame]
print("Returning {} frames".format(len(toReturn)))
return toReturn