2 This is a Optical-Character-Recognition program
3 Copyright (C) 2000-2006 Joerg Schulenburg
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 see README for EMAIL address
25 #include "gocr.h" /* extern job_t JOB; */
27 /* function is only for debugging and for developing
28 it prints out a part of pixmap b at point x0,y0 to stderr
29 using dots .,; if no pixel, and @xoO for pixels
30 modify n_run and print out what would happen on 2nd, 3th loop!
31 new: output original and copied pixmap in the same figure
33 void out_b(struct box *px, pix *b, int x0, int y0, int dx, int dy, int cs ){
34 int x,y,x2,y2,yy0,tx,ty,n1,i;
37 if(px){ /* overwrite rest of arguments */
40 x0=px->x0; dx=px->x1-px->x0+1;
41 y0=px->y0; dy=px->y1-px->y0+1; yy0=y0;
43 if(cs==0) cs=JOB->cfg.cs;
44 fprintf(stderr,"\n# list box x= %4d %4d d= %3d %3d r= %3d %3d"
45 " nrun=%d p=%p", /* ToDo: r,nrun is obsolete */
46 px->x0, px->y0, px->x1 - px->x0 + 1, px->y1 - px->y0 + 1,
47 px->x - px->x0, px->y - px->y0, JOB->tmp.n_run, (void*)px);
48 fprintf(stderr,"\n# dots=%d boxes=%d subboxes=%d c=%s mod=%s"
49 " line=%d m= %d %d %d %d",
50 px->dots, px->num_boxes, px->num_subboxes,
51 decode(px->c,ASCII), decode(px->modifier,ASCII), px->line,
52 px->m1 - px->y0, px->m2 - px->y0, px->m3 - px->y0, px->m4 - px->y0);
55 fprintf(stderr,"\n# frames= %d (sumvects=%d)",px->num_frames,
56 ((px->num_frames)?px->num_frame_vectors[px->num_frames-1]:-1));
57 for (jo=j=i=0; i<px->num_frames; i++, jo=j) {
58 fprintf(stderr,"\n# frame %d (%+4d,%3d,%2d) ",
59 i, px->frame_vol[i], px->frame_per[i],
60 px->num_frame_vectors[i]-jo);
61 /* print only the first vectors of each frame */
62 for (;j<px->num_frame_vectors[i] && j<MaxFrameVectors; j++)
63 fprintf(stderr," #%02d %2d %2d", j,
64 px->frame_vector[j][0] - px->x0,
65 px->frame_vector[j][1] - px->y0);
68 if (px->num_ac){ /* output table of chars and its probabilities */
69 fprintf(stderr,"\n# list box char: ");
70 for(i=0;i<px->num_ac && i<NumAlt;i++)
71 /* output the (xml-)string (picture position, barcodes, glyphs, ...) */
73 fprintf(stderr," %s(%d)", px->tas[i] ,px->wac[i]);
75 fprintf(stderr," %s(%d)",decode(px->tac[i],ASCII),px->wac[i]);
78 if (px->dots && px->m2 && px->m1<y0) { yy0=px->m1; dy=px->y1-yy0+1; }
81 ty=dy/40+1; /* step, usually 1, but greater on large maps */
82 fprintf(stderr,"# list pattern x= %4d %4d d= %3d %3d t= %d %d\n",
85 for(y=yy0;y<yy0+dy;y+=ty) { /* reduce the output to max 78x40 */
86 /* first image is the copied and modified bitmap of the box */
88 for(x=x0;x<x0+dx;x+=tx){ /* by merging sub-pixels */
90 for(y2=y;y2<y+ty && y2<y0+dy;y2++) /* sub-pixels */
91 for(x2=x;x2<x+tx && x2<x0+dx;x2++)
93 if((getpixel(px->p,x2-x0+px->x0,
94 y2-y0+px->y0)<cs)) c1='@';
96 if (px->num_frames) { /* mark vectors */
98 if (c1!='$' && c1!='S') /* dont mark twice */
99 for (i=0;i<px->num_frame_vectors[px->num_frames-1];i++)
100 if ((px->frame_vector[i][0]-px->x0)/tx==(x-x0)/tx
101 && (px->frame_vector[i][1]-px->y0)/ty==(y-y0)/ty)
102 { c1=((c1=='@')?'$':'S'); break; }
104 fprintf(stderr,"%c", c1 );
107 /* 2nd image is the boxframe in the original bitmap */
108 if (dx<40) fprintf(stderr," ");
109 if (dx<40) /* do it only, if we have enough place */
110 for(x=x0;x<x0+dx;x+=tx){ /* by merging sub-pixels */
112 for(y2=y;y2<y+ty && y2<y0+dy;y2++) /* sub-pixels */
113 for(x2=x;x2<x+tx && x2<x0+dx;x2++)
114 { if((getpixel(b,x2,y2)<cs)) c1='@'; }
115 fprintf(stderr,"%c", c1 );
119 /* mark lines with < */
120 if (px) if (y-y0+px->y0==px->m1 || y-y0+px->y0==px->m2
121 || y-y0+px->y0==px->m3 || y-y0+px->y0==px->m4) c1='<';
122 if (y==y0 || y==yy0+dy-1) c2='-'; /* boxmarks */
124 fprintf(stderr,"%c%c\n",c1,c2);
128 /* same as out_b, but for faster use, only a box as argument
130 void out_x(struct box *px) {
131 out_b(px,NULL,0, 0, 0, 0, JOB->cfg.cs);
135 /* print out two boxes side by side, for debugging comparision algos */
136 void out_x2(struct box *box1, struct box *box2){
138 /*FIXME jb static*/static char *c1="OXXXXxx@.,,,,,,,";
140 dy=(box1->y1-box1->y0+1);
141 if(dy<box2->y1-box2->y0+1)dy=box2->y1-box2->y0+1;
142 tx=(box1->x1-box1->x0)/40+1;
143 ty=(box1->y1-box1->y0)/40+1; /* step, usually 1, but greater on large maps */
144 if(box2)fprintf(stderr,"\n# list 2 patterns");
145 for(i=0;i<dy;i+=ty) { /* reduce the output to max 78x40??? */
146 fprintf(stderr,"\n"); y=box1->y0+i;
147 for(x=box1->x0;x<=box1->x1;x+=tx)
148 fprintf(stderr,"%c", c1[ ((getpixel(b,x,y)<JOB->cfg.cs)?0:8)+marked(b,x,y) ] );
150 fprintf(stderr," "); y=box2->y0+i;
151 for(x=box2->x0;x<=box2->x1;x+=tx)
152 fprintf(stderr,"%c", c1[ ((getpixel(b,x,y)<JOB->cfg.cs)?0:8)+marked(b,x,y) ] );
157 /* ---- list output ---- for debugging ---
158 * list all boxes where the results can be found within the c-option
160 int output_list(job_t *job) {
163 pix *pp = &job->src.p;
164 char *lc = job->cfg.lc;
166 fprintf(stderr,"\n# list shape for charlist %s",lc);
167 for_each_data(&(JOB->res.boxlist)) {
168 box2 = (struct box *) list_get_current(&(JOB->res.boxlist));
169 for (j=0; j<box2->num_ac; j++)
170 if (!lc || (box2->tac[j] && strchr(lc, box2->tac[j]))
171 || (box2->tas[j] && strstr(lc, box2->tas[j]))) break;
173 fprintf(stderr,"\n# box found in charlist");
174 if (!lc || (strchr(lc, box2->c) && box2->c < 256 && box2->c)
175 || (strchr(lc, '_') && box2->c==UNKNOWN) /* for compability */
176 || j<box2->num_ac ){ /* also list alternative chars */
179 "\n# list shape %3d x=%4d %4d d= %3d %3d vf=%d ac=%d %04x %s",
180 i, box2->x0, box2->y0,
181 box2->x1 - box2->x0 + 1,
182 box2->y1 - box2->y0 + 1,
183 box2->num_frames, box2->num_ac,
184 (int)box2->c, /* wchar_t -> char ???? */
185 decode(box2->c,ASCII) );
186 if (JOB->cfg.verbose & 4) out_x(box2);
189 } end_for_each(&(JOB->res.boxlist));
190 fprintf(stderr,"\n");