Ejemplo n.º 1
0
def track_viou_matlab_wrapper(
    frames_path,
    detections,
    sigma_l,
    sigma_h,
    sigma_iou,
    t_min,
    ttl,
    tracker_type,
    keep_upper_height_ratio=1.0,
):
    """
    Matlab wrapper of the v-iou tracker for the detrac evaluation toolkit.

    Args:
         detections (numpy.array): numpy array of detections, usually supplied by run_tracker.m
         sigma_l (float): low detection threshold.
         sigma_h (float): high detection threshold.
         sigma_iou (float): IOU threshold.
         t_min (float): minimum track length in frames.

    Returns:
        float: speed in frames per second.
        list: list of tracks.
    """

    detections = detections.reshape((7, -1)).transpose()
    dets = load_mot(detections, with_classes=False)
    start = time()
    tracks = track_viou(
        frames_path + "img{:05d}.jpg",
        dets,
        sigma_l,
        sigma_h,
        sigma_iou,
        int(t_min),
        int(ttl),
        tracker_type,
        keep_upper_height_ratio,
    )
    end = time()

    id_ = 1
    out = []
    for track in tracks:
        for i, bbox in enumerate(track["bboxes"]):
            out += [
                float(bbox[0]),
                float(bbox[1]),
                float(bbox[2] - bbox[0]),
                float(bbox[3] - bbox[1]),
                float(track["start_frame"] + i),
                float(id_),
            ]
        id_ += 1

    num_frames = len(dets)
    speed = num_frames / (end - start)

    return speed, out
Ejemplo n.º 2
0
def track_iou_matlab_wrapper(detections, sigma_l, sigma_h, sigma_iou, t_min):
    """
    Matlab wrapper of the iou tracker for the detrac evaluation toolkit.

    Args:
         detections (numpy.array): numpy array of detections, usually supplied by run_tracker.m
         sigma_l (float): low detection threshold.
         sigma_h (float): high detection threshold.
         sigma_iou (float): IOU threshold.
         t_min (float): minimum track length in frames.

    Returns:
        float: speed in frames per second.
        list: list of tracks.
    """

    detections = detections.reshape((7, -1)).transpose()
    dets = load_mot(detections)
    start = time()
    tracks = track_iou(dets, sigma_l, sigma_h, sigma_iou, t_min)
    end = time()

    id_ = 1
    out = []
    for track in tracks:
        for i, bbox in enumerate(track['bboxes']):
            out += [float(bbox[0]), float(bbox[1]), float(bbox[2] - bbox[0]), float(bbox[3] - bbox[1]),
                    float(track['start_frame'] + i), float(id_)]
        id_ += 1

    num_frames = len(dets)
    speed = num_frames / (end - start)

    return speed, out
Ejemplo n.º 3
0
    def info_callback(self, info):            
        bbox = np.empty((0,5), float) #bbox라는 한 객체를 담는 객체 생성

        # 모든 message data를 객체마다 bbox에 저장
        for i in range( len(info.centerX) ):
            bbox = np.append(bbox, [[info.box_left[i], info.box_top[i], info.box_right[i], info.box_bottom[i], info.conf[i]]], axis=0)

        detection = load_mot(bbox) # bbox로부터 데이터 읽은 후 id부여해서 return     
        self.pre_tracker, self.img_tracks = track_iou( self.pre_tracker, detection) 
Ejemplo n.º 4
0
def tracker(args, detections):
    '''runs a detection, object-oriented version of demo.py'''
    #might need to add nms to load_mot
    dets = load_mot(detections, with_classes=0)
    print('\t[-] Track with Intersection over Union')
    tracks = track_iou(dets, args.sigma_l, args.sigma_h, args.sigma_iou,
                       args.t_min)
    print('\t[-] Format Tracks')
    tracks = build_array2(tracks, fmt=args.fmt)
    return tracks
Ejemplo n.º 5
0
def main(args):
    detections = load_mot(args.detection_path)

    start = time()
    tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou, args.t_min)
    end = time()

    num_frames = len(detections)
    print("finished at " + str(int(num_frames / (end - start))) + " fps!")

    save_to_csv(args.output_path, tracks)
Ejemplo n.º 6
0
def main(args):
    detections = load_mot(args.detection_path)

    start = time()
    tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou,
                       args.t_min)
    end = time()

    num_frames = len(detections)
    print("finished at " + str(int(num_frames / (end - start))) + " fps!")

    save_to_csv(args.output_path, tracks)
