Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions naturalmousetracker/detection_utils/MouseTracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class MouseTracker:
totalAllowedVis = 8
kVelocityDiff = 0.01
kHistogramDiff = 0.5

def __init__(self, startCoord, id, mask = [], frameCount = 0, width = 0, height = 0):
self.currCoord = startCoord
Expand All @@ -30,7 +29,6 @@ def __init__(self, startCoord, id, mask = [], frameCount = 0, width = 0, height
self.canDoVisual = False
self.validatedIndex = 0
self.id = id
self.histogram = None
self.lastFrameCount = 0
self.velocity = (0,0)
self.lostCounter= -1
Expand All @@ -57,23 +55,6 @@ def updatePosition(self, coordinate, mask=[], frameCount = 0, width = 0, height
if self.visualCount > MouseTracker.totalAllowedVis:
self.stopVisualTracking()

def updateHistogram(self, image, pos=False, save=True):
if not pos:
x, y, _, _, w, h, = self.currCoord
else:
x,y,w,h = pos
xmin = int(round(x - (w / 2)))
xmax = int(round(x + (w / 2)))
ymin = int(round(y - (h / 2)))
ymax = int(round(y + (h / 2)))
image = image[ymin:ymax, xmin:xmax]
hist = cv2.calcHist([image], [0], None, [16],
[0, 256])
hist = cv2.normalize(hist, hist).flatten()
if save:
self.histogram = hist
return hist

def startVisualTracking(self, frame):
self.visualTracker = cv2.TrackerCSRT_create()
if len(self.currCoord) <= 5:
Expand Down Expand Up @@ -137,6 +118,15 @@ def trimPositions(self, frameCount = 0):
def getPosition(self):
return self.currCoord

def describeSelf(self):
try:
return [self.id, self.currCoord[0], self.currCoord[1], self.currCoord[4], self.currCoord[5]]
except IndexError:
try:
return [self.id, self.currCoord[0], self.currCoord[1]]
except IndexError:
return [self.id]

def distanceFromPos(self, pos):
x1 = self.currCoord[0]
y1 = self.currCoord[1]
Expand Down Expand Up @@ -179,10 +169,6 @@ def trackLikelihood (self, pos, image):
new_vel = (pos[0] - self.currCoord[0], pos[1] - self.currCoord[1])
del_vel = np.sqrt((new_vel[0] - self.velocity[0])**2 +
(new_vel[1] - self.velocity[1])**2)
# print(self.id, 'old:', self.velocity, 'new', new_vel, 'delta', del_vel)
# new_hist = self.updateHistogram(image, pos=pos, save=False)
# del_hist = cv2.compareHist(new_hist, self.histogram, cv2.HISTCMP_BHATTACHARYYA)
# print(del_hist)
return IOU - MouseTracker.kVelocityDiff*del_vel

def tag(self):
Expand Down
Loading