Пример #1
0
def get_image_meta() -> Response:
    """
    Returns information for all the names in json format
    :return: JSON object
    """
    data: Dict[str, any] = load_json("meta/data.json")
    return jsonify(data)
Пример #2
0
def add_new_image(name: str,
                  id: int,
                  new_name,
                  dirs: List[str],
                  axis: int = 0) -> None:
    """
    Adds new image with all the directories for given original image in meta
    :param name: Name of image
    :param id: Id of image
    :param new_name:  New  name of which image should be generated
    :param dirs: List of directories to the new images
    :param axis: 0 for horizontal and 1 for vertical
    :return: None
    """
    name: str = name.lower()
    data: Dict[str, any] = load_json(DB_DIR)
    if name not in data.keys():
        return
    if id not in range(0, len(data[name])):
        return
    if new_name not in data[name][id]['new_imgs'].keys():
        data[name][id]['new_imgs'][new_name]: Dict[str, any] = {
            "new_name": new_name,
            "dirs": {
                "axis": [[], []]
            }
        }
    data[name][id]['new_imgs'][new_name]['dirs']['axis'][axis]: List[
        str] = dirs
    save_json(DB_DIR, data)
Пример #3
0
def get_image_meta_name(name: str) -> Response:
    """
    Returns information for all the entries based on the name in JSON format
    :param name: name of image (not filename)
    :return: JSON object
    """
    data: Dict[str, any] = load_json("meta/data.json")
    if id not in data.keys():
        abort(404)
    return jsonify(data[name])
def test_image_deallocation():
    file = 'meta/data.json'
    name = 'alex'
    data = load_json(file)[name][0]
    print(data)
    new_name = 'aaaaaa'
    imgs = deallocate_img(data, new_name, 1)
    # for img in imgs:
    #     cv.imshow("EEEEE", img)
    #     cv.waitKey(0)
    save_images(new_name, imgs)
Пример #5
0
def get_image(name: str, id: int) -> Dict[str, any]:
    """
    Returns the image object from meta based on given name and id
    :param name: Name of image
    :param id: Id of image
    :return: Image object with name, directory, and new images (if there are any)
    """
    name: str = name.lower()
    data: Dict[str, any] = load_json(DB_DIR)
    if name not in data.keys():
        return None
    if id not in range(0, len(data[name])):
        return None
    return data[name][id]
Пример #6
0
def delete_original_image(name: str, id: int) -> None:
    """
    Deletes an original image in meta based on given name and id. Does nothing, if image does not exist.
    :param name: Name of image
    :param id: Id of image
    :return: None
    """
    name: str = name.lower()
    data: Dict[str, any] = load_json(DB_DIR)
    if name not in data.keys():
        return
    if id not in range(0, len(data[name])):
        return
    data[name].pop(id)
    if len(data[name]) == 0:
        data.pop(name)
    save_json(DB_DIR, data)
Пример #7
0
def add_original_image(name: str,
                       filename: Optional[str] = None) -> Dict[str, any]:
    """
    Adds new original image in meta file with additional directories and returns created object.
    :param name: Name of image
    :param filename: Filename
    :return: Created new object
    """
    name: str = name.lower()
    data: Dict[str, any] = load_json(DB_DIR)
    if name not in data.keys():
        data[name]: List[Dict[str, any]] = []
    id: int = len(data[name])
    filename: str = name + '.' + filename.split('.')[-1]
    directory: str = IMAGE_DIR + "%i-%s" % (id, filename)
    new_obj: Dict[str, any] = {'name': name, 'dir': directory, 'new_imgs': {}}
    data[name].append(new_obj)
    save_json(DB_DIR, data)
    return new_obj
Пример #8
0
def test_equals(direction, id):
    assert load_json(direction) == test_cases[id]