Ejemplo n.º 7
0
def main(args):
    formats = ["motchallenge", "visdrone"]
    assert (
        args.format
        in formats), "format '{}' unknown supported formats are: {}".format(
            args.format, formats)

    with_classes = False
    if args.format == "visdrone":
        with_classes = True
    detections = load_mot(
        args.detection_path,
        nms_overlap_thresh=args.nms,
        with_classes=with_classes,
        min_short=args.min_short,
        max_short=args.max_short,
        max_long=args.max_long,
    )

    if args.visual:
        tracks = track_viou(
            args.frames_path,
            detections,
            args.sigma_l,
            args.sigma_h,
            args.sigma_iou,
            args.t_min,
            args.ttl,
            args.visual,
            args.keep_upper_height_ratio,
        )
    else:
        if with_classes:
            # track_viou can also be used without visual tracking, but note that the speed will be much slower compared
            # to track_iou. However, this way supports the optimal LAP solving and the handling of multiple object classes:
            tracks = track_viou(
                args.frames_path,
                detections,
                args.sigma_l,
                args.sigma_h,
                args.sigma_iou,
                args.t_min,
                args.ttl,
                "NONE",
                args.keep_upper_height_ratio,
            )
        else:
            tracks = track_iou(detections, args.sigma_l, args.sigma_h,
                               args.sigma_iou, args.t_min)

    save_to_csv(args.output_path, tracks, fmt=args.format)
Ejemplo n.º 8
0
def main(datasetPath):
    if 'Fluo-N2DL-HeLa' in datasetPath:
        mode = 'Fluo-N2DL-HeLa'
    elif 'PhC-C2DL-PSC' in datasetPath:
        mode = 'PhC-C2DL-PSC'
    else:
        mode = 'DIC-C2DH-HeLa'
    detPath = datasetPath.replace(r'/', '_') + '.txt'
    detAbsPath = os.path.join('det', detPath)
    genDets(datasetPath, mode)
    print('loading detections...')
    detections = load_mot(detAbsPath,
                          nms_overlap_thresh=cfg.nms,
                          with_classes=False)
    print('tracking...')
    tracks = track_iou(detections, cfg.sigma_l, cfg.sigma_h, cfg.sigma_iou,
                       cfg.t_min, cfg.max_missing)
    save_to_csv(os.path.join(cfg.output_path, detPath), tracks, fmt=cfg.format)
Ejemplo n.º 9
0
def main(args):
    with open(args.seqmap) as fd:
        seqs = [line.rstrip('\n') for line in fd]

    for idx, seq in enumerate(seqs):
        if seq == "name" or seq == "":
            continue
        else:
            if "DPM" in seq:
                sigma_l = -0.5
                sigma_h = 0.5
                sigma_iou = 0.4
                t_min = 4
            elif "FRCNN" in seq:
                sigma_l = 0.0
                sigma_h = 0.9
                sigma_iou = 0.3
                t_min = 3
            elif "SDP" in seq:
                sigma_l = 0.4
                sigma_h = 0.5
                sigma_iou = 0.2
                t_min = 2
            else:
                print("No detector name found, this could happen with the "
                      "wrong seqmap seqmap file. "
                      "Please use c10-train.txt, c10-test.txt or c10-all.txt")
                exit()

            # Take the pre-computed detections.
            det_path = args.benchmark_dir + "/" + seq + "/det/det.txt"
            out_path = args.res_dir + "/" + seq + ".txt"

            detections = load_mot(det_path)

            start = time()
            tracks = track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min)
            end = time()

            num_frames = len(detections)
            print("finished " + seq + " at " +
                  str(int(num_frames / (end - start))) + " fps!")

            save_to_csv(out_path, tracks)
Ejemplo n.º 10
0
    def callback(self, image, info):
        try:
            cv_image = self.bridge.imgmsg_to_cv2(image, "bgr8")
        except CvBridgeError as e:
            print(e)

        bbox = np.empty((0, 5), float)

        for i in range(len(info.centerX)):
            bbox = np.append(bbox, [[
                info.box_left[i], info.box_top[i], info.box_right[i],
                info.box_bottom[i], info.conf[i], info.distance[i]
            ]],
                             axis=0)

        detection = load_mot(bbox)

        # print("detection")
        # print(detection)
        # for i in range(len(detection)):
        #     print("detection["+str(i)+"]")
        #     print(detection[i])

        self.pre_tracker, tracks = track_iou(self.pre_tracker, detection, 0.3)

        if tracks is "wait":
            print("wait")
        elif tracks is None and self.get_age() >= 5:
            print("실패")
        elif tracks is None and self.get_age() < 5:
            self.set_age(1)
            print("aging")
        else:
            self.set_age(0)
            print("성공")

            blue_color = (255, 0, 0)

            cv.rectangle(cv_image,
                         (int(tracks['bbox'][0]), int(tracks['bbox'][1])),
                         (int(tracks['bbox'][2]), int(tracks['bbox'][3])),
                         blue_color, 3)
            control_msg = self.bridge.cv2_to_imgmsg(cv_image, "bgr8")
            self.control_pub.publish(control_msg)
