X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_ocr.c;h=6de474025a20317402871b5e345b6b1ec1b5b2e0;hb=a04ad248a05e7b613abe09b3bb067f555108d794;hp=abfff494387b0a78b538d9a6582495b8d5954926;hpb=4069096dd535ee99175c2a29c1a1f59c3fc110c1;p=ffmpeg diff --git a/libavfilter/vf_ocr.c b/libavfilter/vf_ocr.c index abfff494387..6de474025a2 100644 --- a/libavfilter/vf_ocr.c +++ b/libavfilter/vf_ocr.c @@ -43,7 +43,7 @@ typedef struct OCRContext { static const AVOption ocr_options[] = { { "datapath", "set datapath", OFFSET(datapath), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, { "language", "set language", OFFSET(language), AV_OPT_TYPE_STRING, {.str="eng"}, 0, 0, FLAGS }, - { "whitelist", "set character whitelist", OFFSET(whitelist), AV_OPT_TYPE_STRING, {.str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:;,-+_!?\"'[]{}()<>|/\\=*&%$#@!~"}, 0, 0, FLAGS }, + { "whitelist", "set character whitelist", OFFSET(whitelist), AV_OPT_TYPE_STRING, {.str="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:;,-+_!?\"'[]{}()<>|/\\=*&%$#@!~ "}, 0, 0, FLAGS }, { "blacklist", "set character blacklist", OFFSET(blacklist), AV_OPT_TYPE_STRING, {.str=""}, 0, 0, FLAGS }, { NULL } }; @@ -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); } @@ -136,7 +146,7 @@ static const AVFilterPad ocr_outputs[] = { { NULL } }; -AVFilter ff_vf_ocr = { +const AVFilter ff_vf_ocr = { .name = "ocr", .description = NULL_IF_CONFIG_SMALL("Optical Character Recognition."), .priv_size = sizeof(OCRContext),