From patchwork Thu May 14 10:32:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 19678 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 BC5F844AAFE for ; Thu, 14 May 2020 13:33:05 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6B87B688320; Thu, 14 May 2020 13:33:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E4306808A0 for ; Thu, 14 May 2020 13:32:59 +0300 (EEST) Received: by mail-pl1-f193.google.com with SMTP id x10so1017451plr.4 for ; Thu, 14 May 2020 03:32:59 -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=AkhWpAVMcee1n+MZINvz0aa+ND4Fzz9JqOmKYidJeAc=; b=ChqeXo9ecODXC4sEbiUeRLj68DcxVgrDBtOuKBRoT6npux+zY8iFobXw/1krS/vzn7 AnG6303BlkFlaGArpZQ1upXxc37042mgrWmy4xocARYD7r6idH/XjxwZASn14tAWhRZf uyO6O/S4g8rF/SDVPIkQ3nyNI0JLjJcIcd8v6mrLYqJhAJG1Zbzjvuy3IS81ibsH49g0 quWJsRfq3CHWb4JumZdYUOGAEpEt2AC2U8liGvwId/3zikMe1p7dmWFqJvonYN1+LOxO wU5Q65OB9ydFsC0lpSAgI9vqIdYJq4r1R8gVHtW7NcMC+ALWpDyYhiVOXbnghwZpTrS9 LI2w== 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=AkhWpAVMcee1n+MZINvz0aa+ND4Fzz9JqOmKYidJeAc=; b=kd1tn3G5dHctTHREbZy7ODh131xlEPOLlJc2rxQub/7L2IIvuz5HoY2mbrMptAO9Xa Z/riXFA7BdNEeUtdWnknDP1uiLEKO8O3yrpDjzxwa2Qg/GyNHj6MTjqnh1QAq92ORMWX Wh4sgdn6G864jEHsxGGdeCqtfV5gJetnuhekKg6eI8O3j/B5txk3Pe81FPmy4LTxojp4 +bcPdidauSfLnau9UPWeHkzuojmW2THXysVkttumVgpZTUhR79C6sXCK11jI3bzED8BC IGPMmrkehhbOOeV6CMcJltdZs4keKBgZ2es15HnmX52HUzSXOkPGKBBOz9HSWCxG2R/J CIvQ== X-Gm-Message-State: AGi0PubFP3x5SwpUzDRjG+83IOkrrXMBBS+jlD67pGgxkw53d/UxRKmU Uocya8Lx5bha3pMKbh1knm0E9QzH X-Google-Smtp-Source: APiQypL5RRKf7Ro9ESyZ7PsW1URb6etx7F69hAEQKswC1NoyL7hyFnI6mQpCVoO23LKeUrwI95X4tQ== X-Received: by 2002:a17:90a:fc8c:: with SMTP id ci12mr40100844pjb.104.1589452377356; Thu, 14 May 2020 03:32:57 -0700 (PDT) Received: from vpn2.localdomain ([161.117.202.209]) by smtp.gmail.com with ESMTPSA id t64sm1920815pgd.24.2020.05.14.03.32.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2020 03:32:56 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 18:32:47 +0800 Message-Id: <1589452367-7681-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1589382763-28061-4-git-send-email-lance.lmwang@gmail.com> References: <1589382763-28061-4-git-send-email-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v3 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 | 13 +++++++++++++ libavfilter/vf_drawbox.c | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 76e12ef..f838dfc 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -9337,6 +9337,12 @@ 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 @var{integer} +Draw the box onto the position of the nth face as detected by the ocv filter's +facedetect mode. If no face detection metadata exists +then the filter will use the specified box parameters instead. + @end table The parameters for @var{x}, @var{y}, @var{w} and @var{h} and @var{t} are expressions containing the @@ -9405,6 +9411,13 @@ 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 a red box onto the position of the first face as detected by the ocv +filter's facedetect method. +@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 } };