Exemplo n.º 1
0
    def test_find_person_by_clothes(self):

        image_path = ('..' + os.sep + 'test_files' + os.sep +
                      'person_tracking' + os.sep + 'Test.jpg')

        ref_image_path = ('..' + os.sep + 'test_files' + os.sep +
                          'person_tracking' + os.sep + 'Reference.jpg')

        align_path = c.ALIGNED_FACES_PATH

        # Detect faces in image and take first result

        result_dict = detect_faces_in_image(
            ref_image_path, align_path, None, False)

        if c.FACES_KEY in result_dict:
            faces = result_dict[c.FACES_KEY]
            if len(faces) > 0:
                face_dict = faces[0]
                bbox = face_dict[c.BBOX_KEY]

                params = None
                show_results = True

                bbox = pt.find_person_by_clothes(
                    image_path, ref_image_path, bbox, params, show_results)

                if bbox:
                    x0 = bbox[0]
                    y0 = bbox[1]
                    width = bbox[2]
                    height = bbox[3]
                    x1 = x0 + width
                    y1 = y0 + height
                    im = cv2.imread(ref_image_path, cv2.IMREAD_COLOR)
                    im_height, im_width, channels = im.shape
                    self.assertGreaterEqual(x0, 0)
                    self.assertGreaterEqual(y0, 0)
                    self.assertLessEqual(x1, im_width)
                    self.assertLessEqual(y1, im_height)
Exemplo n.º 2
0
def person_tracking_image_experiments(params=None):
    """
    Execute person tracking experiments on images

    :type params: dictionary
    :param params: configuration parameters
                   to be used for the experiment (see table)
    ============================================  ========================================  ==============
    Key                                           Value                                     Default value
    ============================================  ========================================  ==============
    person_tracking_clothes_bbox_height           Height of bounding box for clothes
                                                  (in % of the face bounding box height)    1.0
    person_tracking_clothes_bbox_width            Width of bounding box for clothes         2.0
                                                  (in % of the face bounding box width)
    person_tracking_neck_height                   Height of neck (in % of the               0.0
                                                  face bounding box height)
    nr_of_hsv_channels_nr_in_person_tracking      Number of HSV channels used               2
                                                  in person tracking (1-2)
    use_mask_in_person_tracking                   If True, use a mask for HSV values        False
    min_size_height                               Minimum height of face detection          20
                                                  bounding box (in pixels)
    min_size_width                                Minimum width of face detection           20
                                                  bounding box (in pixels)
    annotations_path                              Path of directory containing the
                                                  manual annotations for the images
    dataset_path                                  Path of dataset
    ============================================  ========================================  ==============
    """

    ann_path = ce.PERSON_TRACKING_IMAGE_ANN_PATH
    dataset_path = ce.PERSON_TRACKING_IMAGE_DATASET_PATH
    if params is not None:
        if ce.PERSON_TRACKING_IMAGE_ANN_PATH_KEY in params:
            ann_path = params[ce.PERSON_TRACKING_IMAGE_ANN_PATH_KEY]
        if ce.PERSON_TRACKING_IMAGE_DATASET_PATH_KEY in params:
            dataset_path = params[ce.PERSON_TRACKING_IMAGE_DATASET_PATH_KEY]

    # Load file with annotations
    ann_dict = utils.load_YAML_file(ann_path)

    tot_discrete_score = 0
    tot_cont_score = 0
    tot_tracking_time = 0

    matches_counter = 0
    for subject_dir in os.listdir(dataset_path):
        subject_path = os.path.join(dataset_path, subject_dir)

        # Every image in directory is used as a reference image
        for ref_im_name in os.listdir(subject_path):
            print('ref_im_name', ref_im_name)
            # Full path of reference image
            ref_im_path = os.path.join(subject_path, ref_im_name)
            # Path of image relative to dataset path
            ref_rel_im_path = os.path.join(subject_dir, ref_im_name)
            ref_bbox = ann_dict[ref_rel_im_path][c.BBOX_KEY]

            # Other images in same directory are used as test images
            for test_im_name in os.listdir(subject_path):
                if test_im_name != ref_im_name:
                    # Full path of test image
                    test_im_path = os.path.join(subject_path, test_im_name)
                    # Path of image relative to dataset path
                    test_rel_im_path = os.path.join(subject_dir, ref_im_name)
                    test_true_bbox = ann_dict[test_rel_im_path][c.BBOX_KEY]
                    true_face_width = test_true_bbox[2]
                    true_face_height = test_true_bbox[3]

                    show_results = False
                    # Saving processing time
                    start_time = cv2.getTickCount()
                    test_found_bbox = pt.find_person_by_clothes(
                        test_im_path, ref_im_path, ref_bbox, params, show_results)
                    clocks = cv2.getTickCount() - start_time
                    seconds = clocks / cv2.getTickFrequency()
                    tot_tracking_time += seconds

                    if test_found_bbox:
                        (sim, int_area, int_area_pct) = utils.is_rect_similar(
                            test_true_bbox, test_found_bbox, 0)
                        if sim:
                            tot_discrete_score += 1
                            tot_cont_score += int_area_pct
                            if int_area_pct > 1.8:
                                print('int_area_pct', int_area_pct)
                                pt.find_person_by_clothes(
                                    test_im_path, ref_im_path, ref_bbox,
                                    params, True)
                    matches_counter += 1

    discrete_score = float(tot_discrete_score) / matches_counter
    cont_score = tot_cont_score / matches_counter
    mean_tracking_time = tot_tracking_time / matches_counter

    print('matches_counter', matches_counter)

    print("\n ### RESULTS ###\n")
    print('Mean of discrete score: ' + str(discrete_score * 100) + '%')
    print('Mean of continuous score: ' + str(cont_score * 100) + '%')
    print('Mean tracking time: ' + str(mean_tracking_time) + ' s\n\n')