This is a shapefile parser for the creation of yolov5 readable textfiles of object bounding boxes and polygons.
- Create conda environment.
- Activate environment.
- Run:
conda install pip - Go to project environment and run:
pip install -r requirements.txt
This parser uses jpg-images and polygons stored as ArcGIS shapefiles (.shp). Make sure that there is one shapefile for each image containing the boundaries of all objects within the image as polygons. In order to run this parser the file names must be set in the following way (see examples below). The coordinates of the extend of the images are stored in the image names. The code expects these coordinates in millimeter. Consequently, multiply original coordinates by 1000 beforehand. The first position in the image- and the corresponding shape file names must be a ID.
Structure Image Names
"ID_xminmm_xmincoords_xmaxmm_xmaxcoords_ymincm_ymincoords_ymaxcm_ymaxcoords.jpg"
Example Image Names
"100_xminmm_480500000_xmaxmm_480590000_ymincm_5601100000_ymaxcm_5601200000.jpg"
Example Corresponding Shapefile
"100..._.shp"
If you want to store object id and object class (e.g. species) in the final text files you need to store both information as numeric in attribute fields in the shape files. Name those fields "treeID" and "species_id". Or change ll. 42 and 56 in the parser script accroding to your data.
Create an output folder and store two empty folders inside. Name those folders "box" and "poly".
Activate conda environment. Navigate to the script and run:
python yolo_shapefileparser.py --imagepath "PATH/TO/IMAGES" --shapepath "PATH/TO/SHAPEFILES" --outpath "PATH/TO/OUTPUTFOLDER" --imagesize 640 --attributes False
For help run:
python yolo_shapefileparser.py --help