History

Merge commit 'ee0e8d4b15a87932ab6066cd6eae3cab08726319'

* commit 'ee0e8d4b15a87932ab6066cd6eae3cab08726319': vf_libopencv: switch to an AVOptions-based system.

Michael Niedermayer committed 13 years ago

Commit 94ec7092 parents f780a90 ee0e8d43 files · +45 −23Browse files

Unified · Split

3 files
  1. doc/filters.texi +14 −8
  2. libavfilter/avfilter.c +5 −2
  3. libavfilter/vf_libopencv.c +26 −13
doc/filters.texi+14−8
@@ -4169,12 +4169,18 @@ Apply video transform using libopencv. · 4168 unmodified lines
41694169 To enable this filter install libopencv library and headers and
41704170 configure FFmpeg with @code{--enable-libopencv}.
41714171
4172−The filter takes the parameters: @var{filter_name}@{:=@}@var{filter_params}.
4172+This filter accepts the following parameters:
4173+
4174+@table @option
41734175
4174−@var{filter_name} is the name of the libopencv filter to apply.
4176+@item filter_name
4177+The name of the libopencv filter to apply.
41754178
4176−@var{filter_params} specifies the parameters to pass to the libopencv
4177−filter. If not specified the default values are assumed.
4179+@item filter_params
4180+The parameters to pass to the libopencv filter. If not specified the default
4181+values are assumed.
4182+
4183+@end table
41784184
41794185 Refer to the official libopencv documentation for more precise
41804186 information:
@@ -4188,7 +4194,7 @@ Follows the list of supported libopencv filters. · 7 unmodified lines
41884194 Dilate an image by using a specific structuring element.
41894195 This filter corresponds to the libopencv function @code{cvDilate}.
41904196
4191−It accepts the parameters: @var{struct_el}:@var{nb_iterations}.
4197+It accepts the parameters: @var{struct_el}|@var{nb_iterations}.
41924198
41934199 @var{struct_el} represents a structuring element, and has the syntax:
41944200 @var{cols}x@var{rows}+@var{anchor_x}x@var{anchor_y}/@var{shape}
@@ -4216,7 +4222,7 @@ Follow some example: · 21 unmodified lines
42164222 ocv=dilate
42174223
42184224 # dilate using a structuring element with a 5x5 cross, iterate two times
4219−ocv=dilate=5x5+2x2/cross:2
4225+ocv=filter_name=dilate:filter_params=5x5+2x2/cross|2
42204226
42214227 # read the shape from the file diamond.shape, iterate two times
42224228 # the file diamond.shape may contain a pattern of characters like this:
@@ -4226,7 +4232,7 @@ ocv=dilate=5x5+2x2/cross:2 · 3 unmodified lines
42264232 # ***
42274233 # *
42284234 # the specified cols and rows are ignored (but not the anchor point coordinates)
4229−ocv=0x0+2x2/custom=diamond.shape:2
4235+ocv=dilate:0x0+2x2/custom=diamond.shape|2
42304236 @end example
42314237
42324238 @subsection erode
@@ -4242,7 +4248,7 @@ with the same syntax and semantics as the @ref{dilate} filter. · 9 unmodified lines
42424248 Smooth the input video.
42434249
42444250 The filter takes the following parameters:
4245−@var{type}:@var{param1}:@var{param2}:@var{param3}:@var{param4}.
4251+@var{type}|@var{param1}|@var{param2}|@var{param3}|@var{param4}.
42464252
42474253 @var{type} is the type of smooth filter to apply, and can be one of
42484254 the following values: "blur", "blur_no_scale", "median", "gaussian",
libavfilter/avfilter.c+5−2
@@ -671,6 +671,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 670 unmodified lines
671671 !strcmp(filter->filter->name, "frei0r_src") ||
672672 !strcmp(filter->filter->name, "gradfun" ) ||
673673 !strcmp(filter->filter->name, "hqdn3d" ) ||
674+ !strcmp(filter->filter->name, "ocv" ) ||
674675 !strcmp(filter->filter->name, "format") ||
675676 !strcmp(filter->filter->name, "noformat") ||
676677 !strcmp(filter->filter->name, "resample") ||
@@ -730,7 +731,8 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 53 unmodified lines
730731 } else if (!strcmp(filter->filter->name, "format") ||
731732 !strcmp(filter->filter->name, "noformat") ||
732733 !strcmp(filter->filter->name, "frei0r") ||
733− !strcmp(filter->filter->name, "frei0r_src")) {
734+ !strcmp(filter->filter->name, "frei0r_src") ||
735+ !strcmp(filter->filter->name, "ocv")) {
734736 /* a hack for compatibility with the old syntax
735737 * replace colons with |s */
736738 char *copy = av_strdup(args);
@@ -742,7 +744,8 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 5 unmodified lines
742744 goto fail;
743745 }
744746
745− if (!strcmp(filter->filter->name, "frei0r"))
747+ if (!strcmp(filter->filter->name, "frei0r") ||
748+ !strcmp(filter->filter->name, "ocv"))
746749 nb_leading = 1;
747750 else if (!strcmp(filter->filter->name, "frei0r_src"))
748751 nb_leading = 3;
libavfilter/vf_libopencv.c+26−13
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/avstring.h"
3131 #include "libavutil/common.h"
3232 #include "libavutil/file.h"
33+#include "libavutil/opt.h"
3334 #include "avfilter.h"
3435 #include "formats.h"
3536 #include "internal.h"
@@ -70,7 +71,9 @@ static int query_formats(AVFilterContext *ctx) · 34 unmodified lines
7071 }
7172
7273 typedef struct {
73− const char *name;
74+ const AVClass *class;
75+ char *name;
76+ char *params;
7477 int (*init)(AVFilterContext *ctx, const char *args);
7578 void (*uninit)(AVFilterContext *ctx);
7679 void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg);
@@ -95,7 +98,7 @@ static av_cold int smooth_init(AVFilterContext *ctx, const char *args) · 18 unmodified lines
9598 smooth->param4 = 0.0;
9699
97100 if (args)
98− sscanf(args, "%127[^:]:%d:%d:%lf:%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4);
101+ sscanf(args, "%127[^|]|%d|%d|%lf|%lf", type_str, &smooth->param1, &smooth->param2, &smooth->param3, &smooth->param4);
99102
100103 if (!strcmp(type_str, "blur" )) smooth->type = CV_BLUR;
101104 else if (!strcmp(type_str, "blur_no_scale")) smooth->type = CV_BLUR_NO_SCALE;
@@ -261,14 +264,14 @@ static av_cold int dilate_init(AVFilterContext *ctx, const char *args) · 159 unmodified lines
261264 dilate->nb_iterations = 1;
262265
263266 if (args)
264− kernel_str = av_get_token(&buf, ":");
267+ kernel_str = av_get_token(&buf, "|");
265268 if ((ret = parse_iplconvkernel(&dilate->kernel,
266269 *kernel_str ? kernel_str : default_kernel_str,
267270 ctx)) < 0)
268271 return ret;
269272 av_free(kernel_str);
270273
271− sscanf(buf, ":%d", &dilate->nb_iterations);
274+ sscanf(buf, "|%d", &dilate->nb_iterations);
272275 av_log(ctx, AV_LOG_VERBOSE, "iterations_nb:%d\n", dilate->nb_iterations);
273276 if (dilate->nb_iterations <= 0) {
274277 av_log(ctx, AV_LOG_ERROR, "Invalid non-positive value '%d' for nb_iterations\n",
@@ -317,27 +320,22 @@ static OCVFilterEntry ocv_filter_entries[] = { · 42 unmodified lines
317320 static av_cold int init(AVFilterContext *ctx, const char *args)
318321 {
319322 OCVContext *ocv = ctx->priv;
320− char name[128], priv_args[1024];
321323 int i;
322− char c;
323−
324− sscanf(args, "%127[^=:]%c%1023s", name, &c, priv_args);
325324
326325 for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) {
327326 OCVFilterEntry *entry = &ocv_filter_entries[i];
328− if (!strcmp(name, entry->name)) {
329− ocv->name = entry->name;
327+ if (!strcmp(ocv->name, entry->name)) {
330328 ocv->init = entry->init;
331329 ocv->uninit = entry->uninit;
332330 ocv->end_frame_filter = entry->end_frame_filter;
333331
334332 if (!(ocv->priv = av_mallocz(entry->priv_size)))
335333 return AVERROR(ENOMEM);
336− return ocv->init(ctx, priv_args);
334+ return ocv->init(ctx, ocv->params);
337335 }
338336 }
339337
340− av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", name);
338+ av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", ocv->name);
341339 return AVERROR(EINVAL);
342340 }
343341
@@ -348,7 +346,6 @@ static av_cold void uninit(AVFilterContext *ctx) · 4 unmodified lines
348346 if (ocv->uninit)
349347 ocv->uninit(ctx);
350348 av_free(ocv->priv);
351− memset(ocv, 0, sizeof(*ocv));
352349 }
353350
354351 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
@@ -376,6 +373,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 21 unmodified lines
376373 return ff_filter_frame(outlink, out);
377374 }
378375
376+#define OFFSET(x) offsetof(OCVContext, x)
377+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
378+static const AVOption options[] = {
379+ { "filter_name", NULL, OFFSET(name), AV_OPT_TYPE_STRING, .flags = FLAGS },
380+ { "filter_params", NULL, OFFSET(params), AV_OPT_TYPE_STRING, .flags = FLAGS },
381+ { NULL },
382+};
383+
384+static const AVClass ocv_class = {
385+ .class_name = "ocv",
386+ .item_name = av_default_item_name,
387+ .option = options,
388+ .version = LIBAVUTIL_VERSION_INT,
389+};
390+
379391 static const AVFilterPad avfilter_vf_ocv_inputs[] = {
380392 {
381393 .name = "default",
@@ -398,6 +410,7 @@ AVFilter avfilter_vf_ocv = { · 16 unmodified lines
398410 .description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."),
399411
400412 .priv_size = sizeof(OCVContext),
413+ .priv_class = &ocv_class,
401414
402415 .query_formats = query_formats,
403416 .init = init,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t