From patchwork Wed May 13 15:12:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19672 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E567F44B25E for ; Wed, 13 May 2020 18:13:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CC5FF689A6C; Wed, 13 May 2020 18:13:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1BE27689963 for ; Wed, 13 May 2020 18:13:23 +0300 (EEST) Received: by mail-pl1-f195.google.com with SMTP id b12so5024109plz.13 for ; Wed, 13 May 2020 08:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JPwcg53FbneaQjCfSlrDH5tBtlOjR0xig7Ug/rbahXI=; b=fvnGeWqbS2LQWZkoId7gLHvbBBQ7ovBNvndSsBMLXle10Q5w3uraHRWo11i+XQjwqZ 70Hs5h5OSDt0yppha13tDEQIh9SCM0CLhS+ErS8xOZRzHewKJeJBrT2YzQxFlTWpGrht zLMBrdWVjSnmpz2QtRysua5sWXEd3ymcMWD7WqIfV2J68XNK3YfXVCJtYgHB2wLPcBFA S8mRY/IJZjAV9rScD3coqecLEgs/WIRu6ZOQDCLeBEeOC0RDqsdXZBWDp4ylDipHXPii MH2L2kPo06ejToCP00j70FveDPjo1GG5d06Ni0EN+4g2MAxPhkorW7KqICj9EVNRfJWd Riuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JPwcg53FbneaQjCfSlrDH5tBtlOjR0xig7Ug/rbahXI=; b=qvbsmc1EvQ35GeGK7cRImgVR28/P2icbJSORjR7SE/reRJqoCLZI9uhNlPbdt4oWML r7Fi0a5rqT/lM1yeMkLXJRd3RnZbJ0IbO9Bes1GPLjrQK+ffIZFI0R7rqF9JsLsMq25c lX/7Lqyr67Rd2zbZFClGxvgNEhZUKYBok0mamSqSt6AEPfaqpMMzB+n+uQhyS9DeJ9dK ODY6/xpc0+sgzZzfc4KP/sAepSH9rAh+/7INsKjXcrJyCeIXQ8UgcPMU4es99yF/ttyQ 0oA1UyKnRXtvcJAOE3KqbVOKCAlMIx/StbVRqSvC0pkOTu/7Uywhx6PbAf/sOuWxLwuO 4HQA== X-Gm-Message-State: AOAM533Z+SmCvlf3RcZxox4DM685e5TRiPD8IAVDnRkQ674mFVBbjt5R d2Q3TTpSYgwZBO9yc5uGECKdv1BX X-Google-Smtp-Source: ABdhPJyaJ+UNdlxLdkbQUJYm/B4iHiv232E96qyOytDGMkjSF4GRNgZ+qOpOv0hT9skVGviefyhvxA== X-Received: by 2002:a17:90a:db0f:: with SMTP id g15mr2911502pjv.8.1589382801200; Wed, 13 May 2020 08:13:21 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id t64sm43309pgd.24.2020.05.13.08.13.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 May 2020 08:13:20 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 May 2020 23:12:43 +0800 Message-Id: <1589382763-28061-4-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1589382763-28061-1-git-send-email-lance.lmwang@gmail.com> References: <1589382763-28061-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v2 4/4] avfilter/vf_drawbox: support draw specific face by facedetect metadata X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Limin Wang MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- doc/filters.texi | 10 ++++++++++ libavfilter/vf_drawbox.c | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 76e12ef..bf9043c 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -9337,6 +9337,10 @@ See below for the list of accepted constants. Applicable if the input has alpha. With value @code{1}, the pixels of the painted box will overwrite the video's color and alpha pixels. Default is @code{0}, which composites the box onto the input, leaving the video's alpha intact. + +@item face +Draw the box by the facedetect metadata for the specific face. + @end table The parameters for @var{x}, @var{y}, @var{w} and @var{h} and @var{t} are expressions containing the @@ -9405,6 +9409,12 @@ Draw a 2-pixel red 2.40:1 mask: @example drawbox=x=-t:y=0.5*(ih-iw/2.4)-t:w=iw+t*2:h=iw/2.4+t*2:t=2:c=red @end example + +@item +draw the box with red color for the first face by metadata if its postion is detected: +@example +ocv=filter_name=facedetect:filter_params=facedetect=./haarcascade_frontalface_alt.xml,drawbox=face=0:color=red +@end example @end itemize @subsection Commands diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index 21d520e..239a149 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -81,6 +81,7 @@ typedef struct DrawBoxContext { char *t_expr; ///< expression for thickness int have_alpha; int replace; + int face; } DrawBoxContext; static const int NUM_EXPR_EVALS = 5; @@ -220,6 +221,31 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) int plane, x, y, xb = s->x, yb = s->y; unsigned char *row[4]; + if (s->face >= 0) { + AVDictionaryEntry *ex, *ey, *ew, *eh; + char key2[128]; + AVDictionary *metadata = frame->metadata; + + snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", s->face, "x"); + ex = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE); + + snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", s->face, "y"); + ey = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE); + + snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", s->face, "w"); + ew = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE); + + snprintf(key2, sizeof(key2), "lavfi.facedetect.%d.%s", s->face, "h"); + eh = av_dict_get(metadata, key2, NULL, AV_DICT_MATCH_CASE); + + if (ex && ey && ew && eh) { + xb = s->x = strtol(ex->value, NULL, 10); + yb = s->y = strtol(ey->value, NULL, 10); + s->w = strtol(ew->value, NULL, 10); + s->h = strtol(eh->value, NULL, 10); + } + } + if (s->have_alpha && s->replace) { for (y = FFMAX(yb, 0); y < frame->height && y < (yb + s->h); y++) { row[0] = frame->data[0] + y * frame->linesize[0]; @@ -323,6 +349,7 @@ static const AVOption drawbox_options[] = { { "thickness", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, 0, 0, FLAGS }, { "t", "set the box thickness", OFFSET(t_expr), AV_OPT_TYPE_STRING, { .str="3" }, 0, 0, FLAGS }, { "replace", "replace color & alpha", OFFSET(replace), AV_OPT_TYPE_BOOL, { .i64=0 }, 0, 1, FLAGS }, + { "face", "set which face to draw with metadata", OFFSET(face), AV_OPT_TYPE_INT, { .i64=-1 }, -1, 256, FLAGS }, { NULL } };