From patchwork Wed Jun 12 10:57:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13513 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 3435F449B42 for ; Wed, 12 Jun 2019 14:04:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 125F6689D68; Wed, 12 Jun 2019 14:04:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f194.google.com (mail-vk1-f194.google.com [209.85.221.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CB6F68056C for ; Wed, 12 Jun 2019 14:04:18 +0300 (EEST) Received: by mail-vk1-f194.google.com with SMTP id l73so3159236vkl.8 for ; Wed, 12 Jun 2019 04:04:18 -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 :mime-version:content-transfer-encoding; bh=lGdcLz5RZ+B+z4+MfQnZgP5gZTTBE49DAIbKaP1bDZo=; b=EPU69IaX7m77tnn8WdutKIUw2teJXXCl8RsOnn6AgkqB0/LukpJhTIpMrUsc37Ra75 pqptH/UtsGJPBcysh5vs/+/zJQUVJ7cTwLwwyZJKQN2sB29zJsx08XQD63NpqdHN1s8S 05kFQfUqIBSKxfVkVxZt0cH1G9+RX33MpgEguBp0e/97Xx3NpRolnytKJHdj1gspk/eJ K2L3VScM+fKE2psHjlOf08GtOlB7EeQTa386aYXXfoM4nazzBo6bA2BZsFCCUEhwaU7D oJk4vdaOjnVpVHYQAP7k0m3KSl5gGX4Nk5wocK1J9VYeXBY8xlH92TFLWTu+CPtBxMJh p3dg== 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:mime-version:content-transfer-encoding; bh=lGdcLz5RZ+B+z4+MfQnZgP5gZTTBE49DAIbKaP1bDZo=; b=Y/hnHKl45A/73IG+E652ETi5bPeizNQk+ngFOe6osdgCK1ygPvOZEcLKxWdZwKG5pr DS1/RzYvjAajMUr2bXLv3LHAEhDaTtfYWLap8kJS63TJWTgop0hv/e0g8mfB6jDzwZpI nktLn6C5nLSATXjg6SZU37MtysI6Sn7fftPy13WdWA7bkDx/wsJ+SiRzD2Qq42w496Mv wjDkeT4W27Ov4xVtiBldmsOwY4qQgWXCFKuu+y3NRHDefUl/lAzlSrxGC6Xn+oafGL5G XKw45M9rlPLwWi/cyNu53cNp0gUuId9qe1CvyAbHuE7rAlJc+iaCg6ni6jbqZWuBEi2h ql+g== X-Gm-Message-State: APjAAAXWa8SAFsYGnJzj654MEowEDW4o1RYgLoyW305iTHH1I4fSSP6L qp2HJIpyUIDM+kZYzs0AFSrvVSAYN2k= X-Google-Smtp-Source: APXvYqzoCUiFNURkHbwYTCRaDi4/D6BhegRaxA2WnZV9NTBT2Q9F43kWvWt1GQhhn4egWjZXma2J5Q== X-Received: by 2002:a65:63cd:: with SMTP id n13mr24629400pgv.153.1560337076237; Wed, 12 Jun 2019 03:57:56 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id e6sm15518868pfi.42.2019.06.12.03.57.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Jun 2019 03:57:55 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jun 2019 18:57:29 +0800 Message-Id: <20190612105731.43622-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611060730.21868-1-lance.lmwang@gmail.com> References: <20190611060730.21868-1-lance.lmwang@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 1/3] libavfilter/vf_find_rect: convert the object image to gray8 format instead of failed directly 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- doc/filters.texi | 2 +- libavfilter/vf_find_rect.c | 39 +++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index ec1c7c7591..90c57430a6 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -10150,7 +10150,7 @@ It accepts the following options: @table @option @item object -Filepath of the object image, needs to be in gray8. +Filepath of the object image. @item threshold Detection threshold, default is 0.5. diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c index d7e6579af7..ee6c3f4b45 100644 --- a/libavfilter/vf_find_rect.c +++ b/libavfilter/vf_find_rect.c @@ -28,6 +28,7 @@ #include "internal.h" #include "lavfutils.h" +#include "lswsutils.h" #define MAX_MIPMAPS 5 @@ -244,6 +245,9 @@ static av_cold int init(AVFilterContext *ctx) { FOCContext *foc = ctx->priv; int ret, i; + uint8_t *tmp_data[4] = { NULL }; + int tmp_linesize[4], width, height; + enum AVPixelFormat pix_fmt; if (!foc->obj_filename) { av_log(ctx, AV_LOG_ERROR, "object filename not set\n"); @@ -254,24 +258,37 @@ static av_cold int init(AVFilterContext *ctx) if (!foc->obj_frame) return AVERROR(ENOMEM); - if ((ret = ff_load_image(foc->obj_frame->data, foc->obj_frame->linesize, - &foc->obj_frame->width, &foc->obj_frame->height, - &foc->obj_frame->format, foc->obj_filename, ctx)) < 0) - return ret; - - if (foc->obj_frame->format != AV_PIX_FMT_GRAY8) { - av_log(ctx, AV_LOG_ERROR, "object image is not a grayscale image\n"); - return AVERROR(EINVAL); - } + if ((ret = ff_load_image(tmp_data, tmp_linesize, + &width, &height, + &pix_fmt, foc->obj_filename, ctx)) < 0) + goto error; + + /* convert object image to gray8 format with same width and height */ + foc->obj_frame->format = AV_PIX_FMT_GRAY8; + foc->obj_frame->width = width; + foc->obj_frame->height = height; + if ((ret = ff_scale_image(foc->obj_frame->data, foc->obj_frame->linesize, + foc->obj_frame->width, foc->obj_frame->height, foc->obj_frame->format, + tmp_data, tmp_linesize, width, height, pix_fmt, ctx)) < 0) + goto error; + av_freep(&tmp_data[0]); foc->needle_frame[0] = av_frame_clone(foc->obj_frame); for (i = 1; i < foc->mipmaps; i++) { foc->needle_frame[i] = downscale(foc->needle_frame[i-1]); - if (!foc->needle_frame[i]) - return AVERROR(ENOMEM); + if (!foc->needle_frame[i]) { + ret = AVERROR(ENOMEM); + goto error; + } } return 0; +error: + av_freep(&tmp_data[0]); + if (foc->obj_frame) + av_freep(&foc->obj_frame->data[0]); + av_frame_free(&foc->obj_frame); + return ret; } static const AVFilterPad foc_inputs[] = {