def load_tags(self, db_file_name):
        """
        Load tags from a file.

        :type  db_file_name: string
        :param db_file_name: the root name of the file containing the tags

        :rtype: boolean
        :returns: True if loading was successful
        """
        if db_file_name is None:
            # Set the name of database.
            # Algorithm : LBP (Local Binary Pattern)
            db_file_name = self._db_name

        tags_file_name = self._db_name + "-LBP-Tags"

        ok = False

        if os.path.isfile(tags_file_name):

            self._tags = utils.load_YAML_file(tags_file_name)
            ok = True
            print('\n### TAGS LOADED ###\n')

        return ok
    def load(self, db_file_name):
        """
        Update the face models data structure from a file.

        :type  db_file_name: string
        :param db_file_name: the name of the file containing
                             the dump of the face models data structure

        :rtype: boolean
        :returns: True if loading was successful
        """
        if db_file_name is None:
            '''
            Set the name of database.
            Algorithm :
            LBP (Local Binary Pattern)
            '''
            db_file_name = self._db_name + '-' + self._algorithm

        tags_file_name = db_file_name + '-Tags'

        algorithm = ce.FACE_MODEL_ALGORITHM
        
        if self._params is not None:
            
            algorithm = self._params[ce.FACE_MODEL_ALGORITHM_KEY]
        
        model = None
        
        if algorithm == 'Eigenfaces':
            
            model = cv2.createEigenFaceRecognizer()
        
        elif algorithm == 'Fisherfaces':
            
            model = cv2.createFisherFaceRecognizer()
            
        elif algorithm == 'LBP':
            
            model = cv2.createLBPHFaceRecognizer()
        
        ok = False

        if os.path.isfile(db_file_name) and (os.path.isfile(tags_file_name)):

            if(not((ce.USE_TRACKING or ce.SIM_TRACKING or ce.USE_SLIDING_WINDOW)
                   and ce.LOAD_IND_FRAMES_RESULTS)):
                model.load(db_file_name)

            if not(model is None):
                self.model = model
                self._tags = utils.load_YAML_file(tags_file_name)
                ok = True
                print('\n### DB LOADED ###\n')

        return ok
Exemple #3
0
def load_experiment_results(file_path):
    """
    Load file with results of all experiments

    :type file_path: string
    :param file_path: file to be loaded

    :rtype: list
    :returns: list with experiments
    """
    
    data = utils.load_YAML_file(file_path)
    experiments = data[ce.EXPERIMENTS_KEY]
    return experiments
Exemple #4
0
def load_image_annotations(file_path):
    """
    Load YAML file with image .

    :type file_path: string
    :param file_path: path of YAML file to be loaded

    :rtype: list
    :returns: a list of dictionaries with the annotated images
    """
    
    data = utils.load_YAML_file(file_path)
    
    if data:
        
        images = data[c.ANNOTATIONS_FRAMES_KEY]
        return images
        
    else:
        
        print 'Unable to open', file_path
        return None
Exemple #5
0
if __name__ == "__main__":
    
    import argparse
    import sys
    
    parser = argparse.ArgumentParser(
        description="Execute face recognition tests")
    parser.add_argument("-config", help="configuration file")
    args = parser.parse_args()

    params = None

    if args.config:
        # Load given configuration file
        try:
            params = load_YAML_file(args.config)
        except IOError, (errno, strerror):
            print("I/O error({0}): {1}".format(errno, strerror))
            print("Default configuration file will be used")
        except:
            print("Unexpected error:", sys.exc_info()[0])
            raise
        
    print("\n ### EXECUTING SOFTWARE TEST ###\n")

    test_passed = fr_test(params, False)

    if test_passed:
        print("\nSOFTWARE TEST PASSED\n")
        print("\n ### EXECUTING EXPERIMENTS ###\n")
        fr_experiments(params, False)
if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Execute clothing recognition tests")
    parser.add_argument(
        "-dataset_path", help="path of dataset")
    parser.add_argument("-config", help="configuration_file")
    args = parser.parse_args()

    # Set parameters
    params = None

    if args.config:
        # Load given configuration file
        try:
            params = utils.load_YAML_file(args.config)
        except IOError, (errno, strerror):
            print("I/O error({0}): {1}".format(errno, strerror))
            print("Default configuration file will be used")
        except:
            print("Unexpected error:", sys.exc_info()[0])
            raise
    else:
        print("Default configuration file will be used")

    # Set paths
    dataset_path = None
    if args.dataset_path:
        dataset_path = args.dataset_path
    else:
        print("Path of dataset not provided")
Exemple #7
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')