FFmpeg
Loading...
Searching...
No Matches
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
28int main(void)
29{
31 AVDetectionBBox *bbox;
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");
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");
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,
80 }
82 }
83
84 /* classify fields */
85 printf("\nTesting classify fields\n");
87 if (header) {
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],
101 bbox->classify_confidences[i].den);
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);
112 }
113
114 /* av_detection_bbox_create_side_data */
115 printf("\nTesting av_detection_bbox_create_side_data()\n");
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}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static AVFrame * frame
AVDetectionBBoxHeader * av_detection_bbox_alloc(uint32_t nb_bboxes, size_t *out_size)
Allocates memory for AVDetectionBBoxHeader, plus an array of nb_bboxes AVDetectionBBox,...
AVDetectionBBoxHeader * av_detection_bbox_create_side_data(AVFrame *frame, uint32_t nb_bboxes)
Allocates memory for AVDetectionBBoxHeader, plus an array of nb_bboxes AVDetectionBBox,...
static av_always_inline AVDetectionBBox * av_get_detection_bbox(const AVDetectionBBoxHeader *header, unsigned int idx)
reference-counted frame API
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
Utility Preprocessor macros.
Memory handling functions.
static const uint8_t header[24]
Definition sdr2.c:68
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition snprintf.h:34
char detect_label[AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE]
Detect result with confidence.
int x
Distance in pixels from the left/top edge of the frame, together with width and height,...
char classify_labels[AV_NUM_DETECTION_BBOX_CLASSIFY][AV_DETECTION_BBOX_LABEL_NAME_MAX_SIZE]
AVRational detect_confidence
AVRational classify_confidences[AV_NUM_DETECTION_BBOX_CLASSIFY]
uint32_t classify_count
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
#define av_free(p)
int main(void)
int size