* [FFmpeg-devel] [PATCH v2 FFmpeg 3/20] libavfilter/dnn: move contain_valid_detection_bbox to dnn_backend_common
@ 2025-03-10 19:51 m.kaindl0208
0 siblings, 0 replies; only message in thread
From: m.kaindl0208 @ 2025-03-10 19:51 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: MaximilianKaindl <m.kaindl0208@gmail.com>
---
libavfilter/dnn/dnn_backend_common.c | 38 +++++++++++++++++++++++++
libavfilter/dnn/dnn_backend_common.h | 8 ++++++
libavfilter/dnn/dnn_backend_openvino.c | 39 +-------------------------
3 files changed, 47 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..b5b15bc2f6 100644
--- a/libavfilter/dnn/dnn_backend_common.h
+++ b/libavfilter/dnn/dnn_backend_common.h
@@ -157,4 +157,12 @@ 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".
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-03-10 19:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-10 19:51 [FFmpeg-devel] [PATCH v2 FFmpeg 3/20] libavfilter/dnn: move contain_valid_detection_bbox to dnn_backend_common m.kaindl0208
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