Exemplo n.º 1
0
'''
  basicUDP.py - This is basic UDP example.
  Created by Yasin Kaya (selengalp), January 2, 2019.
  Modified by Saeed Johar (saeedjohar), October 3, 2019.
'''
from tracker import tracker
from time import sleep

node = tracker.Tracker()

#node.Sendline()
node.readNMEA()
sleep(2)

while True:
    message = node.readNMEA()
    msg = message.decode(encoding="utf-8", errors='ignore')
    #print(msg)
    msg = ""
    sleep(2)
Exemplo n.º 2
0
	def init_tracker(self,model_proto,model_weight):
		self.tracker = tracker.Tracker(model_proto,model_weight);
Exemplo n.º 3
0
def pipeline_single_tracker(det,img,otsu_box,track,draw=False):
    track.frame_count+=1
    org_im=img.copy()
    img_dim = (img.shape[1], img.shape[0])
    if debug:
        print('\nFrame:', track.frame_count,' \n')
    #Detect person in the image
    detect_box = det.get_localization(img) # measurement
    final_box=[]
    improved=False
    #check for small box
    if len(detect_box)!=0:
        detect_box=helpers.remove_small_box(detect_box[0],height_limit=150,width_limit=150)

    #If Detected
    if len(detect_box)!=0:
        if debug:
            print("Detection found")
        # detect_box=detect_box[0]
        if draw:
           img1= helpers.draw_box_label('Org Det.',img, detect_box, box_color=(255, 0, 0))
        #Tracker alive or not
        if track.current_tracker!=None:
        #If alive
            if debug:
                print("Tracker Alive")
            track_box=track.current_tracker.box
            #Track result matches,detection or not
            #------------------------------------
            #If matches
            if helpers.box_iou2(track_box,detect_box)>track.detect_track_iou_thres:

                #Check abnormal detect box
                #Abnormal, use previous box NOTE can be improved
                # detect_area=helpers.find_area(detect_box)
                # track_area=helpers.find_area(track_box)

                height_d,width_d=helpers.find_dim(detect_box)
                height_t,width_t=helpers.find_dim(track_box)
                delta=0.2
                delta2=0.3
                if height_d<(1-delta)*height_t or width_d<(1-delta)*width_t or height_d>(1+delta2)*height_t or width_d>(1+delta2)*width_t:
                    if debug:
                        print("Detection improved by tracker")
                    improved=True
                    detect_box=track.current_tracker.box
                # detect_box=helpers.union_box(track_box,detect_box)
            #Track box does not matched
            elif otsu_box==True and helpers.box_ios(detect_box,track_box)>track.box_ios_thres and helpers.box_iou2(track_box,helpers.largest_contour(img))>track.otsu_iou_thres:
                if debug:
                    print("Detect box is subset of track. Track box and Otsu are similar.")
                    print("Detection improved by tracker")
                detect_box=track.current_tracker.box
                improved=True
            else:
                if debug:
                    print("Tracker lost deleting the current tracker")
                track.tracker_list.append(track.current_tracker)
                track.current_tracker=None

        #Improve detect_box by Otsu or any other way
        if otsu_box==True:
            ret,detect_box=helpers.detection_otsu(img,detect_box,draw=True,threshold=track.otsu_iou_thres)
        #Update or create tracker
        #Update if exist or matched
        if track.current_tracker!=None:
            final_box = detect_box
            z = np.expand_dims(detect_box, axis=0).T
            track.current_tracker.kalman_filter(z)
            xx = track.current_tracker.x_state.T[0].tolist()
            xx =[xx[0], xx[2], xx[4], xx[6]]
            if improved:
                final_box = xx
            track.current_tracker.box =xx
            track.current_tracker.hits += 1
            track.current_tracker.no_losses =0
        else:
            final_box = detect_box
            z = np.expand_dims(detect_box, axis=0).T
            track.current_tracker = tracker.Tracker() # Create a new tracker
            x = np.array([[z[0], 0, z[1], 0, z[2], 0, z[3], 0]]).T
            track.current_tracker.x_state = x
            track.current_tracker.predict_only()
            xx = track.current_tracker.x_state
            xx = xx.T[0].tolist()
            xx =[xx[0], xx[2], xx[4], xx[6]]
            track.current_tracker.box =xx

            track.current_tracker.id = track.track_id_list.popleft() # assign an ID for the tracker
            if debug:
                print("New Tracker\n ID: ",track.current_tracker.id)

    #Not Detection
    else:
        #Tracker alive or not
        #alive
        if track.current_tracker!=None:
            if debug:
                print("Tracker Alive")
            track.current_tracker.predict_only()
            xx = track.current_tracker.x_state
            xx = xx.T[0].tolist()
            xx =[xx[0], xx[2], xx[4], xx[6]]

            if otsu_box==True:
            # if False:
                current_state=xx
                flag,current_otsu=helpers.tracker_otsu(img,current_state,draw=True,threshold=track.otsu_iou_thres)
                if not flag:
                    if debug:
                        print("Tracker does not matched with Otsu box, Tracker id",track.current_tracker.id)
                    xx=helpers.remove_small_box(xx,height_limit=150,width_limit=150)

                    if len(xx)==0:
                        if debug:
                            print("Small track box. Deleting...............")
                        track.tracker_list.append(track.current_tracker)
                        track.current_tracker=None
                        final_box = []
                    else:
                        track.current_tracker.no_losses+=1
                        track.current_tracker.box =xx
                        final_box = xx
                else:
                    if debug:
                        print("Tracker box matched with Otsu box, Tracker id",track.current_tracker.id)

                    track.current_tracker.no_losses += 0.5
                    final_box = current_otsu
                    current_otsu = np.expand_dims(current_otsu, axis=0).T

                    track.current_tracker.kalman_filter(current_otsu)
                    xx = track.current_tracker.x_state.T[0].tolist()
                    xx =[xx[0], xx[2], xx[4], xx[6]]

                    track.current_tracker.box =xx
            else:
                if debug:
                    print("No Otsu")
                xx=helpers.remove_small_box(xx,height_limit=150,width_limit=150)
                if len(xx)==0:
                    if debug:
                        print("Small track box. Deleting...............")
                    track.tracker_list.append(track.current_tracker)
                    track.current_tracker=None
                    final_box = []
                else:
                    track.current_tracker.no_losses += 1
                    track.current_tracker.box =xx
                    final_box = xx

            #---------------------
            #Person left the frames or not
                #If left
                #Not left, no detection
        #Not active tracker
        else:
            if debug:
                print("No tracked Box ")

    #Final box
    if track.current_tracker!=None:
        if ((track.current_tracker.hits >= min_hits) and (track.current_tracker.no_losses <=max_age)):
             # final_box = track.current_tracker.box
             if debug:
                 print('updated box: ', final_box)
                 print()
             if draw:
                 img= helpers.draw_box_label("Final",img, final_box,show_label=True) # Draw the bounding boxes on the
                 img= helpers.draw_box_label(track.current_tracker.id,img, track.current_tracker.box,box_color=(255, 255,0),show_label=False) # Draw the bounding boxes on the
        elif track.current_tracker.no_losses >max_age:
            if debug:
                print('Tracker age criteria is not satisfied. Deleting..........')
            track.tracker_list.append(track.current_tracker)
            track.current_tracker=None
        else:
            if debug:
                print('Tracker zero hit')
            if draw:
                img= helpers.draw_box_label("Final",img, final_box,show_label=True) # Draw the bounding boxes on the
    if debug:
        print("Final Box")
        print(final_box)
    return final_box,img
Exemplo n.º 4
0
def main_tracker():
    t = tracker.Tracker()
    t.run()