From patchwork Sat Jun 15 23:26:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13551 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 95B014478B9 for ; Sun, 16 Jun 2019 02:27:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6A54A68A79D; Sun, 16 Jun 2019 02:27:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 28B806800E4 for ; Sun, 16 Jun 2019 02:27:09 +0300 (EEST) Received: by mail-pf1-f196.google.com with SMTP id j2so3590109pfe.6 for ; Sat, 15 Jun 2019 16:27:09 -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=W7tLY43WsR7Sz79V3e1auLu31LkElLOoawkibXsJ1hg=; b=iCasxH89dLodv7WjOcuI9GU4eVUjVACwal0wHRIkFg8TB56ZhVjNqCeeLayhixac0T HrcK825NHIOsWWHd12iUnYsl7lcHpqaKVfnAqU7oP+44JADpHVv8ihMfoBJkpP1PV4XD 486O2y5MLcKUhEOq4K8acmS9Kd1kOspQVWbX06BwAwZV06UE1UQtokR/UEy74JmRUOxR Y+KC4jQ51XhTXvcA/ZCjRXB+jDBX3t+xUIunqrE0pF1Lxo7xa4C0inwHNea09woz2fxJ 4XrUovyMeh9Wkyy+v29rYFr8l2g3UHKAXQKpNlZcw3q1b34C3wln0U+J9Sd6mPBVmiaV bVLg== 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=W7tLY43WsR7Sz79V3e1auLu31LkElLOoawkibXsJ1hg=; b=bKCGKQum1GS50i/6Y2QG/w1bjTlLnhoY5RZGDiE4e8GhoaMId6GPnRQDVZIJO8tm74 0HC67a3FlkYcu6IUi6GNgi4zpKulBujzv6f1uLvYIkYNYTF1qptvb1pCn6tFrCiQxy2P xq/dKb7zp7gAQ6L5u/OV5GbVNHrC32Nm4JJuylt4JiUWEk44HB84k17/MqnVMgttdUHN NTC97nyG1hOlOYeLlgCQ/LEgsxxj/8qXIhyHDV1LUz4yXkV/8Z75RMUnCTG5V0Pr39Sy hROVwWRitewiBETeiwp+r6Z7exJotrb6FgRjBqIzYvfd0E4MmBCzppjr+jC/JHoA/VB1 cmxw== X-Gm-Message-State: APjAAAVd53h6m7epdkkOOyktXmKpFVLYcEZRtJzdnOpZQQQfR3JMCSyb QbeEEdlOhNKFpvkKGnxzE3mNaNv6oQI= X-Google-Smtp-Source: APXvYqyQzwO90D1Z28gk/8DJGWJyoqOVh0wbrTYYnnhenxTpa88CSzSwjI7rqim8xQYqyNxyAfl0kw== X-Received: by 2002:a63:84c1:: with SMTP id k184mr39965445pgd.7.1560641227007; Sat, 15 Jun 2019 16:27:07 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id n1sm6295446pgv.15.2019.06.15.16.27.05 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 15 Jun 2019 16:27:06 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sun, 16 Jun 2019 07:26:55 +0800 Message-Id: <1560641215-64931-1-git-send-email-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <20190612105731.43622-1-lance.lmwang@gmail.com> References: <20190612105731.43622-1-lance.lmwang@gmail.com> Subject: [FFmpeg-devel] [PATCH v6] 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 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 | 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 ec1c7c7..4ee6a57 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, it will be converted to GRAY8 automatically. @item threshold Detection threshold, default is 0.5. diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c index d7e6579..ee6c3f4 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[] = {