Skip to content

Commit

Permalink
Tracking updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-endgame committed Jan 13, 2019
1 parent 9c9621c commit 6209b96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="centroid_tracker",
version="0.0.3",
version="0.0.9",
author="Ross Leitch",
author_email="[email protected]",
description="A small centroid tracker library based off https://www.pyimagesearch.com/2018/07/23/simple-object-tracking-with-opencv/",
Expand Down
20 changes: 14 additions & 6 deletions tracker/centroidtracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ class CentroidTracker():
def __init__(self, maxDisappeared=50):
self.nextObjectID = 0
self.objects = OrderedDict()
self.originRects = OrderedDict()
self.disappeared = OrderedDict()

self.maxDisappeared = maxDisappeared

def register(self, centroid):
def register(self, centroid, rect):
self.originRects[self.nextObjectID] = rect
self.objects[self.nextObjectID] = centroid
self.disappeared[self.nextObjectID] = 0
self.nextObjectID += 1

def deregister(self, objectID):
del self.originRects[objectID]
del self.objects[objectID]
del self.disappeared[objectID]

Expand All @@ -42,12 +45,12 @@ def get_id(self, rect):
def update(self, rects):

if(len(rects) == 0):
for objectID in self.disappeared.keys():
for objectID in list(self.disappeared.keys()):
self.disappeared[objectID] += 1

if(self.disappeared[objectID] > self.maxDisappeared):
self.deregister(objectID)
return self.objects
return self.objects, self.originRects

inputCentroids = np.zeros((len(rects), 2), dtype="int")

Expand All @@ -58,7 +61,9 @@ def update(self, rects):

if(len(self.objects) == 0):
for i in range(0, len(inputCentroids)):
self.register(inputCentroids[i])
centroid = inputCentroids[i]
rect = rects[i]
self.register(centroid, rect)

else:
objectIDs = list(self.objects.keys())
Expand All @@ -79,6 +84,7 @@ def update(self, rects):

objectID = objectIDs[row]
self.objects[objectID] = inputCentroids[col]
self.originRects[objectID] = rects[col]
self.disappeared[objectID] = 0

usedRows.add(row)
Expand All @@ -99,6 +105,8 @@ def update(self, rects):
else:

for col in unusedCols:
self.register(inputCentroids[col])
centroid = inputCentroids[col]
rect = rects[col]
self.register(centroid, rect)

return self.objects
return self.objects, self.originRects

0 comments on commit 6209b96

Please sign in to comment.