1

I'm working on a Python script to build a point shapefile I can open on QGIS from a list of bounding box (X and Y coordinates) returned by an Object Detection algo.

I know the CRS/EPSG and bounds of the TIFF file I ran the prediction on.

However I'm not sure how to handle the list of X and Y Bounding box coordinates: should I convert each coordinates into the original CRS while creating the point shape object ?

Or I just need to append each object with it's X and Y coordinate and save the shapefile with the correct bounds and CRS?

  • Are the bounding box coordinates in different coordinate systems? i.e. TIFF 'A' is in EPSG 4326 and TIFF 'B' is in 3785? If so then you will need to standardise them all before putting into a single shapefile. If they are the same you should be okay to append each. – EnE_ Jul 9 at 4:08
  • there is only 1 TIFF file I convert in JPG to run the prediction At the end of my process, I have a list of N bounding box coordinates in X and Y. I say X and Y because they are relative to the size of the full tiff in pixel My question concerns the many polygon I want to create : should I convert each polygon points (4 * (x , y )) for a rectangle into the EPSG of my original TIFF, or I can just copy the x and y and update the shapefile bounds and EPSG and it will work like that ? – Gil Jul 9 at 16:01
0

I had a similar problem. I did instance segmentation and then I should have restored the coordinates of the completed mask for GIS.
I converted the points of each mask to original coordinates and created a polygon using shapely. I think you just need to convert each point in your bbox to original coordinates and create polygons.
I used rasterio, and I think you can take this too.

Please follow the steps below.

  1. Converts the result of each object detection you cut into an integrated pixel coordinate.
  2. Rasterio calls the original TIFF file.
  3. You can get the coordinate values for the pixel coordinates of the original file.

For example.

import rasterio

#you can get x, y coords from original TIFF cell coords.
origin=rasterio.open("STH.TIFF")

#you make bbox list or xy pixel coods list sth..
bbox_list = [[xmax,xmin,ymax,ymin],....]

#get coords from pixel coords.
origin.xy(1, 100)

#return coords based on original TIFF crs.
(340578.786, 4155398.1545)

#all pixel coords convert to original coords.
for bbox in bbox_list:
    origin.xy(bbox[0], bbox[2])
    .....
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.