diff mbox series

[FFmpeg-devel,09/10] libavfilter: show side data of dnn bounding box

Message ID 20210210045902.15013-1-yejun.guo@intel.com
State Superseded
Headers show
Series [FFmpeg-devel,01/10] dnn_backend_openvino.c: fix mismatch between ffmpeg(NHWC) and openvino(NCHW) | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate fail Make fate failed
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate warning Make fate failed

Commit Message

Guo, Yejun Feb. 10, 2021, 4:59 a.m. UTC
Signed-off-by: Guo, Yejun <yejun.guo@intel.com>
---
 libavfilter/f_sidedata.c  |  2 ++
 libavfilter/vf_showinfo.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
diff mbox series

Patch

diff --git a/libavfilter/f_sidedata.c b/libavfilter/f_sidedata.c
index 3757723375..08ee96c4ef 100644
--- a/libavfilter/f_sidedata.c
+++ b/libavfilter/f_sidedata.c
@@ -71,6 +71,7 @@  static const AVOption filt_name##_options[] = { \
     {   "S12M_TIMECOD",               "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_S12M_TIMECODE              }, 0, 0, FLAGS, "type" }, \
     {   "DYNAMIC_HDR_PLUS",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_DYNAMIC_HDR_PLUS           }, 0, 0, FLAGS, "type" }, \
     {   "REGIONS_OF_INTEREST",        "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_REGIONS_OF_INTEREST        }, 0, 0, FLAGS, "type" }, \
+    {   "DNN_BOUNDING_BOXES",         "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_DNN_BBOXES                 }, 0, 0, FLAGS, "type" }, \
     {   "SEI_UNREGISTERED",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_SEI_UNREGISTERED           }, 0, 0, FLAGS, "type" }, \
     { NULL } \
 }
@@ -100,6 +101,7 @@  static const AVOption filt_name##_options[] = { \
     {   "S12M_TIMECOD",               "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_S12M_TIMECODE              }, 0, 0, FLAGS, "type" }, \
     {   "DYNAMIC_HDR_PLUS",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_DYNAMIC_HDR_PLUS           }, 0, 0, FLAGS, "type" }, \
     {   "REGIONS_OF_INTEREST",        "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_REGIONS_OF_INTEREST        }, 0, 0, FLAGS, "type" }, \
+    {   "DNN_BOUNDING_BOXES",         "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_DNN_BBOXES                 }, 0, 0, FLAGS, "type" }, \
     {   "SEI_UNREGISTERED",           "", 0,             AV_OPT_TYPE_CONST,  {.i64 = AV_FRAME_DATA_SEI_UNREGISTERED           }, 0, 0, FLAGS, "type" }, \
     { NULL } \
 }
diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c
index 6208892005..67653b17ec 100644
--- a/libavfilter/vf_showinfo.c
+++ b/libavfilter/vf_showinfo.c
@@ -38,6 +38,7 @@ 
 #include "libavutil/timecode.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/video_enc_params.h"
+#include "libavutil/dnn_bbox.h"
 
 #include "avfilter.h"
 #include "internal.h"
@@ -153,6 +154,36 @@  static void dump_roi(AVFilterContext *ctx, const AVFrameSideData *sd)
     }
 }
 
+static void dump_dnnbbox(AVFilterContext *ctx, const AVFrameSideData *sd)
+{
+    int nb_bbox;
+    const AVDnnBoundingBox *bbox;
+    uint32_t bbox_size;
+
+    bbox = (const AVDnnBoundingBox *)sd->data;
+    bbox_size = bbox->self_size;
+    if (!bbox_size || sd->size % bbox_size != 0 || bbox_size != sizeof(*bbox)) {
+        av_log(ctx, AV_LOG_ERROR, "Invalid AVDnnBoundingBox.self_size.\n");
+        return;
+    }
+    nb_bbox = sd->size / bbox_size;
+
+    av_log(ctx, AV_LOG_INFO, "Dnn bounding boxes:\n");
+    for (int i = 0; i < nb_bbox; i++) {
+        bbox = (const AVDnnBoundingBox *)(sd->data + bbox_size * i);
+        av_log(ctx, AV_LOG_INFO, "index: %d, region: (%d/%d, %d/%d) -> (%d/%d, %d/%d), label: %d, confidence: %d/%d.\n",
+               i, bbox->left, bbox->model_input_width, bbox->top, bbox->model_input_height,
+               bbox->right, bbox->model_input_width, bbox->bottom, bbox->model_input_height,
+               bbox->detect_label, bbox->detect_conf.num, bbox->detect_conf.den);
+        if (bbox->classify_count > 0) {
+            for (int j = 0; j < bbox->classify_count; j++) {
+                av_log(ctx, AV_LOG_INFO, "\t\tclassify:  label: %d, confidence: %d/%d.\n",
+                       bbox->classify_labels[j], bbox->classify_confs[j].num, bbox->classify_confs[j].den);
+            }
+        }
+    }
+}
+
 static void dump_mastering_display(AVFilterContext *ctx, const AVFrameSideData *sd)
 {
     const AVMasteringDisplayMetadata *mastering_display;
@@ -494,6 +525,9 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
         case AV_FRAME_DATA_REGIONS_OF_INTEREST:
             dump_roi(ctx, sd);
             break;
+        case AV_FRAME_DATA_DNN_BBOXES:
+            dump_dnnbbox(ctx, sd);
+            break;
         case AV_FRAME_DATA_MASTERING_DISPLAY_METADATA:
             dump_mastering_display(ctx, sd);
             break;