diff options
author | Paul B Mahol <onemda@gmail.com> | 2019-05-17 19:00:47 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2019-05-17 19:10:12 +0200 |
commit | 96c79d4e1fd87dbedfd70ed876ee257ddda2ba90 (patch) | |
tree | 9fd468bc96e2ee5d9f409b4fd4547092750dc758 | |
parent | 3f31726994f64801c12349471d1bf94569b8329d (diff) | |
download | ffmpeg-96c79d4e1fd87dbedfd70ed876ee257ddda2ba90.tar.gz |
avfilter/vf_ocr: also export confidence of result
-rw-r--r-- | doc/filters.texi | 1 | ||||
-rw-r--r-- | libavfilter/vf_ocr.c | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index 0d06278665..163ffef13f 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12910,6 +12910,7 @@ Set character blacklist. @end table The filter exports recognized text as the frame metadata @code{lavfi.ocr.text}. +The filter exports confidence of recognized words as the frame metadata @code{lavfi.ocr.confidence}. @section ocv diff --git a/libavfilter/vf_ocr.c b/libavfilter/vf_ocr.c index abfff49438..d5f76059b7 100644 --- a/libavfilter/vf_ocr.c +++ b/libavfilter/vf_ocr.c @@ -100,11 +100,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterLink *outlink = ctx->outputs[0]; OCRContext *s = ctx->priv; char *result; + int *confs; result = TessBaseAPIRect(s->tess, in->data[0], 1, in->linesize[0], 0, 0, in->width, in->height); + confs = TessBaseAPIAllWordConfidences(s->tess); av_dict_set(metadata, "lavfi.ocr.text", result, 0); + for (int i = 0; confs[i] != -1; i++) { + char number[256]; + + snprintf(number, sizeof(number), "%d ", confs[i]); + av_dict_set(metadata, "lavfi.ocr.confidence", number, AV_DICT_APPEND); + } + TessDeleteText(result); + TessDeleteIntArray(confs); return ff_filter_frame(outlink, in); } |