Commit 96c79d4e authored by Paul B Mahol's avatar Paul B Mahol

avfilter/vf_ocr: also export confidence of result

parent 3f317269
......@@ -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
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment