2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVUTIL_DETECTION_BBOX_H
20 #define AVUTIL_DETECTION_BBOX_H
26 typedef struct AVDetectionBBox
{
28 * Distance in pixels from the left/top edge of the frame,
29 * together with width and height, defining the bounding box.
36 #define AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE 64
39 * Detect result with confidence
41 char detect_label
[AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE
];
42 AVRational detect_confidence
;
45 * At most 4 classifications based on the detected bounding box.
46 * For example, we can get max 4 different attributes with 4 different
47 * DNN models on one bounding box.
48 * classify_count is zero if no classification.
50 #define AV_NUM_DETECTION_BBOX_CLASSIFY 4
51 uint32_t classify_count
;
52 char classify_labels
[AV_NUM_DETECTION_BBOX_CLASSIFY
][AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE
];
53 AVRational classify_confidences
[AV_NUM_DETECTION_BBOX_CLASSIFY
];
56 typedef struct AVDetectionBBoxHeader
{
58 * Information about how the bounding box is generated.
59 * for example, the DNN model name.
64 * Number of bounding boxes in the array.
69 * Offset in bytes from the beginning of this structure at which
70 * the array of bounding boxes starts.
75 * Size of each bounding box in bytes.
78 } AVDetectionBBoxHeader
;
81 * Get the bounding box at the specified {@code idx}. Must be between 0 and nb_bboxes.
83 static av_always_inline AVDetectionBBox
*
84 av_get_detection_bbox(const AVDetectionBBoxHeader
*header
, unsigned int idx
)
86 av_assert0(idx
< header
->nb_bboxes
);
87 return (AVDetectionBBox
*)((uint8_t *)header
+ header
->bboxes_offset
+
88 idx
* header
->bbox_size
);
92 * Allocates memory for AVDetectionBBoxHeader, plus an array of {@code nb_bboxes}
93 * AVDetectionBBox, and initializes the variables.
94 * Can be freed with a normal av_free() call.
96 * @param nb_bboxes number of AVDetectionBBox structures to allocate
97 * @param out_size if non-NULL, the size in bytes of the resulting data array is
100 AVDetectionBBoxHeader
*av_detection_bbox_alloc(uint32_t nb_bboxes
, size_t *out_size
);
103 * Allocates memory for AVDetectionBBoxHeader, plus an array of {@code nb_bboxes}
104 * AVDetectionBBox, in the given AVFrame {@code frame} as AVFrameSideData of type
105 * AV_FRAME_DATA_DETECTION_BBOXES and initializes the variables.
107 AVDetectionBBoxHeader
*av_detection_bbox_create_side_data(AVFrame
*frame
, uint32_t nb_bboxes
);