From patchwork Fri Mar 26 08:09:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guo, Yejun" X-Patchwork-Id: 26614 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 39C4144B35A for ; Fri, 26 Mar 2021 10:21:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1EF3E68AA2A; Fri, 26 Mar 2021 10:21:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 160EE68086B for ; Fri, 26 Mar 2021 10:21:00 +0200 (EET) IronPort-SDR: cPnU0o17C7q9ARTULC2jqsZ8MGuWlaDEOeuURtCOHGEdvbE/aD0F6URepvXOL4bzYo+kzyjdLl +nD84bdyUaww== X-IronPort-AV: E=McAfee;i="6000,8403,9934"; a="255100945" X-IronPort-AV: E=Sophos;i="5.81,279,1610438400"; d="scan'208";a="255100945" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2021 01:20:54 -0700 IronPort-SDR: UetQNd8QYj7I1m9S4QlE44KhdvtuHTMc+jqXoL0hIv+D+mU8FZBXIQar7B3AxDJP4RxJ+LuYTf jKLNmQnPWRqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,279,1610438400"; d="scan'208";a="443227475" Received: from yguo18-skl-u1604.sh.intel.com ([10.239.159.53]) by fmsmga002.fm.intel.com with ESMTP; 26 Mar 2021 01:20:53 -0700 From: "Guo, Yejun" To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Mar 2021 16:09:29 +0800 Message-Id: <20210326080931.2952-4-yejun.guo@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210326080931.2952-1-yejun.guo@intel.com> References: <20210326080931.2952-1-yejun.guo@intel.com> Subject: [FFmpeg-devel] [PATCH V6 4/6] lavu: add side data AV_FRAME_DATA_BOUNDING_BOXES 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: yejun.guo@intel.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Guo, Yejun --- doc/APIchanges | 2 ++ libavutil/Makefile | 1 + libavutil/boundingbox.h | 79 +++++++++++++++++++++++++++++++++++++++++ libavutil/frame.c | 1 + libavutil/frame.h | 7 ++++ 5 files changed, 90 insertions(+) create mode 100644 libavutil/boundingbox.h diff --git a/doc/APIchanges b/doc/APIchanges index b41dadee8d..160b020d9d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,8 @@ libavutil: 2017-10-21 API changes, most recent first: +2021-03-xx - xxxxxxxxxx - lavu 56.xx.100 - frame.h boundingbox.h + Add AV_FRAME_DATA_BOUNDING_BOXES 2021-03-21 - xxxxxxxxxx - lavu 56.72.100 - frame.h Deprecated av_get_colorspace_name(). diff --git a/libavutil/Makefile b/libavutil/Makefile index 27bafe9e12..7e1dc713ac 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -11,6 +11,7 @@ HEADERS = adler32.h \ avutil.h \ base64.h \ blowfish.h \ + boundingbox.h \ bprint.h \ bswap.h \ buffer.h \ diff --git a/libavutil/boundingbox.h b/libavutil/boundingbox.h new file mode 100644 index 0000000000..5e2fdd55e9 --- /dev/null +++ b/libavutil/boundingbox.h @@ -0,0 +1,79 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_BOUNDINGBOX_H +#define AVUTIL_BOUNDINGBOX_H + +#include "libavutil/rational.h" + +typedef struct AVBoundingBox { + /** + * Distance in pixels from the top edge of the frame to top + * and bottom, and from the left edge of the frame to left and + * right, defining the bounding box. + */ + int top; + int left; + int bottom; + int right; + +#define AV_BBOX_LABEL_NAME_MAX_SIZE 32 + + /** + * Detect result with confidence + */ + char detect_label[AV_BBOX_LABEL_NAME_MAX_SIZE]; + AVRational detect_confidence; + + /** + * At most 4 classifications based on the detected bounding box. + * For example, we can get max 4 different attributes with 4 different + * DNN models on one bounding box. + * classify_count is zero if no classification. + */ +#define AV_NUM_BBOX_CLASSIFY 4 + uint32_t classify_count; + char classify_labels[AV_NUM_BBOX_CLASSIFY][AV_BBOX_LABEL_NAME_MAX_SIZE]; + AVRational classify_confidences[AV_NUM_BBOX_CLASSIFY]; +} AVBoundingBox; + +typedef struct AVBoundingBoxHeader { + /** + * Information about how the bounding box is generated. + * for example, the DNN model name. + */ + char source[128]; + + /** + * The size of frame when it is detected. + */ + int frame_width; + int frame_height; + + /** + * Number of bounding boxes. + */ + uint32_t nb_bbox; + + /** + * Pointer to the array of AVBoundingBox. + */ + AVBoundingBox bboxes[]; +} AVBoundingBoxHeader; + +#endif diff --git a/libavutil/frame.c b/libavutil/frame.c index 31a2117b82..99080af777 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -853,6 +853,7 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type) case AV_FRAME_DATA_VIDEO_ENC_PARAMS: return "Video encoding parameters"; case AV_FRAME_DATA_SEI_UNREGISTERED: return "H.26[45] User Data Unregistered SEI message"; case AV_FRAME_DATA_FILM_GRAIN_PARAMS: return "Film grain parameters"; + case AV_FRAME_DATA_BOUNDING_BOXES: return "Bounding boxes"; } return NULL; } diff --git a/libavutil/frame.h b/libavutil/frame.h index a5ed91b20a..9b7145199c 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -198,6 +198,13 @@ enum AVFrameSideDataType { * Must be present for every frame which should have film grain applied. */ AV_FRAME_DATA_FILM_GRAIN_PARAMS, + + /** + * Bounding boxes for object detection and classification, the data is a BoundingBoxHeader + * followed with an array of BoudingBox, and BoundingBoxHeader.nb_bbox is the number of + * array element. + */ + AV_FRAME_DATA_BOUNDING_BOXES, }; enum AVActiveFormatDescription {