From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id EC4854C2AA for ; Sat, 8 Mar 2025 14:58:48 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF6BE68F406; Sat, 8 Mar 2025 16:58:46 +0200 (EET) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58CBC68D528 for ; Sat, 8 Mar 2025 16:58:40 +0200 (EET) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-43cebe06e9eso1623805e9.3 for ; Sat, 08 Mar 2025 06:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741445919; x=1742050719; darn=ffmpeg.org; h=content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=teyxkIR3aE2rDiP9NL9L+aD9jIDr+jJ+i4eegiNyp1w=; b=D11eehoz1vswL+4i4EIWA3/2XJjT/hA7rXnYGm7NX8H/JlUKZZxNhpqihAWo0zexBT h4227gt3OgU9monZeqiY4ss7CAshVBPhwLOcOgPYLjuQy25mPk8WYf+nXmXaEcoKz9MV jWxFLehDTf0eQ1BYSHacAoLy2eke8yE+WH3jQvs1nEkUc1tzYJSLYK/4XJGYSi6jhBAr QFqsvuZ7bI2nl1N5A3/d8Wc9b8sHsyt+0UrTIneVXohaT+SGvWys7zBdLFcV2NakJbGp o3cMvCR4+34bNcwkViNBw4bn/xZbIDKpuRMH5ivV0UPs6nUM2vI0+Mpm6CdwXsMagbAV HrLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741445919; x=1742050719; h=content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=teyxkIR3aE2rDiP9NL9L+aD9jIDr+jJ+i4eegiNyp1w=; b=NDBfRpfpINo17SIFcbqD7o6bpXqcbfl64CyEjkfrsLPcy1i9Tek30suQfyRRCiLe8n hPLu8UMK0uvei7SvqR2V4QiYIVnFkmXASnGDYQLeZue7l6DC06KDCpDt0uDNugyStDOe cx5QHRFlyNWePuv4CUQe8wEhMXxpbu/kwM3BQYQJUrJvU/1Y0aeDljXtPzkge8SppgQw iH0GulVRpY8tIM14JPvBY11DtD7fzE5GQxP+n2s55Epr/FXS7hDwY234f8r4lBHfeDzu 9jpiaCcTeMUlT0L6Ir4mLpmZF4ro6eCb1/ic3ysXIVWlJtsAaoNQVgu0IKGWZn7Dv9Gk is7A== X-Gm-Message-State: AOJu0YzDUXzdgIm3ANHhduWg9xOIaiDaemHjzB/g91xkgrcCLwYbSmQz YYOp9xZTEc/vE5W3Osuz+fLuMGqQ2afeQFxj5dJMquSKN5qECMR6sDbieA== X-Gm-Gg: ASbGncv/4siwaJ1saOKIwSFDGYoh/o7JcNRvavYbBYuf5OqsHWS07OuTHSz9kHEu8VQ cmz9Phmk53XNnNLScTWGsnfF+cY9gbj3VgqCWKigIIZpZdkm4Khlk5GmDatHScXF12rcNb5jFXL eNzBYIQC6nrOLAOZIQYAsjRhSZeIoy8kRQh56wlG1tLbZIt/gDIzmXvJU53pv0D/UbUA1BkXv7t TRopZ+hQd9HiuaNqeyM8B2+BecY95hyunKCZAkcOSLHTjskm/3wCyYS1+5Q8G4sRi9hlawZcPDa rjqUKnu3hns+qJZrZKtOwu5WwtwaYG3HEdHe7GE0Lqy4BAdsD44VCBGFOmm9RePGfULdOjck1c2 LB9PGBpI+pB+WSu81 X-Google-Smtp-Source: AGHT+IHCYEzUhPp6z0b4qq6YH+aXSLIW6rRAGJBXsNytpc42++QuE6LCXv6NjwmMfrEybAVsjCag1A== X-Received: by 2002:a05:600c:190d:b0:439:99ab:6178 with SMTP id 5b1f17b1804b1-43c601cf229mr45455325e9.6.1741445918688; Sat, 08 Mar 2025 06:58:38 -0800 (PST) Received: from MK2 (80-108-16-220.cable.dynamic.surfer.at. [80.108.16.220]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43bd4353003sm120095525e9.28.2025.03.08.06.58.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Mar 2025 06:58:38 -0800 (PST) From: To: Date: Sat, 8 Mar 2025 15:58:41 +0100 Message-ID: <007401db903a$95181d10$bf485730$@gmail.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AduQOGYd2MaWLl9/Q7648ay/LB8E0A== Content-Language: en-at Subject: [FFmpeg-devel] [PATCH FFmpeg 2/15] libavfilter/dnn: move existing contain_valid_detection_bbox from openvino backend to dnn_backend_common X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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".