[FFmpeg-devel] [PATCH] Add threshold libopencv wrapper.
Stefano Sabatini
stefano.sabatini-lala
Thu Dec 23 19:11:18 CET 2010
---
libavfilter/vf_libopencv.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/libavfilter/vf_libopencv.c b/libavfilter/vf_libopencv.c
index cbff7f3..b36deb8 100644
--- a/libavfilter/vf_libopencv.c
+++ b/libavfilter/vf_libopencv.c
@@ -361,6 +361,54 @@ static void laplace_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplI
}
typedef struct {
+ double value;
+ double max_value;
+ int type;
+} ThresholdContext;
+
+static av_cold int threshold_init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+ OCVContext *ocv = ctx->priv;
+ ThresholdContext *threshold = ocv->priv;
+ char type_str[128] = "binary";
+
+ if (args)
+ sscanf(args, "%lf:%lf:%127s", &threshold->value, &threshold->max_value, type_str);
+
+ if (!strcmp(type_str, "binary" )) threshold->type = CV_THRESH_BINARY;
+ else if (!strcmp(type_str, "binary_inv" )) threshold->type = CV_THRESH_BINARY_INV;
+ else if (!strcmp(type_str, "trunc" )) threshold->type = CV_THRESH_TRUNC;
+ else if (!strcmp(type_str, "to_zero" )) threshold->type = CV_THRESH_TOZERO;
+ else if (!strcmp(type_str, "to_zero_inv")) threshold->type = CV_THRESH_TOZERO_INV;
+ else {
+ av_log(ctx, AV_LOG_ERROR,
+ "Unknown threshold type '%s'\n", type_str);
+ return AVERROR(EINVAL);
+ }
+
+ av_log(ctx, AV_LOG_INFO, "threshold:%lf max_value:%lf type:%s\n",
+ threshold->value, threshold->max_value, type_str);
+ return 0;
+}
+
+static int threshold_query_formats(AVFilterContext *ctx)
+{
+ static const enum PixelFormat pix_fmts[] = {
+ PIX_FMT_GRAY16LE, PIX_FMT_GRAY16BE, PIX_FMT_GRAY8, PIX_FMT_NONE
+ };
+
+ avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
+ return 0;
+}
+
+static void threshold_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
+{
+ OCVContext *ocv = ctx->priv;
+ ThresholdContext *threshold = ocv->priv;
+ cvThreshold(inimg, outimg, threshold->value, threshold->max_value, threshold->type);
+}
+
+typedef struct {
const char *name;
size_t priv_size;
int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
@@ -374,6 +422,7 @@ static OCVFilterEntry ocv_filter_entries[] = {
{ "erode", sizeof(DilateContext), dilate_init, dilate_uninit, erode_end_frame_filter, query_formats_8bit },
{ "laplace", sizeof(LaplaceContext), laplace_init, NULL, laplace_end_frame_filter, query_formats_16bit_1ch },
{ "smooth", sizeof(SmoothContext), smooth_init, NULL, smooth_end_frame_filter, query_formats_8bit },
+ { "threshold", sizeof(ThresholdContext), threshold_init, NULL, threshold_end_frame_filter, threshold_query_formats },
};
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
--
1.7.2.3
More information about the ffmpeg-devel
mailing list