FFmpeg
detection_bbox.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <string.h>
22 
24 #include "libavutil/frame.h"
25 #include "libavutil/macros.h"
26 #include "libavutil/mem.h"
27 
28 int main(void)
29 {
31  AVDetectionBBox *bbox;
32  AVFrame *frame;
33  size_t size;
34 
35  static const unsigned int alloc_counts[] = { 0, 1, 4 };
36 
37  /* av_detection_bbox_alloc - various counts */
38  printf("Testing av_detection_bbox_alloc()\n");
39  for (int i = 0; i < FF_ARRAY_ELEMS(alloc_counts); i++) {
40  unsigned int nb = alloc_counts[i];
42  if (header) {
43  printf("alloc %u: OK, nb=%u, size>0=%s\n",
44  nb, header->nb_bboxes, size > 0 ? "yes" : "no");
45  av_free(header);
46  } else {
47  printf("alloc %u: FAIL\n", nb);
48  }
49  }
50 
51  /* av_detection_bbox_alloc without size */
53  printf("alloc (no size): %s\n", header ? "OK" : "FAIL");
54  av_free(header);
55 
56  /* av_get_detection_bbox - pointer consistency and write/read back */
57  printf("\nTesting av_get_detection_bbox()\n");
59  if (header) {
60  for (int i = 0; i < 3; i++) {
62  if ((uint8_t *)bbox != (uint8_t *)header + header->bboxes_offset +
63  (size_t)i * header->bbox_size)
64  printf("bbox %d: pointer inconsistent with bboxes_offset/bbox_size\n", i);
65  bbox->x = i * 100;
66  bbox->y = i * 200;
67  bbox->w = 50 + i;
68  bbox->h = 60 + i;
69  snprintf(bbox->detect_label, sizeof(bbox->detect_label),
70  "obj%d", i);
71  bbox->detect_confidence = (AVRational){ 90 + i, 100 };
72  }
73  for (int i = 0; i < 3; i++) {
75  printf("bbox %d: x=%d y=%d w=%d h=%d label=%s conf=%d/%d\n",
76  i, bbox->x, bbox->y, bbox->w, bbox->h,
77  bbox->detect_label,
78  bbox->detect_confidence.num,
79  bbox->detect_confidence.den);
80  }
81  av_free(header);
82  }
83 
84  /* classify fields */
85  printf("\nTesting classify fields\n");
87  if (header) {
88  bbox = av_get_detection_bbox(header, 0);
89  bbox->classify_count = 2;
90  snprintf(bbox->classify_labels[0], sizeof(bbox->classify_labels[0]),
91  "cat");
92  bbox->classify_confidences[0] = (AVRational){ 95, 100 };
93  snprintf(bbox->classify_labels[1], sizeof(bbox->classify_labels[1]),
94  "animal");
95  bbox->classify_confidences[1] = (AVRational){ 80, 100 };
96  printf("classify_count=%u\n", bbox->classify_count);
97  for (int i = 0; i < (int)bbox->classify_count; i++)
98  printf("classify %d: %s %d/%d\n", i,
99  bbox->classify_labels[i],
100  bbox->classify_confidences[i].num,
101  bbox->classify_confidences[i].den);
102  av_free(header);
103  }
104 
105  /* header source field */
106  printf("\nTesting source field\n");
108  if (header) {
109  snprintf(header->source, sizeof(header->source), "test_model_v1");
110  printf("source: %s\n", header->source);
111  av_free(header);
112  }
113 
114  /* av_detection_bbox_create_side_data */
115  printf("\nTesting av_detection_bbox_create_side_data()\n");
116  frame = av_frame_alloc();
117  if (frame) {
119  if (header) {
120  printf("side_data: OK, nb=%u\n", header->nb_bboxes);
121  bbox = av_get_detection_bbox(header, 0);
122  bbox->x = 10;
123  bbox->y = 20;
124  printf("side_data bbox 0: x=%d y=%d\n", bbox->x, bbox->y);
125  } else {
126  printf("side_data: FAIL\n");
127  }
129  }
130 
131  return 0;
132 }
printf
__device__ int printf(const char *,...)
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVDetectionBBox::y
int y
Definition: detection_bbox.h:32
AVDetectionBBox::detect_label
char detect_label[AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE]
Detect result with confidence.
Definition: detection_bbox.h:41
macros.h
AVRational::num
int num
Numerator.
Definition: rational.h:59
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
av_get_detection_bbox
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
Definition: detection_bbox.h:84
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVDetectionBBox::classify_confidences
AVRational classify_confidences[AV_NUM_DETECTION_BBOX_CLASSIFY]
Definition: detection_bbox.h:53
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVDetectionBBox::classify_labels
char classify_labels[AV_NUM_DETECTION_BBOX_CLASSIFY][AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE]
Definition: detection_bbox.h:52
AVDetectionBBoxHeader
Definition: detection_bbox.h:56
av_detection_bbox_create_side_data
AVDetectionBBoxHeader * av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes)
Allocates memory for AVDetectionBBoxHeader, plus an array of.
Definition: detection_bbox.c:52
main
int main(void)
Definition: detection_bbox.c:28
AVDetectionBBox::w
int w
Definition: detection_bbox.h:33
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
size
int size
Definition: twinvq_data.h:10344
frame.h
header
static const uint8_t header[24]
Definition: sdr2.c:68
AVDetectionBBox::classify_count
uint32_t classify_count
Definition: detection_bbox.h:51
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AVDetectionBBox::h
int h
Definition: detection_bbox.h:34
AVDetectionBBox::detect_confidence
AVRational detect_confidence
Definition: detection_bbox.h:42
AVRational::den
int den
Denominator.
Definition: rational.h:60
AVDetectionBBox::x
int x
Distance in pixels from the left/top edge of the frame, together with width and height,...
Definition: detection_bbox.h:31
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDetectionBBox
Definition: detection_bbox.h:26
snprintf
#define snprintf
Definition: snprintf.h:34
detection_bbox.h
av_detection_bbox_alloc
AVDetectionBBoxHeader * av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size)
Allocates memory for AVDetectionBBoxHeader, plus an array of.
Definition: detection_bbox.c:22