From: "Chen, Wenbin" <wenbin.chen-at-intel.com@ffmpeg.org> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter/dnn: do not manually parse anchors filter option Date: Thu, 27 Feb 2025 02:38:57 +0000 Message-ID: <IA1PR11MB63961488A9EB30FFF2157B46F8CD2@IA1PR11MB6396.namprd11.prod.outlook.com> (raw) In-Reply-To: <6c4d8098-bb57-4f7c-b86b-9221492b7ced@gmail.com> > Instead, rely on AV_OPT_TYPE_FLAG_ARRAY, which will automatically > perform the parsing. > > Signed-off-by: Leandro Santiago <leandrosansilva@gmail.com> > --- > 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 <float.h> > > 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 > LGTM. Thanks Wenbin > > _______________________________________________ > 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". _______________________________________________ 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".
prev parent reply other threads:[~2025-02-27 2:39 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-02-26 13:57 Leandro Santiago 2025-02-27 2:38 ` Chen, Wenbin [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=IA1PR11MB63961488A9EB30FFF2157B46F8CD2@IA1PR11MB6396.namprd11.prod.outlook.com \ --to=wenbin.chen-at-intel.com@ffmpeg.org \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git