Unified · Split
| @@ -12910,6 +12910,7 @@ Set character blacklist. · 12909 unmodified lines | ||
| 12910 | 12910 | @end table |
| 12911 | 12911 | |
| 12912 | 12912 | The filter exports recognized text as the frame metadata @code{lavfi.ocr.text}. |
| 12913 | +The filter exports confidence of recognized words as the frame metadata @code{lavfi.ocr.confidence}. | |
| 12913 | 12914 | |
| 12914 | 12915 | @section ocv |
| 12915 | 12916 | |
| @@ -100,11 +100,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 99 unmodified lines | ||
| 100 | 100 | AVFilterLink *outlink = ctx->outputs[0]; |
| 101 | 101 | OCRContext *s = ctx->priv; |
| 102 | 102 | char *result; |
| 103 | + int *confs; | |
| 103 | 104 | |
| 104 | 105 | result = TessBaseAPIRect(s->tess, in->data[0], 1, |
| 105 | 106 | in->linesize[0], 0, 0, in->width, in->height); |
| 107 | + confs = TessBaseAPIAllWordConfidences(s->tess); | |
| 106 | 108 | av_dict_set(metadata, "lavfi.ocr.text", result, 0); |
| 109 | + for (int i = 0; confs[i] != -1; i++) { | |
| 110 | + char number[256]; | |
| 111 | + | |
| 112 | + snprintf(number, sizeof(number), "%d ", confs[i]); | |
| 113 | + av_dict_set(metadata, "lavfi.ocr.confidence", number, AV_DICT_APPEND); | |
| 114 | + } | |
| 115 | + | |
| 107 | 116 | TessDeleteText(result); |
| 117 | + TessDeleteIntArray(confs); | |
| 108 | 118 | |
| 109 | 119 | return ff_filter_frame(outlink, in); |
| 110 | 120 | } |