[FFmpeg-devel] [PATCH 2/4] Implement ocv_dilate libopencv filter wrapper.
Michael Niedermayer
michaelni
Mon Sep 13 18:31:59 CEST 2010
On Sun, Sep 12, 2010 at 08:19:48PM +0200, Stefano Sabatini wrote:
> On date Sunday 2010-09-12 13:07:45 +0200, Michael Niedermayer encoded:
> > On Sat, Sep 11, 2010 at 03:59:18PM +0200, Stefano Sabatini wrote:
> > > ---
> > > configure | 1 +
> > > libavfilter/Makefile | 1 +
> > > libavfilter/allfilters.c | 1 +
> > > libavfilter/vf_libopencv.c | 158 ++++++++++++++++++++++++++++++++++++++++++++
> > > 4 files changed, 161 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/configure b/configure
> > > index 26db167..9453fc9 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -1394,6 +1394,7 @@ udp_protocol_deps="network"
> > >
> > > # filters
> > > ocv_smooth_filter_deps="libopencv"
> > > +ocv_dilate_filter_deps="libopencv"
> > >
> > > # libraries
> > > avdevice_deps="avcodec avformat"
> > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > > index a15c3f1..394b674 100644
> > > --- a/libavfilter/Makefile
> > > +++ b/libavfilter/Makefile
> > > @@ -23,6 +23,7 @@ OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o
> > > OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o
> > > OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o
> > > OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
> > > +OBJS-$(CONFIG_OCV_DILATE_FILTER) += vf_libopencv.o
> > > OBJS-$(CONFIG_OCV_SMOOTH_FILTER) += vf_libopencv.o
> > > OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
> > > OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o
> > > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> > > index fb84968..da1fedb 100644
> > > --- a/libavfilter/allfilters.c
> > > +++ b/libavfilter/allfilters.c
> > > @@ -43,6 +43,7 @@ void avfilter_register_all(void)
> > > REGISTER_FILTER (HFLIP, hflip, vf);
> > > REGISTER_FILTER (NOFORMAT, noformat, vf);
> > > REGISTER_FILTER (NULL, null, vf);
> > > + REGISTER_FILTER (OCV_DILATE, ocv_dilate, vf);
> > > REGISTER_FILTER (OCV_SMOOTH, ocv_smooth, vf);
> > > REGISTER_FILTER (PAD, pad, vf);
> > > REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf);
> > > diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
> > > index 63d5b61..6c535f0 100644
> > > --- a/libavfilter/vf_libopencv.c
> > > +++ b/libavfilter/vf_libopencv.c
> > > @@ -63,6 +63,164 @@ static int query_formats(AVFilterContext *ctx)
> > >
> > > static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
> > >
> > > +static int read_shape_from_file(int *cols, int *rows, int **values, const char *filename, void *log_ctx)
> > > +{
> > > + char *p, *buf;
> > > + size_t size;
> > > + int i, j, w;
> > > + FILE *f = fopen(filename, "rb");
> > > + char *line;
> > > +
> > > + *cols = *rows = 0;
> > > +
> > > + if (!f) {
> > > + av_log(log_ctx, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, strerror(errno));
> > > + return AVERROR(errno);
> > > + }
> > > + fseek(f, 0, SEEK_END);
> > > + size = ftell(f);
> > > + fseek(f, 0, SEEK_SET);
> > > + buf = av_malloc(size + 1);
> > > + if (!buf) {
> > > + fclose(f);
> > > + return AVERROR(ENOMEM);
> > > + }
> > > + fread(buf, 1, size, f);
> > > + buf[size++] = 0;
> > > + fclose(f);
> > > +
> > > + /* prescan file to get the number of lines and the maximum width */
> > > + w = 0;
> > > + for (i = 0; i < size; i++) {
> > > + if (buf[i] == '\n') {
> > > + (*rows)++;
> > > + *cols = FFMAX(*cols, w); w = 0;
> > > + } else
> > > + w++;
> > > + }
> >
> > rows & cols can overflow for large files
> >
> >
> > > + av_log(log_ctx, AV_LOG_DEBUG, "rows:%d cols:%d\n", *rows, *cols);
> > > +
> > > + if (!(*values = av_mallocz(sizeof(int) * *rows * *cols)))
> > > + return AVERROR(ENOMEM);
> >
> > memleak and integer overflow
> >
> > and anyway, it should be possible to specify things on the command line and
> > not require a file.
> > and please explain what this filter does and why it accesses files
> > like this
>
> That function get a shape from a file, this is more easily specified
> writing the shape right into a file, e.g. by writing:
>
> *
> ***
> *****
> ***
> *
does it make sense for this to be a second input to the filter and have a
filter that reads from files ?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In a rich man's house there is no place to spit but his face.
-- Diogenes of Sinope
-------------- 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/20100913/0099fac1/attachment.pgp>
More information about the ffmpeg-devel
mailing list