EXTRACTOBJECTS Procedure
Example 7.2 Visualize Detections in COCO Format
(View the complete code for this example.)
This example shows how to use the EXTRACTOBJECTS procedure to visualize object detections that are provided in COCO format. For more information about annotation formats, see the section Supported Image Annotation Formats.
The following PROC FEDSQL statement adds the object detections in COCO format to the image table. It is assumed that the input image is loaded in the mylib.images table.
proc fedsql sessref=mysess;
create table coco_annotations as
select
*,
2 as "_nObjects_",
'bird0' as "_Object0_", 0.92 as "_P_Object0_",
4 as "_Object0_xmin", 23 as "_Object0_ymin",
205 as "_Object0_xmax", 177 as "_Object0_ymax",
'bird1' as "_Object1_", 0.84 as "_P_Object1_",
191 as "_Object1_xmin", 116 as "_Object1_ymin",
388 as "_Object1_xmax", 263 as "_Object1_ymax"
from
images;
quit;
Note: These statements create the mylib.coco_annotations table by using the image binaries and metadata from the mylib.images table and adding annotation variables in COCO format. Ensure that the following variables are specified for each detected object in the mylib.coco_annotations table, where N denotes the Nth detected object:
_ObjectN__ObjectN_xmin_ObjectN_ymin_ObjectN_xmax_ObjectN_ymax
You can also provide the probability values for each object detection as follows: _P_ObjectN_, where N denotes the Nth detected object.
The following PROC PRINT statement displays the contents of the mylib.coco_annotations table, which is generated by the previous statements:
proc print data=mylib.coco_annotations;
run;
Output 7.2.1 shows the mylib.coco_annotations table.
Output 7.2.1: The mylib.coco_annotations Table
| Obs | _width_ | _height_ | _image_ | _size_ | _path_ | _type_ | _id_ | _nObjects_ | _Object0_ | _P_Object0_ | _Object0_xmin | _Object0_ymin | _Object0_xmax | _Object0_ymax | _Object1_ | _P_Object1_ | _Object1_xmin | _Object1_ymin | _Object1_xmax | _Object1_ymax |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 448 | 448 | ... | 457024 | /path/to/birds.png | png | 1 | 2 | bird0 | 0.92 | 4 | 23 | 205 | 177 | bird1 | 0.84 | 191 | 116 | 388 | 263 |
The following statements highlight the two detected objects in the input image by using the annotations that are provided in COCO format. The resulting table, mylib.objects, contains images that have visualizations.
proc extractobjects data=mylib.coco_annotations
coordinateformat=coco maxobjects=2 method=highlight;
output out=mylib.objects;
run;
Output 7.2.2 shows the output image with two objects highlighted, along with their probabilities.
Output 7.2.2: Visualization of Object Detections and Probabilities
