def main():
    # construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-m", "--map", required=False, help="Path to the map of the parking lot")
    ap.add_argument("-mo", "--model", required=False, help="Path to model")

    args = vars(ap.parse_args())
    map_file = args['map']
    model_path = args['model']

    model_path = os.path.join(model_path, 'model.ckpt')
    model_dir, model_filename = os.path.split(model_path)

    uacj_images_path = 'C:\\Eduardo\\tesis\\datasets\\uacj'

    error_filename = 'uacj_{}_test.json'.format(os.path.splitext(model_filename)[0])
    if not os.path.isdir(os.path.join(model_dir, 'test_info')):
        os.mkdir(os.path.join(model_dir, 'test_info'))

    error_path = os.path.join(model_dir, 'test_info', error_filename)

    if os.path.isfile(error_path):
        print('This test was already made')
        return

    images_path = get_images_path(uacj_images_path)
    test_all_images = TestAllImages(images_path, model_filename, map_file, model_path, 'psv1', time_step=5)
    error_info = test_all_images.testAccuracy()

    with open(error_path, 'w') as efile:
        json.dump(error_info, efile)
Esempio n. 2
0
def main():
    # construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-s",
                    "--scale",
                    required=False,
                    default=3,
                    help="The scale where the image can be better managed")
    ap.add_argument("-i", "--image", required=True, help="Initial image")
    args = vars(ap.parse_args())
    scale = float(args['scale'])
    initial_image = args['image']

    uacj_images_path = 'C:\\Eduardo\\tesis\\datasets\\uacj'
    # uacj_images_path = 'C:\\Eduardo\\ProyectoFinal\\Pruebas_UACJ'
    images_path = get_images_path(uacj_images_path)
    if initial_image is not None:
        try:
            current_image_i = images_path.index(initial_image)
        except:
            print('The image given doesnt exist')
            return
    else:
        current_image_i = 0
    image_path = images_path[current_image_i]
    # load the image, clone it, and setup the mouse callback function
    image = cv2.imread(image_path)
    cv2.namedWindow("image")

    map_file = 'map_points_crop_rectangle_2.txt'
    map = []
    if os.path.isfile(map_file):
        with open(map_file, 'r') as filehandle:
            map1 = json.load(filehandle)
        for info in map1:
            info["rectangle"] = [
                tuple([x for x in l]) for l in info["rectangle"]
            ]
            info["angle"] = float(info["angle"])
            map.append(info)
    for m in map:
        rectangle = m['rectangle']
        fixed_rectangle = []
        for p in rectangle:
            p = (int(p[0] / scale), int(p[1] / scale))
            fixed_rectangle.append(p)
        m['rectangle_scaled'] = fixed_rectangle

    define_states = DefineStates(image=image,
                                 image_path=image_path,
                                 map=map,
                                 scale=scale,
                                 angle=-1)
    cv2.setMouseCallback("image", click_and_crop, define_states)

    functionality = setFunctionality(define_states, [])

    # keep looping until the 'q' key is pressed
    while True:
        key = cv2.waitKey(1) & 0xFF

        for f in functionality:
            if key == ord(f['key']):
                if '_callback' in f:
                    if 'param' in f:
                        f['_callback'](f['param'])
                    else:
                        f['_callback']()
        if key == ord("b"):
            current_image_i -= 1
            if current_image_i < 0:
                current_image_i = len(images_path) - 1
            image_path = images_path[current_image_i]
            image = cv2.imread(image_path)
            define_states.saveStates()
            last_states = define_states.states
            define_states = DefineStates(image=image,
                                         image_path=image_path,
                                         map=map,
                                         angle=define_states.angle,
                                         scale=scale)
            functionality = setFunctionality(define_states, last_states)
            cv2.setMouseCallback("image", click_and_crop, define_states)
        if key == ord("n"):
            current_image_i += 1
            if current_image_i >= len(images_path):
                current_image_i = 0
            image_path = images_path[current_image_i]
            print(image_path)
            image = cv2.imread(image_path)
            define_states.saveStates()
            last_states = define_states.states
            define_states = DefineStates(image=image,
                                         image_path=image_path,
                                         map=map,
                                         angle=define_states.angle,
                                         scale=scale)
            functionality = setFunctionality(define_states, last_states)
            cv2.setMouseCallback("image", click_and_crop, define_states)
        if key == ord("x"):
            break

        define_states.showImage()

    define_states.saveStates()
def main():
    # construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-i",
                    "--image",
                    required=False,
                    help="Path to the image",
                    default='29_07\\image28-11-2018_19-19-19.jpg')
    ap.add_argument("-s",
                    "--scale",
                    required=False,
                    default=3,
                    help="The scale where the image can be better managed")
    args = vars(ap.parse_args())
    #uacj_images_path = 'C:\\Eduardo\\ProyectoFinal\\Pruebas_UACJ'
    scale = float(args['scale'])
    uacj_images_path = 'C:\\Eduardo\\tesis\\datasets\\uacj'
    image_path = os.path.join(uacj_images_path, args["image"])
    images_path = get_images_path(uacj_images_path)
    image_path = images_path[0]
    # load the image, clone it, and setup the mouse callback function
    image = cv2.imread(image_path)
    cv2.namedWindow("image")

    map_file = 'map_points_crop_rectangle_2.txt'
    map = []
    if os.path.isfile(map_file):
        with open(map_file, 'r') as filehandle:
            map1 = json.load(filehandle)
        for info in map1:
            info["rectangle"] = [
                tuple([x for x in l]) for l in info["rectangle"]
            ]
            info["angle"] = float(info["angle"])
            map.append(info)
    for m in map:
        rectangle = m['rectangle']
        fixed_rectangle = []
        for p in rectangle:
            p = (int(p[0] / scale), int(p[1] / scale))
            fixed_rectangle.append(p)
        m['rectangle'] = fixed_rectangle

    crop_rectangle = CropRectangles(image=image,
                                    map=map,
                                    scale=scale,
                                    angle=-1)
    cv2.setMouseCallback("image", click_and_crop, crop_rectangle)

    functionality = set_functionality(crop_rectangle)

    # keep looping until the 'q' key is pressed
    while True:
        key = cv2.waitKey(1) & 0xFF

        # if the 'c' key is pressed, break from the loop
        if key != 255 and crop_rectangle.getLetter(key):
            crop_rectangle.show_image()
            continue
        for f in functionality:
            if key == ord(f['key']):
                if '_callback' in f:
                    if 'param' in f:
                        f['_callback'](f['param'])
                    else:
                        f['_callback']()
        if key == ord("c"):
            saveMap(map, map_file, scale)
        if key == ord("x"):
            break
        if key == ord("j"):
            image_path = random.choice(images_path)
            # load the image, clone it, and setup the mouse callback function
            image = cv2.imread(image_path)
            crop_rectangle = CropRectangles(image=image,
                                            map=map,
                                            angle=crop_rectangle.angle,
                                            scale=scale)
            functionality = set_functionality(crop_rectangle)
            cv2.setMouseCallback("image", click_and_crop, crop_rectangle)

        crop_rectangle.show_image()

    saveMap(map, map_file, scale)