Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: <m.kaindl0208@gmail.com>
To: <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH FFmpeg 2/15] libavfilter/dnn: move existing contain_valid_detection_bbox from openvino backend to dnn_backend_common
Date: Sat, 8 Mar 2025 15:58:41 +0100
Message-ID: <007401db903a$95181d10$bf485730$@gmail.com> (raw)

Moves the contain_valid_detection_bbox function from the OpenVINO backend to the common backend code, making it available for all DNN backends to use when checking bounding box validity.

Will be used by the Torch backend in an upcoming patch in this series.

Try the new filters using my Github Repo https://github.com/MaximilianKaindl/DeepFFMPEGVideoClassification.

Any Feedback is appreciated!

Signed-off-by: MaximilianKaindl <m.kaindl0208@gmail.com>
---
 libavfilter/dnn/dnn_backend_common.c   | 38 +++++++++++++++++++++++++
 libavfilter/dnn/dnn_backend_common.h   |  9 ++++++
 libavfilter/dnn/dnn_backend_openvino.c | 39 +-------------------------
 3 files changed, 48 insertions(+), 38 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_common.c b/libavfilter/dnn/dnn_backend_common.c
index e45eefd14d..3944db35b5 100644
--- a/libavfilter/dnn/dnn_backend_common.c
+++ b/libavfilter/dnn/dnn_backend_common.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/mem.h"
 #include "dnn_backend_common.h"
+#include "libavutil/detection_bbox.h"
 
 #define DNN_ASYNC_SUCCESS (void *)0
 #define DNN_ASYNC_FAIL (void *)-1
@@ -178,3 +179,40 @@ int ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_param
 
     return ff_dnn_fill_task(task, exec_params, backend_model, 0, 0);
 }
+
+int ff_dnn_contain_valid_detection_bbox(AVFrame *frame)
+{
+    AVFrameSideData *sd;
+    const AVDetectionBBoxHeader *header;
+    const AVDetectionBBox *bbox;
+
+    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES);
+    if (!sd) { // this frame has nothing detected
+        return 0;
+    }
+
+    if (!sd->size) {
+        return 0;
+    }
+
+    header = (const AVDetectionBBoxHeader *)sd->data;
+    if (!header->nb_bboxes) {
+        return 0;
+    }
+
+    for (uint32_t i = 0; i < header->nb_bboxes; i++) {
+        bbox = av_get_detection_bbox(header, i);
+        if (bbox->x < 0 || bbox->w < 0 || bbox->x + bbox->w >= frame->width) {
+            return 0;
+        }
+        if (bbox->y < 0 || bbox->h < 0 || bbox->y + bbox->h >= frame->height) {
+            return 0;
+        }
+
+        if (bbox->classify_count == AV_NUM_DETECTION_BBOX_CLASSIFY) {
+            return 0;
+        }
+    }
+
+    return 1;
+}
\ No newline at end of file
diff --git a/libavfilter/dnn/dnn_backend_common.h b/libavfilter/dnn/dnn_backend_common.h
index 9f5d37b3e0..3629cb4922 100644
--- a/libavfilter/dnn/dnn_backend_common.h
+++ b/libavfilter/dnn/dnn_backend_common.h
@@ -157,4 +157,13 @@ DNNAsyncStatusType ff_dnn_get_result_common(Queue *task_queue, AVFrame **in, AVF
  */
 int ff_dnn_fill_gettingoutput_task(TaskItem *task, DNNExecBaseParams *exec_params, void *backend_model, int input_height, int input_width, void *ctx);
 
+/**
+ * Check if the given frame contains a valid detection bounding box.
+ *
+ * @param frame The frame to check for valid detection bounding box
+ * 
+ * @return Non-zero if frame contains valid detection bounding box, 0 otherwise
+ */
+int ff_dnn_contain_valid_detection_bbox(AVFrame *frame);
+
 #endif
diff --git a/libavfilter/dnn/dnn_backend_openvino.c b/libavfilter/dnn/dnn_backend_openvino.c
index 2f6706dcd4..03183af822 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -1151,43 +1151,6 @@ static int get_input_ov(DNNModel *model, DNNData *input, const char *input_name)
 #endif
 }
 
-static int contain_valid_detection_bbox(AVFrame *frame)
-{
-    AVFrameSideData *sd;
-    const AVDetectionBBoxHeader *header;
-    const AVDetectionBBox *bbox;
-
-    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DETECTION_BBOXES);
-    if (!sd) { // this frame has nothing detected
-        return 0;
-    }
-
-    if (!sd->size) {
-        return 0;
-    }
-
-    header = (const AVDetectionBBoxHeader *)sd->data;
-    if (!header->nb_bboxes) {
-        return 0;
-    }
-
-    for (uint32_t i = 0; i < header->nb_bboxes; i++) {
-        bbox = av_get_detection_bbox(header, i);
-        if (bbox->x < 0 || bbox->w < 0 || bbox->x + bbox->w >= frame->width) {
-            return 0;
-        }
-        if (bbox->y < 0 || bbox->h < 0 || bbox->y + bbox->h >= frame->height) {
-            return 0;
-        }
-
-        if (bbox->classify_count == AV_NUM_DETECTION_BBOX_CLASSIFY) {
-            return 0;
-        }
-    }
-
-    return 1;
-}
-
 static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Queue *lltask_queue, DNNExecBaseParams *exec_params)
 {
     switch (func_type) {
@@ -1217,7 +1180,7 @@ static int extract_lltask_from_task(DNNFunctionType func_type, TaskItem *task, Q
         task->inference_todo = 0;
         task->inference_done = 0;
 
-        if (!contain_valid_detection_bbox(frame)) {
+        if (!ff_dnn_contain_valid_detection_bbox(frame)) {
             return 0;
         }
 
-- 
2.34.1


_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2025-03-08 14:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='007401db903a$95181d10$bf485730$@gmail.com' \
    --to=m.kaindl0208@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git