Skip to content
Snippets Groups Projects
Commit 47b8aedc authored by Anton Tetov Johansson's avatar Anton Tetov Johansson
Browse files

download metadata together with images

parent e30cb0a5
No related branches found
No related tags found
No related merge requests found
......@@ -3,16 +3,14 @@ import argparse
import os
from pathlib import Path
from typing import List
import json
import requests
from farmbot_yolo import creds
from farmbot_yolo import TMPDIR
# note: download only returns 100 at a time!
# note: we are currently ignoreing placeholders
DEBUG_SKIP_DELETE_FILES = True
IMG_FILE_SUFFIX = ".jpg"
......@@ -80,7 +78,19 @@ def download_images(directory: os.PathLike, delete_after=False) -> List[str]:
with filepath.open(mode="wb") as fp:
fp.write(img_req.content)
img_paths.append(filepath)
img_metadata_dict = {
"farmbot_metadata": {
"id": img_dict["id"],
"location": {
"x": img_dict["meta"]["x"],
"y": img_dict["meta"]["y"],
"z": img_dict["meta"]["z"],
},
}
}
with filepath.with_suffix(".json").open(mode="w") as fp:
json.dump(img_metadata_dict, fp)
# post delete from cloud storage
if delete_after:
......@@ -93,7 +103,10 @@ def download_images(directory: os.PathLike, delete_after=False) -> List[str]:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Farmbot YOLO image downloader")
parser.add_argument(
"download_dir", type=Path, help="Directory to download images too."
"download_dir",
type=Path,
help="Directory to download images too.",
default=TMPDIR,
)
parser.add_argument("-d", "--delete", action="store_true")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment