Path: blob/master/dep/ffmpeg/include/libavutil/detection_bbox.h
4216 views
/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718#ifndef AVUTIL_DETECTION_BBOX_H19#define AVUTIL_DETECTION_BBOX_H2021#include "rational.h"22#include "avassert.h"23#include "frame.h"2425typedef struct AVDetectionBBox {26/**27* Distance in pixels from the left/top edge of the frame,28* together with width and height, defining the bounding box.29*/30int x;31int y;32int w;33int h;3435#define AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE 643637/**38* Detect result with confidence39*/40char detect_label[AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE];41AVRational detect_confidence;4243/**44* At most 4 classifications based on the detected bounding box.45* For example, we can get max 4 different attributes with 4 different46* DNN models on one bounding box.47* classify_count is zero if no classification.48*/49#define AV_NUM_DETECTION_BBOX_CLASSIFY 450uint32_t classify_count;51char classify_labels[AV_NUM_DETECTION_BBOX_CLASSIFY][AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE];52AVRational classify_confidences[AV_NUM_DETECTION_BBOX_CLASSIFY];53} AVDetectionBBox;5455typedef struct AVDetectionBBoxHeader {56/**57* Information about how the bounding box is generated.58* for example, the DNN model name.59*/60char source[256];6162/**63* Number of bounding boxes in the array.64*/65uint32_t nb_bboxes;6667/**68* Offset in bytes from the beginning of this structure at which69* the array of bounding boxes starts.70*/71size_t bboxes_offset;7273/**74* Size of each bounding box in bytes.75*/76size_t bbox_size;77} AVDetectionBBoxHeader;7879/*80* Get the bounding box at the specified {@code idx}. Must be between 0 and nb_bboxes.81*/82static av_always_inline AVDetectionBBox *83av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)84{85av_assert0(idx < header->nb_bboxes);86return (AVDetectionBBox *)((uint8_t *)header + header->bboxes_offset +87idx * header->bbox_size);88}8990/**91* Allocates memory for AVDetectionBBoxHeader, plus an array of {@code nb_bboxes}92* AVDetectionBBox, and initializes the variables.93* Can be freed with a normal av_free() call.94*95* @param nb_bboxes number of AVDetectionBBox structures to allocate96* @param out_size if non-NULL, the size in bytes of the resulting data array is97* written here.98*/99AVDetectionBBoxHeader *av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size);100101/**102* Allocates memory for AVDetectionBBoxHeader, plus an array of {@code nb_bboxes}103* AVDetectionBBox, in the given AVFrame {@code frame} as AVFrameSideData of type104* AV_FRAME_DATA_DETECTION_BBOXES and initializes the variables.105*/106AVDetectionBBoxHeader *av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes);107#endif108109110