chiark / gitweb /
wip can invoke show-things.tcl
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 3 Jun 2009 22:28:00 +0000 (23:28 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 3 Jun 2009 22:28:00 +0000 (23:28 +0100)
pctb/Makefile
pctb/convert.c
pctb/ocr.c
pctb/ocr.h

index 2cb3fad60670aef5745b334841fcf1ddd76ee3ff..3707d81f1f5cd054ffbfa73ccf5363ef1a4fbb4d 100644 (file)
@@ -1,6 +1,6 @@
 LDLIBS += -lnetpbm
 CFLAGS += -Wall -Wwrite-strings -Wpointer-arith -Wmissing-prototypes \
-       -Wstrict-prototypes -g
+       -Wstrict-prototypes -Werror -g
 
 all: convert
 
index f3de35936c14df5f40325ed8bee8508d32e7c8ec..c8082e697cea3ff4f70b26c1e1d24c9e72e2eafc 100644 (file)
@@ -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));
 }
index a90ecea64e590641911a3faa5e250373ce16863c..87bf80842a510280e30826d8fe36c877911b59e8 100644 (file)
@@ -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; x++) fprintf(debug," %"PSPIXCOL(PRIx),cols[x]);
+  fprintf(debug,"\n");
+  debug_flush();
+
  restart:
   x=0;
   for (;;) {
+    debug_flush();
     /* skip spaces */
-    if (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; i<current->nlinks; 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<w && cols[rx]; rx++);
-      printf("UNKNOWN x=%d ctx=%d %d..%d\n",x, ctx, lx,rx);
+      fprintf(debug," x=%d ctx=%d %d..%d\n",x, ctx, lx,rx);
+      debug_flush();
       callout_unknown(w,h,cols, lx,rx, results,nresults);
       goto restart;
     }
   }
   add_result(0,-1,-1,0);
+  fprintf(debug,"OCR  finished %d glyphs\n",nresults);
+  debug_flush();
   return results;
 }
 
index 0824404579f753ca9ba65dd4d224258f188fdb5f..26bccbc7b83b81bb693b27995063ed7cedbecc1d 100644 (file)
@@ -26,6 +26,8 @@ OcrResultGlyph *ocr(int w, int h, Pixcol cols[]);
 
 void ocr_init(void);
 
+void debug_flush(void);
+
 #define eassert assert
 #define debug stdout