diff --git a/README.md b/README.md index 80b7e7a..afa2159 100755 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@ Python 3.8 or later with all [requirements.txt](https://github.com/ultralytics/J $ pip install -r requirements.txt ``` +# How to use + +```bash +$ python general_json2yolo.py -source coco -json_dir annotations/ +``` + # Citation [![DOI](https://zenodo.org/badge/186122711.svg)](https://zenodo.org/badge/latestdoi/186122711) diff --git a/general_json2yolo.py b/general_json2yolo.py index 36ed278..190a3c4 100644 --- a/general_json2yolo.py +++ b/general_json2yolo.py @@ -5,6 +5,7 @@ from PIL import Image from utils import * +import argparse # Convert INFOLKS JSON file into YOLO-format labels ---------------------------- @@ -282,17 +283,23 @@ def convert_coco_json(json_dir='../coco/annotations/', use_segments=False): # Write if box[2] > 0 and box[3] > 0: # if w > 0 and h > 0 - line = coco80[x['category_id'] - 1], *(s if use_segments else box) # cls, box or segments + line = x['category_id'] - 1, *(s if use_segments else box) # cls, box or segments with open((fn / f).with_suffix('.txt'), 'a') as file: file.write(('%g ' * len(line)).rstrip() % line + '\n') if __name__ == '__main__': - source = 'coco' + + parser = argparse.ArgumentParser() + parser.add_argument('-json_dir', action='store', help='please include the full path of the folder with bounding boxes (.json)', type=str) + parser.add_argument('-source', action='store', help='define the format to convert to yolo (coco,infolks,vott,ath)', type=str,default="coco") + args = parser.parse_args() + json_dir=args.json_dir + source=args.source if source == 'coco': - convert_coco_json('../../Downloads/coco/annotations/') - + convert_coco_json(json_dir) + elif source == 'infolks': # Infolks https://infolks.info/ convert_infolks_json(name='out', files='../data/sm4/json/*.json', diff --git a/requirements.txt b/requirements.txt index a8a0038..0143e80 100755 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ Pillow pyYAML requests tqdm +argparse