From patchwork Wed May 13 14:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19666 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 E1D1844A624 for ; Wed, 13 May 2020 17:42:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C841A6898C0; Wed, 13 May 2020 17:42:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 74E44687F7D for ; Wed, 13 May 2020 17:42:48 +0300 (EEST) Received: by mail-pf1-f194.google.com with SMTP id y25so8092814pfn.5 for ; Wed, 13 May 2020 07:42:48 -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=7f4WYiLWcUNolIgLGdaKnzN2bmxJfu2q36a4H5Uz37g=; b=iHKoZ/dLxgvRBsL1WPz9RhTUFYay1QvlGju3T/BSQ0R77O61382MzRso7Wlt+X6npn +RbM6cKGWtR96Du9stKgQezoct6oa9rXyii495PK7zJmuIuEz8fq+2aAcisKfmxwzNdr JQWm5qIpySTuwUlKYotTWGcWH/hnZdefck3UhquR8lVU4UHCY4MwJ/Bt57Acg7bjoK6w LC5V7JwR6ufY6fIMDGSybu/IMZFIscTTU/oRKJktX8Uc4XAKzJWumv8lYQtjyUXef9w7 XtWMVr2Z1cxqJ2CnOSZZpuAuYXO6lkok/7OM2fnENl8S60h7zpOoTpXHVBVyOFdqUFzL dS/g== 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=7f4WYiLWcUNolIgLGdaKnzN2bmxJfu2q36a4H5Uz37g=; b=Ypw8ez3u6IgL7mu0gosOPkSHRMb5+mtctkfe5IpM+nBv3+z37U3hM3nGeersMlmWKs RnLw302hcq29Qcnzv/aIT3+S670BGGH6gTHqElCT4b2Qyyk/dEJFL+DsaAFU5UHInwyp IH46TW/fROWbMWOoXWdW8tu4hyiyUr6T16dAJHOnco4Onqgq+JXbIFa0GM4DK43LwHw9 YDsEE8aDbYxdMvV59sNqJpxKQ4w0ZNkxVpYuk26W8+9J4HPxRL677draeQrfQDhot4AW 5WtRCj30/6vY23BWL9Eq6XEhuX0IqbxHB3s1YNMsdw1MqHSXY/fOp5BKQYVcGdEEDp3+ JBOw== X-Gm-Message-State: AOAM530ml7L9qlZkLvUZldFZuevSGSv9tATkKHKbcLhD2gI53792UEdq QqJW6v1SGobLPok+N82MoxDwSzGi X-Google-Smtp-Source: ABdhPJy5HDdWKbspg9Eh2IofPYEdMw/LcivCu4yZneRzEif6Aa4GWWEqbBzQPeOPNSd5N1heFz4vPQ== X-Received: by 2002:a62:fc52:: with SMTP id e79mr2926051pfh.297.1589380966568; Wed, 13 May 2020 07:42:46 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id c184sm791410pfc.57.2020.05.13.07.42.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 May 2020 07:42:46 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 May 2020 22:42:37 +0800 Message-Id: <1589380957-23603-3-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1589380957-23603-1-git-send-email-lance.lmwang@gmail.com> References: <1589380957-23603-1-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] 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 e50dcf3..a1a4e81 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -9336,6 +9336,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 @@ -9404,6 +9408,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 } };