I am doing an object detection project using detectron2, which requires datasets to be in COCO format. This format needs images as png and polygons in a JSON file. However, spatial images (e.g. satellites or drones) are georeferenced (tif
format), and the annotations/labels also have geographical coordinates (shp
/geojson
format). Getting a regular image from a tif
file is pretty straightforward using rasterio
and numpy
, but getting the annotations in the correct coordinate system has been difficult because they need to point to the position of the polygons in the png
, not the georeferenced image.
As an example, say I have a 300*300 px satellite image bounded by these coordinates: 75W 10N, 70W 5N. The coordinates of the polygons will be within the region of the geographical box. Once I transform the geo-image to a normal image, it will lose its geographical reference, so the coordinates of the polygons should be in (0, 300), (0, 300).
Is there a way to translate the polygons from geographical coordinates to positional coordinates in an image so that I can make a dataset in COCO format?