コード例 #1
0
def track_worker(input_queue, output_queue, gpu_id):
    """Runs Re3 tracker on images from input queue, passing bounding boxes to output queue."""
    sys.path.insert(1, PATH_TO_RE3)
    from tracker import re3_tracker

    tracker = re3_tracker.Re3Tracker(gpu_id)
    while True:
        image_np, box_ids, init_bounding_boxes = input_queue.get()
        tracked_boxes = np.empty(0)
        if len(box_ids) > 1:
            tracked_boxes = tracker.multi_track(box_ids, image_np,
                                                init_bounding_boxes)
        elif len(box_ids) == 1:
            init_bounding_box = None
            if init_bounding_boxes is not None:
                init_bounding_box = init_bounding_boxes[box_ids[0]]
            tracked_boxes = tracker.track(box_ids[0], image_np,
                                          init_bounding_box)

        if tracked_boxes.ndim == 0 or tracked_boxes.size == 0:
            output_queue.put([])
        elif tracked_boxes.ndim == 1:
            # If only a single box is detected, Re3 returns only that box. Convert to two dim
            # result to match.
            output_queue.put([tracked_boxes])
        else:
            output_queue.put(tracked_boxes)
コード例 #2
0
    def __init__(self,
                 re3_checkpoint_dir: str = os.path.join(os.path.dirname(__file__), "..", LOG_DIR, "checkpoints"),
                 face_detection_path: str = None,
                 facenet_path: str = None,
                 intersection_threshold: float = 0.2,
                 detect_each: int = 10,
                 gpu_id=GPU_ID,
                 add_min=0.3,
                 add_max=0.5,
                 profiler: Profiler = None,
                 **kwargs):

        self._detect_each: int = detect_each
        self._counter: int = -1
        self._tracked: typing.List[TrackedFace] = []

        self._kd_tree = None
        self._kd_embeddings = None
        self._kd_classes = []

        self._add_range = [add_min, add_max]
        # intersection coef for identifying tracked and detected faces
        self._intersection_threshold: float = intersection_threshold
        self._log_msgs: typing.List[str] = []
        self._report_start_ts = None
        self._report: typing.Dict[int: FaceTrackerReportItem] = {}
        self._class_images = {}
        self._profiler: Profiler = profiler_pipe(profiler)

        kwargs['profiler'] = self._profiler
        self.agender = age_gender.AgeGenderFilter(**kwargs)
        self.head_pose = headpose.HeadPoseFilter(**kwargs)

        self._re3_tracker: re3_tracker.Re3Tracker = re3_tracker.Re3Tracker(
            re3_checkpoint_dir, gpu_id=gpu_id, profiler=self._profiler
        )
        self._face_detector: detector.Detector = detectors.get_face_detector(face_detection_path)

        if facenet_path is None:
            self._facenet = None
        else:
            self._facenet = facenet.Facenet(facenet_path, self._profiler)
コード例 #3
0
    def __init__(self):

        self.tracker = re3_tracker.Re3Tracker()
        self.trkid_lst = []

        # Initialize eCAL
        ecal.initialize(sys.argv, "object tracking")
        # Read the JSON files
        with open(topics_json_path) as data_file:
            self.json_data = json.load(data_file)

        # Topic names
        self.tracker_request = self.json_data['image_request']
        self.tracker_response = self.json_data['image_response']

        print("Tracker initialization done!!")

        # Define the callbacks for publisher subscriber
        self.initialize_subscr_topics()
        self.initialize_publsr_topics()

        # The callbacks will redirect to the tracker function and publish predicted ROI
        self.define_subscr_callbacks()
コード例 #4
0
import cv2
import glob
import numpy as np
import sys
import os.path
import os
import pandas as pd
basedir = os.path.dirname(__file__)
sys.path.append(os.path.abspath(os.path.join(basedir, os.path.pardir)))
import xml.etree.cElementTree as ET
# from read_cap import *
# from tracker import re3_tracker
from tracker import re3_tracker

import natsort
tracker = re3_tracker.Re3Tracker()
# status_pause=True
index = 0
last_file = None
round_counter = 1
start = True
status_pause = False
image_paths = natsort.natsorted(
    glob.glob(os.path.join(os.path.dirname(__file__), 'data',
                           '*.jpg')))  #path data
