You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Assess Images](../../docs/project_types/assess_images.md) projects are created from a COCO-format JSON file describing the images to be mapped. This page provides a Python script that produces a minimal COCO file (`{ "images": [...] }`) from a folder of images hosted on Dropbox, so they can be referenced by public URL. The script also uploads the resulting JSON back to the same Dropbox folder.
12
+
[Assess Images](../../docs/project_types/assess_images.md) projects are created from a COCO-format JSON file describing the images to be mapped. This page provides two Python scripts that generate such a file from a Dropbox folder, exposing image URLs as public Dropbox share links.
13
13
14
-
> [!CAUTION]
15
-
> Ongoing updates to MapSwipe and Dropbox may render this script **out-of-date**.
14
+
-**v1** — `generate_coco_from_dropbox.py`: builds a minimal COCO file (`{ "images": [...] }`) from a **flat folder of images**. No annotations, no categories. Useful when you only need to register images for mapping.
15
+
-**v2** — `generate_coco_with_annotations_from_dropbox.py`: builds a full COCO file (`images`, `annotations`, `categories`) from an **images folder paired with a CSV metadata file** that describes bounding-box annotations per image. Useful when you already have annotations and want to seed an Assess Images project with them.
Produces a minimal COCO file containing only an `images` array. Each image is given a public Dropbox share link as its `coco_url`. The resulting JSON is uploaded back into the same Dropbox folder.
45
+
46
+
### Additional Prerequisites
47
+
48
+
- A Dropbox folder containing the images to be exported (`.jpg`, `.jpeg`, `.png`, or `.webp`). The folder is listed **non-recursively** — only files in the top level are picked up.
Produces a full COCO file (`images`, `annotations`, `categories`) by combining an images sub-folder with a CSV metadata file that describes one bounding-box annotation per row. Image URLs are resolved to public Dropbox share links. The output is written locally; uploading back to Dropbox is opt-in.
73
+
74
+
### Additional Prerequisites
75
+
76
+
- A Dropbox folder containing:
77
+
- An images sub-folder (default: `images/`) with `.jpg`, `.jpeg`, `.png`, or `.webp` files. The folder is listed **recursively**.
78
+
- A CSV metadata file (default: `metadata.csv`) with at least these columns:
79
+
-`image_name` — image path relative to the images folder.
80
+
-`boxes` — JSON-encoded 4-element list (e.g. `[x1, y1, x2, y2]`).
81
+
-`type` — category name for the annotation.
82
+
83
+
Additional columns are preserved as per-annotation `attributes`. All column names are configurable via flags.
84
+
85
+
### Creation Steps
86
+
87
+
1. Copy the folder path in Dropbox (the one containing the images sub-folder and the CSV).
88
+
2. Copy the generated access token from Dropbox and export it:
uv run generate_coco_with_annotations_from_dropbox.py --help
98
+
99
+
# Usage
100
+
uv run generate_coco_with_annotations_from_dropbox.py "FOLDER_PATHNAME_IN_DROPBOX" [options]
101
+
102
+
# Example
103
+
uv run generate_coco_with_annotations_from_dropbox.py "/Indonesia"
104
+
105
+
# Example with custom columns, lenient mode, image-dimension probing, and upload
106
+
uv run generate_coco_with_annotations_from_dropbox.py "/Indonesia" \
107
+
--output ./indonesia.coco.json \
108
+
--images-path images/ \
109
+
--metadata-csv-path metadata.csv \
110
+
--category-column type \
111
+
--image-name-column image_name \
112
+
--boxes-column boxes \
113
+
--box-format xyxy \
114
+
--lenient \
115
+
--probe-dimensions \
116
+
--upload-to-dropbox
117
+
```
118
+
4. Download the exported COCO JSON from the local path printed in the terminal (default: `./<base-folder-basename>.coco.json`). If `--upload-to-dropbox` was used, a temporary Dropbox link is also printed.
119
+
120
+
### Options
121
+
122
+
| Flag | Default | Purpose |
123
+
| --- | --- | --- |
124
+
|`--output`|`./<base-folder-basename>.coco.json`| Local path to write the COCO JSON. |
125
+
|`--images-path`|`images/`| Images folder, relative to the base folder (absolute Dropbox paths also accepted). |
126
+
|`--metadata-csv-path`|`metadata.csv`| CSV file path, relative to the base folder (absolute also accepted). |
127
+
|`--category-column`|`type`| CSV column used to derive COCO categories. |
128
+
|`--image-name-column`|`image_name`| CSV column with the image path relative to `--images-path`. |
129
+
|`--boxes-column`|`boxes`| CSV column with the bounding box (JSON-encoded 4-element list). |
130
+
|`--box-format`|`xyxy`| Format of the values in `--boxes-column`. `xyxy` is converted to COCO `xywh` on output. |
131
+
|`--annotation-id-column`|_(unset)_| CSV column to use as annotation id (must be unique). Defaults to sequential 1..N. |
132
+
|`--image-id-column`|_(unset)_| CSV column to use as image id (must be consistent per image). Defaults to sequential 1..N. |
133
+
|`--strict` / `--lenient`|`--strict`| Hard-error vs. skip-and-warn on rows referencing missing images or invalid boxes. |
134
+
|`--probe-dimensions`|`false`| Download each image and probe `width`/`height` with Pillow. |
135
+
|`--upload-to-dropbox`|`false`| Also upload the COCO JSON to `<base_folder>/<output basename>` in Dropbox. |
0 commit comments