Ejemplo n.º 11
0
def main(args):
    with open(args.seqmap) as fd:
        seqs = [line.rstrip('\n') for line in fd]

    for idx, seq in enumerate(seqs):
        if seq == "name" or seq == "":
            continue
        else:
            if "DPM" in seq:
                sigma_l = -0.5
                sigma_h = 0.5
                sigma_iou = 0.4
                t_min = 4
            elif "FRCNN" in seq:
                sigma_l = 0.0
                sigma_h = 0.9
                sigma_iou = 0.3
                t_min = 3
            elif "SDP" in seq:
                sigma_l = 0.4
                sigma_h = 0.5
                sigma_iou = 0.2
                t_min = 2
            else:
                print("No detector name found, this could happen with the wrong seqmap seqmap file. "
                      "Please use c10-train.txt, c10-test.txt or c10-all.txt")
                exit()

            det_path = args.benchmark_dir + "/" + seq + "/det/det.txt"
            out_path = args.res_dir + "/" + seq + ".txt"

            detections = load_mot(det_path)

            start = time()
            tracks = track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min)
            end = time()

            num_frames = len(detections)
            print("finished " + seq + " at " + str(int(num_frames / (end - start))) + " fps!")

            save_to_csv(out_path, tracks)
Ejemplo n.º 12
0
def main(args):
    print('loading detections...')
    det_path = os.path.expanduser('~/') + args.detection_path
    detections = load_mot(det_path)

    print('tracking...')
    start = time()
    tracks = track_iou(detections, args.sigma_l, args.sigma_h, args.sigma_iou,
                       args.t_min)
    end = time()
    print("Finished Tracking", tracks)
    num_frames = len(detections)
    print("finished at " + str(int(num_frames / (end - start))) + " fps!")

    orig_out_path = os.path.expanduser('~/') + args.output_path
    save_to_csv(orig_out_path, tracks)

    out_path = os.path.expanduser('~/') + args.output_path + 'ordredfrm'
    if args.frameorder:
        #reading in all the data again for re-formatting
        idorder_frameorder(orig_out_path, out_path)
Ejemplo n.º 13
0
def track_iou_matlab_wrapper(detections, sigma_l, sigma_iou, sigma_p, sigma_len, skip_frames=False, n_skip=3):
    """
    Matlab wrapper of the iou tracker for the detrac evaluation toolkit.

    Args:
         detections (numpy.array): numpy array of detections, usually supplied by run_tracker.m
         sigma_l (float): low detection threshold.
         sigma_iou (float): IOU threshold.
         sigma_p (int): maximum frames a track remains pending before termination.
         sigma_len (int): minimum track length in frames.
         skip_frames (boolean): whether to skip some frames to speed up tracking.
         n_skip (int): when skip_frames is True, the tracker uses only one out of every n_skip frames for tracking.

    Returns:
        float: speed in frames per second.
        list: list of tracks.
    """

    detections = detections.reshape((7, -1)).transpose()
    detections = load_mot(detections)
    start = time()
    tracks = track_iou(detections, sigma_l, sigma_iou, sigma_p, sigma_len, skip_frames, n_skip)
    end = time()

    id_ = 1
    out = []
    for track in tracks:
        for tracklet in track:
            out += [float(tracklet['roi'][1]), float(tracklet['roi'][0]), float(tracklet['roi'][3] - tracklet['roi'][1]), float(tracklet['roi'][2] - tracklet['roi'][0]), float(tracklet['frame']), float(id_)]
        id_ += 1

    num_frames = len(detections)

    # this part occasionally throws ZeroDivisionError when evaluated in the DETRAC toolkit without the except clause 
    try:
        speed = num_frames / (end - start)
    except:
        speed = num_frames / 0.1

    return speed, out
Ejemplo n.º 14
0
def main(args):
    with open(args.seqmap) as fd:
        seqs = [line.rstrip('\n') for line in fd]

    for idx, seq in enumerate(seqs):
        if seq == "name" or seq == "":
            continue
        else:
            det_path = args.benchmark_dir + "/" + seq + "/det/det.txt"
            out_path = args.res_dir + "/" + seq + ".txt"

            detections = load_mot(det_path, with_classes=False)

            start = time()
            tracks = track_iou(detections, args.sigma_l, args.sigma_h,
                               args.sigma_iou, args.t_min)
            end = time()

            num_frames = len(detections)
            print("finished " + seq + " at " +
                  str(int(num_frames / (end - start))) + " fps!")

            save_to_csv(out_path, tracks)
