[FFmpeg-devel] [POF] libopencv smooth filter

Michael Niedermayer michaelni
Fri Sep 10 12:13:05 CEST 2010


On Fri, Sep 10, 2010 at 11:46:39AM +0200, Stefano Sabatini wrote:
> On date Tuesday 2010-09-07 19:52:00 +0200, Michael Niedermayer encoded:
> > On Sun, Sep 05, 2010 at 11:34:16PM +0200, Stefano Sabatini wrote:
> > > On date Sunday 2010-09-05 18:42:35 +0200, Michael Niedermayer encoded:
> > > > On Tue, Aug 03, 2010 at 03:05:11AM +0200, Stefano Sabatini wrote:
> > > > [...]
> > > > > + *
> > > > > + * 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
> > > > > + */
> > > > > +
> > > > > +/**
> > > > > + * @file
> > > > > + * libopencv wrapper functions
> > > > > + */
> > > > > +
> > > > > +#include "opencv/cv.h"
> > > > > +#include "opencv/cxtypes.h"
> > > > > +#include "avfilter.h"
> > > > > +
> > > > > +static void fill_iplimage_from_picref(IplImage *img, const AVFilterPicRef *picref, enum PixelFormat pixfmt)
> > > > > +{
> > > > > +    int i;
> > > > > +    IplImage *tmpimg;
> > > > > +
> > > > > +    struct {
> > > > > +        enum PixelFormat pixfmt;
> > > > > +        int depth;
> > > > > +        int channels;
> > > > > +    } entry, pixfmt_iplimage_map[] = {
> > > > > +        { PIX_FMT_GRAY8, IPL_DEPTH_8U, 1 },
> > > > > +        { PIX_FMT_BGRA , IPL_DEPTH_8U, 4 },
> > > > > +        { PIX_FMT_BGR24, IPL_DEPTH_8U, 3 },
> > > > > +        { PIX_FMT_NONE                   }
> > > > > +    };
> > > > > +
> > > > > +    for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_iplimage_map); i++) {
> > > > > +        entry = pixfmt_iplimage_map[i];
> > > > > +        if (pixfmt == entry.pixfmt)
> > > > > +            break;
> > > > > +    }
> > > > 
> > > > > +    if (entry.pixfmt == PIX_FMT_NONE)
> > > > > +        assert(1);
> > > > 
> > > > ?
> > > 
> > > Ehm I suppose I can skip this.
> > > 
> > > > [...]
> > > > > +#if CONFIG_OCV_SMOOTH_FILTER
> > > > > +
> > > > > +typedef struct {
> > > > > +    int type;
> > > > > +    int    param1, param2;
> > > > > +    double param3, param4;
> > > > > +} SmoothContext;
> > > > > +
> > > > > +static av_cold int smooth_init(AVFilterContext *ctx, const char *args, void *opaque)
> > > > > +{
> > > > > +    SmoothContext *smooth = ctx->priv;
> > > > > +    char type_str[128] = "gaussian";
> > > > > +
> > > > > +    smooth->param1 = 3;
> > > > > +    smooth->param2 = 0;
> > > > > +    smooth->param3 = 0.0;
> > > > > +    smooth->param4 = 0.0;
> > > > > +
> > > > > +    if (args)
> > > > > +        sscanf(args, "%127[^:]:%d:%d:%lf:%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4);
> > > > > +
> > > > > +    if      (!strcmp(type_str, "blur"         )) smooth->type = CV_BLUR;
> > > > > +    else if (!strcmp(type_str, "blur_no_scale")) smooth->type = CV_BLUR_NO_SCALE;
> > > > > +    else if (!strcmp(type_str, "median"       )) smooth->type = CV_MEDIAN;
> > > > > +    else if (!strcmp(type_str, "gaussian"     )) smooth->type = CV_GAUSSIAN;
> > > > > +    else if (!strcmp(type_str, "bilateral"    )) smooth->type = CV_BILATERAL;
> > > > > +    else {
> > > > > +        av_log(ctx, AV_LOG_ERROR, "Smoothing type '%s' unknown\n.", type_str);
> > > > > +        return AVERROR(EINVAL);
> > > > > +    }
> > > > 
> > > > its a bit ugly, to implement such wraper for each filter
> > > 
> > > What do you exactly mean? For opencv there is no way to implement a
> > > general wrapper (as opposed to frei0r) because for filtering we have
> > > to use each time a different function with a different interface.
> > 
> > so each function need to be wraped in a generic interface, it seems you do
> > more than that.
> 
> I can't understand yet. Note that my plan was to share different

you add code that is shareable in each filter wraper.


> opencv filters in the same file, so at least the

thats good but you try to implement each of these as a independant and
seperate avfilter (more or less at least) and this is bad.
each filter should only have enough code in its wraper to get them all
onto a common interface and this common interface could be handled by a
single avfilter.
I think thats simpler once a few filters are there.


> fill_iplimage_from_picref() and fill_picref_from_iplimage() functions
> will be shared.
> 

> Or do you mean to have something like AVOption for specifying the
> options?

iam still scared of the last time this was tried


> BTW I remember you said you was working on AVOption cleanup
> (as discussed more than one year ago), is that true or should I revive
> the old AVOption discussion?

theres alot i wanted to work on, it cant hurt if you ping the thread you
are thinking of

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100910/bd5b9235/attachment.pgp>



More information about the ffmpeg-devel mailing list