threshold_iou = 13


def cal_iou(bb1, bb2):
    x_left = max(bb1['x1'], bb2['x1'])
    y_top = max(bb1['y1'], bb2['y1'])
コード例 #5
0
ファイル: test_net.py プロジェクト: thepian/re3-pytorch
    FLAGS = parser.parse_args()

    DISPLAY = FLAGS.display

    data = get_datasets.get_data_for_dataset(FLAGS.dataset, FLAGS.mode)
    gt = data["gt"]
    imageNames = data["image_paths"]
    sample_inds = np.where(gt[:, 4] % FLAGS.video_sample_rate == 0)[0]
    gt = gt[sample_inds, :]
    numImages = gt.shape[0]
    imageNums = gt[:, 6].astype(int)

    if FLAGS.maxCount == -1:
        FLAGS.maxCount = numImages - FLAGS.skipCount

    tracker = re3_tracker.Re3Tracker(FLAGS.cuda_visible_devices)

    print("Testing", numImages, "frames")

    # Set up global data holders
    imOn = FLAGS.skipCount
    numFrames = 0
    ignoreFrames = 0
    initializeFrames = 0
    lostTarget = 0
    currentTrackLength = 0
    initialize = True

    totalIou = 0

    if FLAGS.record:
コード例 #6
0
            cv2.rectangle(img,
                          (int(outputBoxToDraw[0]), int(outputBoxToDraw[1])),
                          (int(outputBoxToDraw[2]), int(outputBoxToDraw[3])),
                          [0, 0, 255], PADDING)
        cv2.imshow('Webcam', img)
        if RECORD:
            if outputBoxToDraw is not None:
                labels.write('%d %.2f %.2f %.2f %.2f\n' %
                             (frameNum, outputBoxToDraw[0], outputBoxToDraw[1],
                              outputBoxToDraw[2], outputBoxToDraw[3]))
            cv2.imwrite('%s%08d.jpg' % (outputDir, frameNum), origImg)
            print('saving')
        keyPressed = cv2.waitKey(1)
        if keyPressed == 27 or keyPressed == 1048603:
            break  # esc to quit
        frameNum += 1
    cv2.destroyAllWindows()


# Main function
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Show the Webcam demo.')
    parser.add_argument('-r', '--record', action='store_true', default=False)
    parser.add_argument('--checkpoint', required=True)
    args = parser.parse_args()
    RECORD = args.record

    tracker = re3_tracker.Re3Tracker(args.checkpoint)

    show_webcam(mirror=True)
コード例 #7
0
                outputBoxToDraw = tracker.track('webcam', img[:, :, ::-1])
            cv2.rectangle(img,
                          (int(outputBoxToDraw[0]), int(outputBoxToDraw[1])),
                          (int(outputBoxToDraw[2]), int(outputBoxToDraw[3])),
                          [0, 0, 255], PADDING)
        cv2.imshow('Webcam', img)
        if RECORD:
            if outputBoxToDraw is not None:
                labels.write('%d %.2f %.2f %.2f %.2f\n' %
                             (frameNum, outputBoxToDraw[0], outputBoxToDraw[1],
                              outputBoxToDraw[2], outputBoxToDraw[3]))
            cv2.imwrite('%s%08d.jpg' % (outputDir, frameNum), origImg)
            print('saving')
        keyPressed = cv2.waitKey(1)
        if keyPressed == 27 or keyPressed == 1048603:
            break  # esc to quit
        frameNum += 1
    cv2.destroyAllWindows()


# Main function
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Show the Webcam demo.')
    parser.add_argument('-r', '--record', action='store_true', default=False)
    args = parser.parse_args()
    RECORD = args.record

    tracker = re3_tracker.Re3Tracker("./logs/checkpoints/")

    show_webcam(mirror=True)
コード例 #8
0
def setup(opts):
    tracker = re3_tracker.Re3Tracker(opts["checkpoint"])
    return tracker
コード例 #9
0
 def __init__(self, tracker_type=TrackerType.RE3):
     # initializing the type of tracker to be used
     #self.tracker = re3_tracker.Re3Tracker()
     self.tracker_type = tracker_type
     self.tracker = re3_tracker.Re3Tracker()