Ejemplo n.º 15
0
from iou_tracker import Tracker
from util import load_mot, save_to_csv

DETS_PATH = "./MOT17/train/MOT17-04-SDP/det/det.txt"
detections = load_mot(DETS_PATH)
tracker = Tracker()
tracks = {}
for frame, detection in enumerate(detections, start=1):
    track = tracker.track(detection)
    tracks[frame] = track
Ejemplo n.º 16
0
def main(args):

    time_iou = 0
    time_ext = 0
    time_merge = 0
    time_ttl = 0

    with open(args.seqmap) as fd:
        seqs = [line.rstrip('\n') for line in fd]

    for idx, seq in enumerate(seqs):
        print(seq)
        if seq == "name" or seq == "":
            continue
        else:
            if "DPM" in seq:
                sigma_l = -0.5
                sigma_h = 0.5
                sigma_iou = 0.5
                t_min = 4
            elif "FRCNN" in seq:
                sigma_l = 0.0
                sigma_h = 0.9
                sigma_iou = 0.4
                t_min = 3
            elif "SDP" in seq:
                sigma_l = 0.4
                sigma_h = 0.5
                sigma_iou = 0.3
                t_min = 2
            else:
                sigma_l = -0.5  # default -0.5
                sigma_h = 0.5  # default 0.5
                sigma_iou = 0.4  # default 0.4
                t_min = 3  # default 4

            ttl_vtracking = 8  # maximum length of visual track (amount of framess)
            sigma_iou_merge = 0.4

            # uncomment line below if f4k2013 data is used
            # det_path = os.path.join(args.benchmark_dir,seq+"det.txt")
            # motchallenge data used
            det_path = os.path.join(args.benchmark_dir, seq, "det", "det.txt")
            img_path = os.path.join(args.benchmark_dir, seq, "img1")
            out_path = os.path.join(args.res_dir, seq + ".txt")
            detections = load_mot(det_path)

            # test preprocessing detections
            if args.prep_detections:
                detections = detections_preprocessing(detections,
                                                      iou_filter=0.90)

            start = time()
            tracks_iou = track_iou(detections, sigma_l, sigma_h, sigma_iou,
                                   t_min)
            end_iou = time()
            tracks_iou_ext, tracks_kcf_front, tracks_kcf_rear = track_kcf_2(
                tracks_iou, img_path, ttl_vtracking)
            end_ext = time()
            tracks_merged = merge(tracks_iou_ext, tracks_kcf_front,
                                  tracks_kcf_rear, sigma_iou_merge)
            end = time()
            num_frames = len(detections)
            print("finished " + seq + " at " +
                  str(int(num_frames / (end - start))) + " fps!")

            save_to_csv(out_path, tracks_merged)

            time_iou += (end_iou - start)
            time_ext += (end_ext - end_iou)
            time_merge += (end - end_ext)
            time_ttl += (end - start)

    print('Time IOU: ' + str(time_iou))
    print('Time VOT: ' + str(time_ext))
    print('Time Merge:' + str(time_merge))
    print('Time total: ' + str(time_ttl))
Ejemplo n.º 17
0
        print("Reading Video {}".format(INPUT_VIDEO))
        input_video = skvideo.io.vread(INPUT_VIDEO)
        print("Reading Finished")
        for i, frame in enumerate(input_video, start=1):
            tracks = tracks_per_frame.get(i, {})
            output_frame = render_frame(frame, tracks)
            output_video.writeFrame(output_frame)
            print("Writen Frame: {}".format(i))

    output_video.close()


font = cv2.FONT_HERSHEY_DUPLEX
font_size = 0.8

if __name__ == '__main__':

    #INPUT_VIDEO = "./MOT17-04-SDP.mp4"
    INPUT_PATH = "MOT17/train/MOT17-04-SDP/img1"
    INPUT_DETECTION = "MOT17/train/MOT17-04-SDP/det/det.txt"
    OUTPUT_VIDEO = "./result.mp4"

    detections = load_mot(INPUT_DETECTION)
    tracker = Tracker()
    tracks = {}
    for frame, detection in enumerate(detections, start=1):
        track = tracker.track(detection)
        tracks[frame] = track

    parsed_tracks = parse_tracks(tracks)
    write_video(INPUT_PATH, parsed_tracks, OUTPUT_VIDEO)