From a7c52a5cdad0b1a4c4e053992858674e8d7953a7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 3 Jun 2009 23:28:00 +0100 Subject: [PATCH] wip can invoke show-things.tcl --- pctb/Makefile | 2 +- pctb/convert.c | 2 +- pctb/ocr.c | 33 ++++++++++++++++++++++++++++----- pctb/ocr.h | 2 ++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pctb/Makefile b/pctb/Makefile index 2cb3fad..3707d81 100644 --- a/pctb/Makefile +++ b/pctb/Makefile @@ -1,6 +1,6 @@ LDLIBS += -lnetpbm CFLAGS += -Wall -Wwrite-strings -Wpointer-arith -Wmissing-prototypes \ - -Wstrict-prototypes -g + -Wstrict-prototypes -Werror -g all: convert diff --git a/pctb/convert.c b/pctb/convert.c index f3de359..c8082e6 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -9,7 +9,7 @@ typedef struct { static int height, width; static char *image; -static void debug_flush(void) { +void debug_flush(void) { eassert(!fflush(debug)); eassert(!ferror(debug)); } diff --git a/pctb/ocr.c b/pctb/ocr.c index a90ecea..87bf808 100644 --- a/pctb/ocr.c +++ b/pctb/ocr.c @@ -186,11 +186,18 @@ OcrResultGlyph *ocr(int w, int h, Pixcol cols[]) { nresults=0; assert(db); + fprintf(debug,"OCR h=%d w=%d",w,h); + for (x=0; x=w) break; + if (x>=w) + break; if (!cols[x]) { nspaces++; @@ -204,34 +211,50 @@ OcrResultGlyph *ocr(int w, int h, Pixcol cols[]) { int lx=x; int bestmatch_rx=-1; current= &ocr_contexts[ctx]; + fprintf(debug,"OCR lx=%d ctx=%d ",lx,ctx); + for (;;) { + debug_flush(); + fprintf(debug,"| x=%d",x); if (x>w) break; Pixcol cv= cols[x]; + fprintf(debug," cv=%"PSPIXCOL(PRIx),x); for (i=0; inlinks; i++) if (current->links[i].col == cv) goto found; /* not found */ + fprintf(debug," ?"); break; + found: current= current->links[i].then; - if (current->s[0]) { bestmatch=current; bestmatch_rx=x; } + if (current->s[0]) { + fprintf(debug," \"%s\"",current->s); + bestmatch=current; bestmatch_rx=x; + } else { + fprintf(debug," ..."); + } x++; } - if (!bestmatch) { + if (bestmatch) { + fprintf(debug," YES\n"); add_result(bestmatch->s, lx, bestmatch_rx, ctx); x= bestmatch_rx+1; ctx= 0; } else { - int rx; + fprintf(debug," UNKNOWN"); for (rx=lx+1; rx