From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 15BF14D8E0 for ; Wed, 26 Feb 2025 13:57:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8477568CA07; Wed, 26 Feb 2025 15:57:41 +0200 (EET) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4114068C720 for ; Wed, 26 Feb 2025 15:57:34 +0200 (EET) Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-388cae9eb9fso3774107f8f.3 for ; Wed, 26 Feb 2025 05:57:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740578253; x=1741183053; darn=ffmpeg.org; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=6hpXCRJQ/SiIDesQL05IP1MTLiJ6YSht8vwOhQiA60U=; b=c1iP9qFB2pd6LOQWZuJ2YxVtec7EDXbQZ7LJbd862XSGrc+LYbIxOy3NzB55rlCpVj zw6q0fpmLfdFDEweSJPp5x1N0jz1H5cH8vjQL6htR1S55W2nU1UMbx+T1zrF+la6jmmw HpSNzYh9AUnJf252X28y1ETkeCkHZ9dqFfRtJsb7TcUvkilALz8eFb+Sq+lXept9dHiS 1rc3CQc8Q14Sj5MANi4uU4Yy71ismY2NbYz49z918jtJYqLKUs9z6zqgcEILJHlvEnC8 ZhLwxvqz03l6py2ZQ7Zjp3WLz2d7Uk+qAvZ6QD87y5WsCbX63JLkAUkuymIUJj4UxT7/ Szcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740578253; x=1741183053; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=6hpXCRJQ/SiIDesQL05IP1MTLiJ6YSht8vwOhQiA60U=; b=IkM01xOeQBMUp/K4cxVM2ViL5vz/poHtFblGQ9UBcPPe/XaS2axqURE+KijTuySxf0 kNndkCYOkKDPw+oun/mSUPtmofijL7EGrCo4gntRxqO7pKP0slB+1GnMqsS4q4D1HavY 0l9IYbICP0npCeKkoz5hEXs5amMuSa9tAgcMwZOvjubJG/yI2D+yGsgfgZQApfzYRuDn VPUlJXVBHGou/na9e2HBumdee4Px1mpyfjaPXvBw1GrukDC4JhZbpF3x23cqwtRqYiol i3IA9wJe4iwTb4HO4++L+s/0OY94SibL9RYepH3YBSZtMn+tMvXenKRuvZbIj9IrG2d4 BKtg== X-Gm-Message-State: AOJu0YwFij/LkXsCdrF4iLr662+fd6usZyjmFrL9HhQbPHlfc+huA5lJ YXGa5Gzr6oRIlo0jR5LrcuJbxB2xMVmEw0ptpftf1onnb4u7YnkwyrfNZg== X-Gm-Gg: ASbGnctwBqNPBiGIfwjAZY/G74EvPOcKF7WQiALcVfiskDJKdgOKbbUMIhzKL/k5Y31 7wY8hjvkBRSOrdLjf2482Ww2uRWUZbsjI5f8e2NWJJOEHL1gAxvVoFIDaJyEWMVWgxea9klJbop htSICYX2nMB65/D/m2SYMnZcgR30KD088/J3C/8EhWDTM/HUcjuVm5kiINxFoYixyCyiZPIw8BL 11MmMAcJKH3DV9dXzjG8KiCBggTmhA7HliXox+korzGLAKzf6rJVzZh2qGYOVg/vgVWJMdkkxTw +S6+Nyx3rVloqgReCu9xJ/IeF3CyJb/lsNBcwrSAMEghsnLspdlvKVtnCZDnaKp9AEOd1HUI8Zr MeJ5Y X-Google-Smtp-Source: AGHT+IHpc1U96uu+yQBgoufhIo7u+2mJaQvi4L2ICxbVh/NYHqM480zrGww+CnofcMTJLQ+fQLl3jw== X-Received: by 2002:a05:6000:4108:b0:390:dfeb:c6aa with SMTP id ffacd0b85a97d-390dfebc7camr160726f8f.26.1740578253293; Wed, 26 Feb 2025 05:57:33 -0800 (PST) Received: from ?IPV6:2001:9e8:1d8b:5400:78d5:4c81:c4fb:f3ab? ([2001:9e8:1d8b:5400:78d5:4c81:c4fb:f3ab]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390cd8fbc31sm5560230f8f.85.2025.02.26.05.57.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Feb 2025 05:57:32 -0800 (PST) Message-ID: <6c4d8098-bb57-4f7c-b86b-9221492b7ced@gmail.com> Date: Wed, 26 Feb 2025 14:57:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Leandro Santiago To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/dnn: do not manually parse anchors filter option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Instead, rely on AV_OPT_TYPE_FLAG_ARRAY, which will automatically perform the parsing. Signed-off-by: Leandro Santiago --- libavfilter/vf_dnn_detect.c | 43 ++++--------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/libavfilter/vf_dnn_detect.c b/libavfilter/vf_dnn_detect.c index 590e4e256d..cd70c64e98 100644 --- a/libavfilter/vf_dnn_detect.c +++ b/libavfilter/vf_dnn_detect.c @@ -31,6 +31,7 @@ #include "libavutil/avstring.h" #include "libavutil/detection_bbox.h" #include "libavutil/fifo.h" +#include typedef enum { DDMT_SSD, @@ -53,11 +54,12 @@ typedef struct DnnDetectContext { AVFifo *bboxes_fifo; int scale_width; int scale_height; - char *anchors_str; float *anchors; int nb_anchor; } DnnDetectContext; +static const AVOptionArrayDef anchor_array_def = { .sep = '&' }; + #define OFFSET(x) offsetof(DnnDetectContext, dnnctx.x) #define OFFSET2(x) offsetof(DnnDetectContext, x) #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM @@ -79,7 +81,7 @@ static const AVOption dnn_detect_options[] = { { "cell_w", "cell width", OFFSET2(cell_w), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INTMAX_MAX, FLAGS }, { "cell_h", "cell height", OFFSET2(cell_h), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INTMAX_MAX, FLAGS }, { "nb_classes", "The number of class", OFFSET2(nb_classes), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INTMAX_MAX, FLAGS }, - { "anchors", "anchors, splited by '&'", OFFSET2(anchors_str), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS }, + { "anchors", "anchors, splited by '&'", OFFSET2(anchors), AV_OPT_TYPE_FLOAT | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &anchor_array_def }, FLT_MIN, FLT_MAX, FLAGS }, { NULL } }; @@ -106,34 +108,6 @@ static int dnn_detect_get_label_id(int nb_classes, int cell_size, float *label_d return label_id; } -static int dnn_detect_parse_anchors(char *anchors_str, float **anchors) -{ - char *saveptr = NULL, *token; - float *anchors_buf; - int nb_anchor = 0, i = 0; - while(anchors_str[i] != '\0') { - if(anchors_str[i] == '&') - nb_anchor++; - i++; - } - nb_anchor++; - anchors_buf = av_mallocz(nb_anchor * sizeof(**anchors)); - if (!anchors_buf) { - return 0; - } - for (int i = 0; i < nb_anchor; i++) { - token = av_strtok(anchors_str, "&", &saveptr); - if (!token) { - av_freep(&anchors_buf); - return 0; - } - anchors_buf[i] = strtof(token, NULL); - anchors_str = NULL; - } - *anchors = anchors_buf; - return nb_anchor; -} - /* Calculate Intersection Over Union */ static float dnn_detect_IOU(AVDetectionBBox *bbox1, AVDetectionBBox *bbox2) { @@ -701,15 +675,6 @@ static av_cold int dnn_detect_init(AVFilterContext *context) } } - if (ctx->anchors_str) { - ret = dnn_detect_parse_anchors(ctx->anchors_str, &ctx->anchors); - if (!ctx->anchors) { - av_log(context, AV_LOG_ERROR, "failed to parse anchors_str\n"); - return AVERROR(EINVAL); - } - ctx->nb_anchor = ret; - } - return 0; } -- 2.48.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".