Skip to content

Commit

Permalink
Merge pull request #1 from MacherLabs/dev
Browse files Browse the repository at this point in the history
mapped new detections to mapped trackers
  • Loading branch information
saurabh1993 authored Feb 26, 2020
2 parents aa933c2 + 05fd11a commit 1f4bf1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions multitracker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from kalmantracking import KalmanTracker
from multitracker import MultiTracker
from singletracker import CorrelationTracker
from .kalmantracking import KalmanTracker
from .multitracker import MultiTracker
from .singletracker import CorrelationTracker
33 changes: 22 additions & 11 deletions multitracker/multitracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from singletracker import getSingleTracker
from .singletracker import getSingleTracker
import numpy as np
from utils import *
from .utils import *
import logging
import cv2
import itertools
Expand Down Expand Up @@ -31,7 +31,7 @@ def update(self, img, detections = []):
# update_merged(mapped)
self.update_trackers_with_detections(img, detections, mapped_trackers)
# add_trackers(new)
self.add_trackers(img,new_detections)
# self.add_trackers(img,new_detections)
# remove_trackers(obselete)
self.remove_trackers(obselete_trackers)

Expand All @@ -43,8 +43,15 @@ def add_trackers(self, img, detections):
trackerID =self.new_trackerID(detection)
self.trackers[trackerID] = self.SingleTracker(trackerID, img, detection) #TODO , detection2bbox=self.detection2bbox)

def add_tracker(self, img, detection):
# Provide the tracker the initial position of the object
trackerID =self.new_trackerID(detection)
self.trackers[trackerID] = self.SingleTracker(trackerID, img, detection)
return trackerID

def update_trackers_with_detections(self,img, detections, mapped_trackers):
for trackerid,detection in mapped_trackers.items():
for trackerid,detections in mapped_trackers.items():
detection = detections['box']
self.trackers[trackerid].tracker.init(img, self.detection2bbox(detection))
self.trackers[trackerid].visible_count +=1
self.trackers[trackerid].consecutive_invisible_count = 0
Expand All @@ -57,15 +64,17 @@ def remove_trackers(self,obselete_trackers):
def merge_trackers(self, img, detections):
obselete_trackers = []
mapped_trackers = {}
new_detections = []
new_detections = {}

points = map(self.detection2bbox,detections)
#points = map(self.detection2bbox,detections)
points = detections
trackers = self.trackers

### Main Algo here
if detections:
##Calculate cost and minimize it:
Cost = np.zeros((len(points),len(trackers)))

for i,p in enumerate(points):
prect = cvbox2drectangle(p)
for j,trackerid in enumerate(trackers):
Expand All @@ -79,14 +88,16 @@ def merge_trackers(self, img, detections):
if i not in covered_points:
if Cost[i,j] > 0.5:
covered_points.append(i)
mapped_trackers[trackerid] = detections[i]
mapped_trackers[trackerid] = {"index":i,"box":detections[i]}

##Add new tracker for new detections:
for i in range(len(points)):
if i not in covered_points:
new_detections.append(detections[i])
trackerid=self.add_tracker(img,detections[i])
new_detections[trackerid] = {"index":i,"box":detections[i]}
mapped_trackers[trackerid] = {"index":i,"box":detections[i]}

##Obselete_trackers:
## Obselete_trackers:
# tracker removal by invisble_count
if self.removalConfig['invisible_count']:
invisible_count_thresh = self.removalConfig['invisible_count']
Expand All @@ -101,7 +112,7 @@ def merge_trackers(self, img, detections):
removal_thresh = self.removalConfig['overlap_thresh']
overlap_invisible_count = self.removalConfig['overlap_invisible_count']
removal_candidate_trackers = list(removal_candidate_trackers - set(obselete_trackers))
valid_trackers = removal_candidate_trackers+mapped_trackers.keys()
valid_trackers = removal_candidate_trackers+list(mapped_trackers.keys())

if valid_trackers:
valid_trackers_bbox = np.array([ trackers[idx].bbox for idx in valid_trackers]) # x,y,w,h
Expand Down Expand Up @@ -148,7 +159,7 @@ def merge_trackers(self, img, detections):
corner_check = (removal_candidate_trackers_bbox[:,0] < corner_x1 ) | (removal_candidate_trackers_bbox[:,1] < corner_x1 ) | \
(removal_candidate_trackers_bbox[:,2] > corner_x2 ) | (removal_candidate_trackers_bbox[:,3] > corner_y2 )

print corner_x1,corner_y1,corner_x2,corner_y2
#print (corner_x1,corner_y1,corner_x2,corner_y2)

# import pdb;pdb.set_trace()
for trackerid in itertools.compress(removal_candidate_trackers,corner_check):
Expand Down
2 changes: 1 addition & 1 deletion multitracker/singletracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dlib
import cv2
from utils import *
from .utils import *
# tracker = cv2.TrackerKCF_create()

# tracker = dlib.correlation_tracker()
Expand Down

0 comments on commit 1f4bf1b

Please sign in to comment.