forked from jeffshih/countSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainApp.py
More file actions
91 lines (69 loc) · 2.99 KB
/
mainApp.py
File metadata and controls
91 lines (69 loc) · 2.99 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import numpy
from Generator import detGenerator, detectionResult
from Util import *
from trackerManager import trackerManager
from Point import Point
from detectionParser import detectionParser
from config import *
class mainProgram(object):
def __init__(self, imgSize=resolution):
self.objectCount = 0
self.width = imgSize.w
self.width = imgSize.h
self.detParser = detectionParser()
self.detectionSequence = {}
self.momTracker = trackerManager()
self.countingResult = {}
def initWithData(self, detRes:list):
self.detectionSequence = self.detParser.getDetSequence(transform(detRes))
def doCounting(self):
for frameNum, dets in self.detectionSequence.items():
self.momTracker.update(dets)
messages,renderData = self.momTracker.predict()
for trkId, msg in messages.items():
print("At frameNum: {}, captured type {} with confidence {:.4f}".\
format(frameNum, msg.catagory, msg.confidence))
def genCountingResult(self):
for frameNum, dets in self.detectionSequence.items():
self.momTracker.update(dets)
messages, renderData = self.momTracker.predict()
self.countingResult[frameNum] = []
for trkId, msg in messages.items():
self.countingResult[frameNum].append(msg.catagory)
self.momTracker.reset()
return self.countingResult
def printSequence(self):
for frameNum, dets in self.detectionSequence.items():
print(frameNum, len(dets))
def printTrackerHistory(self):
for frameNum, dets in self.detectionSequence.items():
self.momTracker.update(dets)
messages,renderData = self.momTracker.predict()
trackerHistory = self.momTracker.getTrackerHistory()
transpose = {}
colors = {}
for idx, history in trackerHistory.items():
transpose[history.frameNum]=history.rects
colors[history.frameNum] = history.colors
for frameNum, rectsPair in transpose.items():
backGround = np.zeros((720, 1080, 3), np.uint8)
backGround[:,:,:] = (255,255,255)
for id, rects in rectsPair.items():
for idx, rect in enumerate(rects):
color = colors[frameNum][id]
renderRectWithColor(rect,backGround,color)
renderTextUnderRect(rect,backGround,idx,color)
cv2.imshow("blank", backGround)
k = cv2.waitKey(0)
if k == 'n':
continue
elif k == 27: #escape key
break
if __name__ == "__main__":
detGen = detGenerator(minObj=5, maxObj=10,framenum=100)
res = detGen.getDetectionRes()
App = mainProgram()
App.initWithData(res)
#print(res)
App.doCounting()
#App.printTrackerHistory()