Ejemplo n.º 1
0
def calculate_feature_points(file_name, db_path):
    """
    Analyzes 2 images and compares with the best result
    If the image is stored on the db, it uses the values from the db
    Else calculates de kaze features and saves them to the db
    """
    image = img.open_image_for_process(file_name)
    feature_points = db.load_db(db_path)

    if file_name in feature_points:
        kaze_features = feature_points[file_name]
        kp = utils.list_to_kp(kaze_features['kp_list'])
    else:
        detector = cv.KAZE_create()
        matcher = cv.FlannBasedMatcher()
        kp, desc = detector.detectAndCompute(image, None)

        feature_point = {
            file_name: {
                'path': file_name,
                'kp_list': utils.kp_to_list(kp),
                'desc': desc
            }
        }
        feature_points.update(feature_point)
        db.save_db(db_path, feature_points)

    best = {}
    best['img'] = image
    best['path'] = file_name

    return best
Ejemplo n.º 2
0
def get_kp(file_name):
    feature_points = db.load_db(DB_FP)

    if file_name in feature_points:
        kaze_features = feature_points[file_name]
        kp = utils.list_to_kp(kaze_features['kp_list'])
    else:
        raise Exception('Run preparation program first.')

    return kp, kaze_features['desc']
Ejemplo n.º 3
0
def main():
    '''Initializing Preparation'''

    parse_arguments()

    if DEBUG: print("Loading Points of interest databse")
    points_of_interest = db.load_db(DB_POI)

    if DEBUG: print("Waiting for Points of interest")
    click_map(points_of_interest, IMAGE_BASE, window_name="Preparation")

    if DEBUG: print("Saving Points of Interest")
    db.save_db(DB_POI, points_of_interest)

    if DEBUG: print("Calculating Feature Points")
    calculate_feature_points(IMAGE_BASE, DB_FP)

    if CALIBRATE:
        if DEBUG:
            print("Entering Camera Calibration Mode")
        pyr.calibrate()

    if DEBUG: print("Successful, exiting Preparation")
Ejemplo n.º 4
0
# 유저가 입력한 번호에 따라 명령 실행
def execute_action(db, action):
    if not 1 <= action <= 16:
        print('Invalid action')
        return
    map_actions[action](db)


# 프로그램 종료
def exit_db(db):
    del db
    print('Bye!')


if __name__ == '__main__':
    db = load_db()
    print(get_initial_message())

    while True:
        action = input('Select your action: ')
        if not action.isdigit():
            print('Invalid action')
            continue

        action = int(action)
        if action == 15:
            exit_db(db)
            break
        execute_action(db, action)
 def load_db(self):
     self.students = database.load_db(database.file_name)
Ejemplo n.º 6
0
def main():
    points_of_interest = db.load_db(DB_POI)
    prep.click_map(points_of_interest, IMAGE_BASE, window_name="Preparation")
    img, path = aug.search_all(IMAGE_TEST, DB_FP, points_of_interest, True)
    db.save_db(DB_POI, points_of_interest)
Ejemplo n.º 7
0
def applyAugmentedComponents(homography, image_base_display,
                             image_test_display):

    if DEBUG: print("Loading Points of Interest from Database")
    points_of_interest = db.load_db(DB_POI)

    if DEBUG: print("Calculating inverse homography")
    inverse = np.linalg.inv(homography)

    if DEBUG: print("Calculating important")
    heigth, width = image_test_display.shape[:2]
    xCenter = int(round(width / 2.0))
    yCenter = int(round(heigth / 2.0))

    if DEBUG: print("Placing center")
    disp.place_center(image_test_display, xCenter, yCenter)

    if DEBUG: print("Mapping center to original image")
    xOriginal, yOriginal = utils.map_coordinates(inverse, xCenter, yCenter)

    closest_point = {
        'name': None,
        'distance': 9999,
        'x': 0,
        'y': 0,
        'originX': 0,
        'originY': 0
    }

    if DEBUG: print("Finding closest interest point")
    for name, point in points_of_interest.items():
        dist = utils.calculate_distance(xOriginal, yOriginal, point['x'],
                                        point['y'])
        pX, pY = utils.map_coordinates(homography, point['x'], point['y'])

        print(dist, pX, pY, name, width, heigth)

        if (dist < closest_point['distance'] and pX >= 0 and pX < width
                and pY >= 0 and pY < heigth):
            closest_point['name'] = name
            closest_point['distance'] = dist
            closest_point['x'] = pX
            closest_point['y'] = pY
            closest_point['originX'] = point['x']
            closest_point['originY'] = point['y']

    if DEBUG: print("Calculationg real distance")
    if (closest_point['name'] is not None):
        distance_km = 290 * closest_point['distance'] / 57

    if DEBUG: print("Placing closest point")
    if (closest_point['name'] is not None):
        if CIRCLE:
            disp.place_intereset_point(image_test_display, closest_point)
        else:
            pyr.calculate_pyramid(homography, image_test_display,
                                  closest_point['x'], closest_point['y'])
        disp.place_distance_and_name(
            image_test_display,
            closest_point,
            distance_km,
        )

    if DEBUG: print("Placing compass")
    disp.place_compass(inverse, image_test_display, xCenter, yCenter,
                       closest_point['x'], closest_point['y'])

    if DEBUG: print("Getting images of point")
    if (closest_point['name'] is not None):
        disp.create_slideshow(closest_point['name'], distance_km, IMAGE_FOLDER)

    cv.imshow("Augmented", image_test_display)
    cv.waitKey(0)