MLObjectDetector.AnnotationType.boundingBox(units:origin:anchor:)
An annotation type that defines a rectangle around an object within an image.
Declaration
case boundingBox(units: MLBoundingBoxUnits = .pixel, origin: MLBoundingBoxCoordinatesOrigin = .topLeft, anchor: MLBoundingBoxAnchor = .center)Discussion
To use bounding box annotations, you must tell Create ML how to interpret your annotations.
Use MLBoundingBoxUnits to specify the coordinate units of your bounding boxes.
Use MLBoundingBoxAnchor to specify the location in the bounding box its coordinates refer to.
Use MLBoundingBoxCoordinatesOrigin to specify the part of the image the annotations use as their origin.
Formatting a Bounding Box JSON Annotation File
The base of the JSON file must contain an array of the following JSON object structure.
Name | Type | Value |
|---|---|---|
| String | The name of the image’s file. |
| Array | An array of annotation JSON objects. |
Each JSON object in the annotation array must have the following JSON object structure.
Name | Type | Value |
|---|---|---|
| String | The name of the annotated object. |
| JSON object | The location of the object and the area it occupies in the image. |
The coordinate JSON object must have the following structure. The origin of the image is the upper-left corner. The x-values increase from left to right, and the y-values increase from the top to the bottom.
Name | Type | Value |
|---|---|---|
| Number | The |
| Number | The |
| Number | The width of the annotation’s bounding box. |
| Number | The height of the annotation’s bounding box. |
As an example, the following JSON file has correct structure with one image file ("cat and dog.png") in its base array, which has two annotations.
// JSON file
[{
"imagefilename": "cat and dog.png",
"annotation":
[
{
"label": "cat",
"coordinates":
{
"y": 2.0,
"x": 3.9,
"height": 40.1,
"width": 20.0
}
}, {
"label": "dog",
"coordinates":
{
"y": 40.0,
"x": 38.9,
"height": 100.1,
"width": 70.0
}
}
]
},
... ]A typical annotation JSON file has many more objects in its base array, one for each image file.