Python script which generates annotations in JSON format required for training object detection models using CreateML.
CreateML requires a list of dictionaries with information about the selected bounding boxes: center and size (height and width) of the bounding box.
The following code shows how to draw bounding boxes using matplotlib library. It iterates over the images of a folder and draws bounding boxes to get the center coodinates, heitgh and width of the bounding box.
Detailed description on: https://medium.com/@eriksols/generate-annotations-json-format-for-createml-apple-with-python-90fc848cd439?postPublishedType=repub
Pass the path to the images folder (image_folder = 'path_to_image_folder'). Each image must be named with the corresponding class in order to detect the label, example: 'dog_01.jpg'.
Code will iterate over all the images contained on the images folder.
Now, you must draw the bounding box over the interest object. Once you are confident about the drawn bounding box, press "q" to generate and store the corresponding dictionary and continue the process with the next image.
A list containing the dictionaries of all images will be generated.
Finally a JSON file will be generated.
This script opens and iterates over the list containing the image dictionaries. This script also shows how to access the the list elements and the corresponding dictionaries.
It prints: List length (number of contained dictionaries) Image dictionary Label dictionary Coordinates dictionary
That's all! :D