The same filter class will be used for managing all the libopencv
filtering functions.
Originally committed as revision 26079 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -1413,7 +1413,7 @@ cropdetect_filter_deps="gpl" |
1413 | 1413 |
frei0r_filter_deps="frei0r dlopen strtok_r" |
1414 | 1414 |
frei0r_src_filter_deps="frei0r dlopen strtok_r" |
1415 | 1415 |
hqdn3d_filter_deps="gpl" |
1416 |
-ocv_smooth_filter_deps="libopencv" |
|
1416 |
+ocv_filter_deps="libopencv" |
|
1417 | 1417 |
yadif_filter_deps="gpl" |
1418 | 1418 |
|
1419 | 1419 |
# libraries |
... | ... |
@@ -512,14 +512,31 @@ input to the vflip filter. |
512 | 512 |
|
513 | 513 |
Pass the video source unchanged to the output. |
514 | 514 |
|
515 |
-@section ocv_smooth |
|
515 |
+@section ocv |
|
516 | 516 |
|
517 |
-Apply smooth transform using libopencv. |
|
517 |
+Apply video transform using libopencv. |
|
518 | 518 |
|
519 | 519 |
To enable this filter install libopencv library and headers and |
520 | 520 |
configure FFmpeg with --enable-libopencv. |
521 | 521 |
|
522 |
-The filter accepts the following parameters: |
|
522 |
+The filter takes the parameters: @var{filter_name}@{:=@}@var{filter_params}. |
|
523 |
+ |
|
524 |
+@var{filter_name} is the name of the libopencv filter to apply. |
|
525 |
+ |
|
526 |
+@var{filter_params} specifies the parameters to pass to the libopencv |
|
527 |
+filter. If not specified the default values are assumed. |
|
528 |
+ |
|
529 |
+Refer to the official libopencv documentation for more precise |
|
530 |
+informations: |
|
531 |
+@url{http://opencv.willowgarage.com/documentation/c/image_filtering.html} |
|
532 |
+ |
|
533 |
+Follows the list of supported libopencv filters. |
|
534 |
+ |
|
535 |
+@subsection smooth |
|
536 |
+ |
|
537 |
+Smooth the input video. |
|
538 |
+ |
|
539 |
+The filter takes the following parameters: |
|
523 | 540 |
@var{type}:@var{param1}:@var{param2}:@var{param3}:@var{param4}. |
524 | 541 |
|
525 | 542 |
@var{type} is the type of smooth filter to apply, and can be one of |
... | ... |
@@ -535,9 +552,7 @@ The default value for @var{param1} is 3, the default value for the |
535 | 535 |
other parameters is 0. |
536 | 536 |
|
537 | 537 |
These parameters correspond to the parameters assigned to the |
538 |
-libopencv function @code{cvSmooth}. Refer to the official libopencv |
|
539 |
-documentation for the exact meaning of the parameters: |
|
540 |
-@url{http://opencv.willowgarage.com/documentation/c/image_filtering.html} |
|
538 |
+libopencv function @code{cvSmooth}. |
|
541 | 539 |
|
542 | 540 |
@section overlay |
543 | 541 |
|
... | ... |
@@ -31,7 +31,7 @@ OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o |
31 | 31 |
OBJS-$(CONFIG_HQDN3D_FILTER) += vf_hqdn3d.o |
32 | 32 |
OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o |
33 | 33 |
OBJS-$(CONFIG_NULL_FILTER) += vf_null.o |
34 |
-OBJS-$(CONFIG_OCV_SMOOTH_FILTER) += vf_libopencv.o |
|
34 |
+OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o |
|
35 | 35 |
OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o |
36 | 36 |
OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o |
37 | 37 |
OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o |
... | ... |
@@ -52,7 +52,7 @@ void avfilter_register_all(void) |
52 | 52 |
REGISTER_FILTER (HQDN3D, hqdn3d, vf); |
53 | 53 |
REGISTER_FILTER (NOFORMAT, noformat, vf); |
54 | 54 |
REGISTER_FILTER (NULL, null, vf); |
55 |
- REGISTER_FILTER (OCV_SMOOTH, ocv_smooth, vf); |
|
55 |
+ REGISTER_FILTER (OCV, ocv, vf); |
|
56 | 56 |
REGISTER_FILTER (OVERLAY, overlay, vf); |
57 | 57 |
REGISTER_FILTER (PAD, pad, vf); |
58 | 58 |
REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf); |
... | ... |
@@ -27,7 +27,7 @@ |
27 | 27 |
#include "libavcore/samplefmt.h" |
28 | 28 |
|
29 | 29 |
#define LIBAVFILTER_VERSION_MAJOR 1 |
30 |
-#define LIBAVFILTER_VERSION_MINOR 69 |
|
30 |
+#define LIBAVFILTER_VERSION_MINOR 70 |
|
31 | 31 |
#define LIBAVFILTER_VERSION_MICRO 0 |
32 | 32 |
|
33 | 33 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
... | ... |
@@ -63,7 +63,13 @@ static int query_formats(AVFilterContext *ctx) |
63 | 63 |
|
64 | 64 |
static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } |
65 | 65 |
|
66 |
-#if CONFIG_OCV_SMOOTH_FILTER |
|
66 |
+typedef struct { |
|
67 |
+ const char *name; |
|
68 |
+ int (*init)(AVFilterContext *ctx, const char *args, void *opaque); |
|
69 |
+ void (*uninit)(AVFilterContext *ctx); |
|
70 |
+ void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg); |
|
71 |
+ void *priv; |
|
72 |
+} OCVContext; |
|
67 | 73 |
|
68 | 74 |
typedef struct { |
69 | 75 |
int type; |
... | ... |
@@ -73,7 +79,8 @@ typedef struct { |
73 | 73 |
|
74 | 74 |
static av_cold int smooth_init(AVFilterContext *ctx, const char *args, void *opaque) |
75 | 75 |
{ |
76 |
- SmoothContext *smooth = ctx->priv; |
|
76 |
+ OCVContext *ocv = ctx->priv; |
|
77 |
+ SmoothContext *smooth = ocv->priv; |
|
77 | 78 |
char type_str[128] = "gaussian"; |
78 | 79 |
|
79 | 80 |
smooth->param1 = 3; |
... | ... |
@@ -113,17 +120,74 @@ static av_cold int smooth_init(AVFilterContext *ctx, const char *args, void *opa |
113 | 113 |
return 0; |
114 | 114 |
} |
115 | 115 |
|
116 |
-static void smooth_end_frame(AVFilterLink *inlink) |
|
116 |
+static void smooth_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg) |
|
117 | 117 |
{ |
118 |
- SmoothContext *smooth = inlink->dst->priv; |
|
119 |
- AVFilterLink *outlink = inlink->dst->outputs[0]; |
|
118 |
+ OCVContext *ocv = ctx->priv; |
|
119 |
+ SmoothContext *smooth = ocv->priv; |
|
120 |
+ cvSmooth(inimg, outimg, smooth->type, smooth->param1, smooth->param2, smooth->param3, smooth->param4); |
|
121 |
+} |
|
122 |
+ |
|
123 |
+typedef struct { |
|
124 |
+ const char *name; |
|
125 |
+ size_t priv_size; |
|
126 |
+ int (*init)(AVFilterContext *ctx, const char *args, void *opaque); |
|
127 |
+ void (*uninit)(AVFilterContext *ctx); |
|
128 |
+ void (*end_frame_filter)(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg); |
|
129 |
+} OCVFilterEntry; |
|
130 |
+ |
|
131 |
+static OCVFilterEntry ocv_filter_entries[] = { |
|
132 |
+ { "smooth", sizeof(SmoothContext), smooth_init, NULL, smooth_end_frame_filter }, |
|
133 |
+}; |
|
134 |
+ |
|
135 |
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
|
136 |
+{ |
|
137 |
+ OCVContext *ocv = ctx->priv; |
|
138 |
+ char name[128], priv_args[1024]; |
|
139 |
+ int i; |
|
140 |
+ char c; |
|
141 |
+ |
|
142 |
+ sscanf(args, "%127[^=:]%c%1023s", name, &c, priv_args); |
|
143 |
+ |
|
144 |
+ for (i = 0; i < FF_ARRAY_ELEMS(ocv_filter_entries); i++) { |
|
145 |
+ OCVFilterEntry *entry = &ocv_filter_entries[i]; |
|
146 |
+ if (!strcmp(name, entry->name)) { |
|
147 |
+ ocv->name = entry->name; |
|
148 |
+ ocv->init = entry->init; |
|
149 |
+ ocv->uninit = entry->uninit; |
|
150 |
+ ocv->end_frame_filter = entry->end_frame_filter; |
|
151 |
+ |
|
152 |
+ if (!(ocv->priv = av_mallocz(entry->priv_size))) |
|
153 |
+ return AVERROR(ENOMEM); |
|
154 |
+ return ocv->init(ctx, priv_args, opaque); |
|
155 |
+ } |
|
156 |
+ } |
|
157 |
+ |
|
158 |
+ av_log(ctx, AV_LOG_ERROR, "No libopencv filter named '%s'\n", name); |
|
159 |
+ return AVERROR(EINVAL); |
|
160 |
+} |
|
161 |
+ |
|
162 |
+static av_cold void uninit(AVFilterContext *ctx) |
|
163 |
+{ |
|
164 |
+ OCVContext *ocv = ctx->priv; |
|
165 |
+ |
|
166 |
+ if (ocv->uninit) |
|
167 |
+ ocv->uninit(ctx); |
|
168 |
+ av_free(ocv->priv); |
|
169 |
+ memset(ocv, 0, sizeof(*ocv)); |
|
170 |
+} |
|
171 |
+ |
|
172 |
+static void end_frame(AVFilterLink *inlink) |
|
173 |
+{ |
|
174 |
+ AVFilterContext *ctx = inlink->dst; |
|
175 |
+ OCVContext *ocv = ctx->priv; |
|
176 |
+ AVFilterLink *outlink= inlink->dst->outputs[0]; |
|
120 | 177 |
AVFilterBufferRef *inpicref = inlink ->cur_buf; |
121 | 178 |
AVFilterBufferRef *outpicref = outlink->out_buf; |
122 | 179 |
IplImage inimg, outimg; |
123 | 180 |
|
124 | 181 |
fill_iplimage_from_picref(&inimg , inpicref , inlink->format); |
125 | 182 |
fill_iplimage_from_picref(&outimg, outpicref, inlink->format); |
126 |
- cvSmooth(&inimg, &outimg, smooth->type, smooth->param1, smooth->param2, smooth->param3, smooth->param4); |
|
183 |
+ ocv->end_frame_filter(ctx, &inimg, &outimg); |
|
127 | 184 |
fill_picref_from_iplimage(outpicref, &outimg, inlink->format); |
128 | 185 |
|
129 | 186 |
avfilter_unref_buffer(inpicref); |
... | ... |
@@ -132,19 +196,20 @@ static void smooth_end_frame(AVFilterLink *inlink) |
132 | 132 |
avfilter_unref_buffer(outpicref); |
133 | 133 |
} |
134 | 134 |
|
135 |
-AVFilter avfilter_vf_ocv_smooth = { |
|
136 |
- .name = "ocv_smooth", |
|
137 |
- .description = NULL_IF_CONFIG_SMALL("Apply smooth transform using libopencv."), |
|
135 |
+AVFilter avfilter_vf_ocv = { |
|
136 |
+ .name = "ocv", |
|
137 |
+ .description = NULL_IF_CONFIG_SMALL("Apply transform using libopencv."), |
|
138 | 138 |
|
139 |
- .priv_size = sizeof(SmoothContext), |
|
139 |
+ .priv_size = sizeof(OCVContext), |
|
140 | 140 |
|
141 | 141 |
.query_formats = query_formats, |
142 |
- .init = smooth_init, |
|
142 |
+ .init = init, |
|
143 |
+ .uninit = uninit, |
|
143 | 144 |
|
144 | 145 |
.inputs = (AVFilterPad[]) {{ .name = "default", |
145 | 146 |
.type = AVMEDIA_TYPE_VIDEO, |
146 | 147 |
.draw_slice = null_draw_slice, |
147 |
- .end_frame = smooth_end_frame, |
|
148 |
+ .end_frame = end_frame, |
|
148 | 149 |
.min_perms = AV_PERM_READ }, |
149 | 150 |
{ .name = NULL}}, |
150 | 151 |
|
... | ... |
@@ -152,5 +217,3 @@ AVFilter avfilter_vf_ocv_smooth = { |
152 | 152 |
.type = AVMEDIA_TYPE_VIDEO, }, |
153 | 153 |
{ .name = NULL}}, |
154 | 154 |
}; |
155 |
- |
|
156 |
-#endif /* CONFIG_OCV_SMOOTH_FILTER */ |