コード例 #1
0
    def get_people_diff(cls, person1: 'ClassPeopleReId',
                        person2: 'ClassPeopleReId'):
        # Comparing people between list
        diff_upper = ClassUtils.get_color_diff_rgb(person1.color_upper,
                                                   person2.color_upper)
        diff_lower = ClassUtils.get_color_diff_rgb(person1.color_lower,
                                                   person2.color_lower)

        diff_colors_1 = ClassUtils.get_color_diff_rgb(person1.color_upper,
                                                      person1.color_lower)
        diff_colors_2 = ClassUtils.get_color_diff_rgb(person2.color_upper,
                                                      person2.color_lower)

        diff_colors = math.fabs(diff_colors_1 - diff_colors_2)

        diff_k_means = ClassDescriptors.get_kmeans_diff(
            person1.hist_pose, person2.hist_pose)

        distance = cls.get_person_distance(person1, person2)

        return_data = {
            'diffUpper': diff_upper,
            'diffLower': diff_lower,
            'diffColors': diff_colors,
            'distance': distance,
            'diffKMeans': diff_k_means
        }

        return return_data
コード例 #2
0
def test_color_compare():
    print('Test color comparision')

    print('Loading image comparision')
    # Loading instances
    instance_pose = ClassOpenPose()

    # Avoid to open two prompts
    obj_img = ClassDescriptors.load_images_comparision_ext(instance_pose,
                                                           min_score,
                                                           load_one_img=True)
    hist_pose1 = obj_img['listPoints1']

    list_process = list()

    # Iterating in examples folder
    for root, _, files in os.walk(EXAMPLES_FOLDER):
        for file in files:
            full_path = os.path.join(root, file)
            extension = ClassUtils.get_filename_extension(full_path)

            if extension == '.jpg':
                list_process.append(full_path)

    # Sorting list
    list_process.sort()

    list_result = list()
    score_max_pt = -1

    for full_path in list_process:
        print('Processing file: {0}'.format(full_path))
        json_path = full_path.replace('.jpg', '.json')

        with open(json_path, 'r') as f:
            obj_json = json.loads(f.read())

        his_pose2 = obj_json['histPose']
        diff = ClassDescriptors.get_kmeans_diff(hist_pose1, his_pose2)
        print('Diff {0}'.format(diff))

        if diff <= 15:
            res = True
        else:
            res = False

        list_result.append({
            'filename':
            ClassUtils.get_filename_no_extension(full_path),
            'score':
            res
        })

    # list_result.sort(key=lambda x: x['score'])
    print('Printing list result')
    print(json.dumps(list_result, indent=2))
    print('min_score: {0}'.format(score_max_pt))

    print('Done!')
コード例 #3
0
def test_color_compare_hist(perform_eq=False):
    print('Test color comparision')

    print('Loading image comparision')
    # Loading instances
    instance_pose = ClassOpenPose()

    ignore_json_color = False
    if perform_eq:
        ignore_json_color = True

    # Avoid to open two prompts
    obj_img = ClassDescriptors.load_images_comparision_ext(
        instance_pose,
        min_score,
        load_one_img=True,
        perform_eq=perform_eq,
        ignore_json_color=ignore_json_color)

    # Extract color comparision from image
    hist1 = obj_img['listPoints1']

    # Generating examples folder
    list_process = list()
    for root, _, files in os.walk(EXAMPLES_FOLDER):
        for file in files:
            full_path = os.path.join(root, file)
            extension = ClassUtils.get_filename_extension(full_path)

            if extension == '.jpg':
                list_process.append(full_path)

    # Sorting list
    list_process.sort()
    """
    list_result = list()
    score_max_pt = -1
    """

    for full_path in list_process:
        print('Processing file: {0}'.format(full_path))
        json_path = full_path.replace('.jpg', '.json')

        with open(json_path, 'r') as f:
            obj_json = json.loads(f.read())

        image2 = cv2.imread(full_path)

        if perform_eq:
            image2 = ClassUtils.equalize_hist(image2)

        if 'vector' in obj_json:
            pose2 = obj_json['vector']
        elif 'vectors' in obj_json:
            pose2 = obj_json['vectors']
        else:
            raise Exception('Invalid vector property for vector custom')

        hist2 = ClassDescriptors.get_points_by_pose(image2, pose2, min_score)

        diff = ClassDescriptors.get_kmeans_diff(hist1, hist2)

        # Getting mean y from image 2 - discarding purposes
        pt1, pt2 = ClassUtils.get_rectangle_bounds(pose2, min_score)
        image2_crop = image2[pt1[1]:pt2[1], pt1[0]:pt2[0]]
        image2_ycc = cv2.cvtColor(image2_crop, cv2.COLOR_BGR2YCrCb)
        mean_y = np.mean(image2_ycc[:, :, 0])

        print('Diff color: {0} - Mean y: {1}'.format(diff, mean_y))
    """
    list_result.sort(key=lambda x: x['score'])
    print('Printing list result')
    print(list_result)
    print('min_score: {0}'.format(score_max_pt))
    """

    print('Done!')