isbn 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/{README → README.md} +5 -11
- data/Rakefile +20 -14
- data/isbn.gemspec +23 -0
- data/lib/isbn.rb +2 -0
- data/test/isbn_spec.rb +1 -1
- metadata +29 -316
- data/VERSION +0 -1
- data/src/gocr-0.48/.cvsignore +0 -6
- data/src/gocr-0.48/AUTHORS +0 -7
- data/src/gocr-0.48/BUGS +0 -55
- data/src/gocr-0.48/CREDITS +0 -17
- data/src/gocr-0.48/HISTORY +0 -243
- data/src/gocr-0.48/INSTALL +0 -83
- data/src/gocr-0.48/Makefile +0 -193
- data/src/gocr-0.48/Makefile.in +0 -193
- data/src/gocr-0.48/README +0 -165
- data/src/gocr-0.48/READMEde.txt +0 -80
- data/src/gocr-0.48/REMARK.txt +0 -18
- data/src/gocr-0.48/REVIEW +0 -538
- data/src/gocr-0.48/TODO +0 -65
- data/src/gocr-0.48/bin/.cvsignore +0 -2
- data/src/gocr-0.48/bin/create_db +0 -38
- data/src/gocr-0.48/bin/gocr.tcl +0 -527
- data/src/gocr-0.48/bin/gocr_chk.sh +0 -44
- data/src/gocr-0.48/configure +0 -4689
- data/src/gocr-0.48/configure.in +0 -71
- data/src/gocr-0.48/doc/.#Makefile.1.6 +0 -39
- data/src/gocr-0.48/doc/.cvsignore +0 -2
- data/src/gocr-0.48/doc/Makefile +0 -39
- data/src/gocr-0.48/doc/Makefile.in +0 -39
- data/src/gocr-0.48/doc/example.dtd +0 -53
- data/src/gocr-0.48/doc/example.xml +0 -21
- data/src/gocr-0.48/doc/examples.txt +0 -67
- data/src/gocr-0.48/doc/gocr.html +0 -578
- data/src/gocr-0.48/doc/unicode.txt +0 -57
- data/src/gocr-0.48/examples/.#Makefile.1.22 +0 -166
- data/src/gocr-0.48/examples/4x6.png +0 -0
- data/src/gocr-0.48/examples/4x6.txt +0 -2
- data/src/gocr-0.48/examples/5x7.png +0 -0
- data/src/gocr-0.48/examples/5x7.png.txt +0 -2
- data/src/gocr-0.48/examples/5x8.png +0 -0
- data/src/gocr-0.48/examples/5x8.png.txt +0 -2
- data/src/gocr-0.48/examples/Makefile +0 -166
- data/src/gocr-0.48/examples/color.fig +0 -20
- data/src/gocr-0.48/examples/ex.fig +0 -16
- data/src/gocr-0.48/examples/font.tex +0 -22
- data/src/gocr-0.48/examples/font1.tex +0 -46
- data/src/gocr-0.48/examples/font2.fig +0 -27
- data/src/gocr-0.48/examples/font_nw.tex +0 -24
- data/src/gocr-0.48/examples/handwrt1.jpg +0 -0
- data/src/gocr-0.48/examples/handwrt1.txt +0 -10
- data/src/gocr-0.48/examples/inverse.fig +0 -20
- data/src/gocr-0.48/examples/matrix.jpg +0 -0
- data/src/gocr-0.48/examples/ocr-a-subset.png +0 -0
- data/src/gocr-0.48/examples/ocr-a-subset.png.txt +0 -4
- data/src/gocr-0.48/examples/ocr-a.png +0 -0
- data/src/gocr-0.48/examples/ocr-a.txt +0 -6
- data/src/gocr-0.48/examples/ocr-b.png +0 -0
- data/src/gocr-0.48/examples/ocr-b.png.txt +0 -4
- data/src/gocr-0.48/examples/polish.tex +0 -28
- data/src/gocr-0.48/examples/rotate45.fig +0 -14
- data/src/gocr-0.48/examples/score +0 -36
- data/src/gocr-0.48/examples/text.tex +0 -28
- data/src/gocr-0.48/gpl.html +0 -537
- data/src/gocr-0.48/include/.cvsignore +0 -2
- data/src/gocr-0.48/include/config.h +0 -36
- data/src/gocr-0.48/include/config.h.in +0 -36
- data/src/gocr-0.48/include/version.h +0 -2
- data/src/gocr-0.48/install-sh +0 -3
- data/src/gocr-0.48/make.bat +0 -57
- data/src/gocr-0.48/man/.cvsignore +0 -2
- data/src/gocr-0.48/man/Makefile +0 -29
- data/src/gocr-0.48/man/Makefile.in +0 -29
- data/src/gocr-0.48/man/man1/gocr.1 +0 -166
- data/src/gocr-0.48/src/.cvsignore +0 -4
- data/src/gocr-0.48/src/Makefile +0 -132
- data/src/gocr-0.48/src/Makefile.in +0 -132
- data/src/gocr-0.48/src/amiga.h +0 -31
- data/src/gocr-0.48/src/barcode.c +0 -846
- data/src/gocr-0.48/src/barcode.c.orig +0 -593
- data/src/gocr-0.48/src/barcode.h +0 -11
- data/src/gocr-0.48/src/box.c +0 -372
- data/src/gocr-0.48/src/database.c +0 -462
- data/src/gocr-0.48/src/detect.c +0 -943
- data/src/gocr-0.48/src/gocr.c +0 -373
- data/src/gocr-0.48/src/gocr.h +0 -288
- data/src/gocr-0.48/src/jconv.c +0 -168
- data/src/gocr-0.48/src/job.c +0 -84
- data/src/gocr-0.48/src/lines.c +0 -350
- data/src/gocr-0.48/src/list.c +0 -334
- data/src/gocr-0.48/src/list.h +0 -90
- data/src/gocr-0.48/src/ocr0.c +0 -6756
- data/src/gocr-0.48/src/ocr0.h +0 -63
- data/src/gocr-0.48/src/ocr0n.c +0 -1475
- data/src/gocr-0.48/src/ocr1.c +0 -85
- data/src/gocr-0.48/src/ocr1.h +0 -3
- data/src/gocr-0.48/src/otsu.c +0 -289
- data/src/gocr-0.48/src/otsu.h +0 -23
- data/src/gocr-0.48/src/output.c +0 -289
- data/src/gocr-0.48/src/output.h +0 -37
- data/src/gocr-0.48/src/pcx.c +0 -153
- data/src/gocr-0.48/src/pcx.h +0 -9
- data/src/gocr-0.48/src/pgm2asc.c +0 -2893
- data/src/gocr-0.48/src/pgm2asc.h +0 -105
- data/src/gocr-0.48/src/pixel.c +0 -537
- data/src/gocr-0.48/src/pnm.c +0 -533
- data/src/gocr-0.48/src/pnm.h +0 -35
- data/src/gocr-0.48/src/progress.c +0 -87
- data/src/gocr-0.48/src/progress.h +0 -42
- data/src/gocr-0.48/src/remove.c +0 -703
- data/src/gocr-0.48/src/tga.c +0 -87
- data/src/gocr-0.48/src/tga.h +0 -6
- data/src/gocr-0.48/src/unicode.c +0 -1314
- data/src/gocr-0.48/src/unicode.h +0 -1257
- data/src/jpeg-7/Makefile.am +0 -133
- data/src/jpeg-7/Makefile.in +0 -1089
- data/src/jpeg-7/README +0 -322
- data/src/jpeg-7/aclocal.m4 +0 -8990
- data/src/jpeg-7/ansi2knr.1 +0 -36
- data/src/jpeg-7/ansi2knr.c +0 -739
- data/src/jpeg-7/cderror.h +0 -132
- data/src/jpeg-7/cdjpeg.c +0 -181
- data/src/jpeg-7/cdjpeg.h +0 -187
- data/src/jpeg-7/change.log +0 -270
- data/src/jpeg-7/cjpeg.1 +0 -325
- data/src/jpeg-7/cjpeg.c +0 -616
- data/src/jpeg-7/ckconfig.c +0 -402
- data/src/jpeg-7/coderules.txt +0 -118
- data/src/jpeg-7/config.guess +0 -1561
- data/src/jpeg-7/config.sub +0 -1686
- data/src/jpeg-7/configure +0 -17139
- data/src/jpeg-7/configure.ac +0 -317
- data/src/jpeg-7/depcomp +0 -630
- data/src/jpeg-7/djpeg.1 +0 -251
- data/src/jpeg-7/djpeg.c +0 -617
- data/src/jpeg-7/example.c +0 -433
- data/src/jpeg-7/filelist.txt +0 -215
- data/src/jpeg-7/install-sh +0 -520
- data/src/jpeg-7/install.txt +0 -1097
- data/src/jpeg-7/jaricom.c +0 -148
- data/src/jpeg-7/jcapimin.c +0 -282
- data/src/jpeg-7/jcapistd.c +0 -161
- data/src/jpeg-7/jcarith.c +0 -921
- data/src/jpeg-7/jccoefct.c +0 -453
- data/src/jpeg-7/jccolor.c +0 -459
- data/src/jpeg-7/jcdctmgr.c +0 -482
- data/src/jpeg-7/jchuff.c +0 -1612
- data/src/jpeg-7/jcinit.c +0 -65
- data/src/jpeg-7/jcmainct.c +0 -293
- data/src/jpeg-7/jcmarker.c +0 -667
- data/src/jpeg-7/jcmaster.c +0 -770
- data/src/jpeg-7/jcomapi.c +0 -106
- data/src/jpeg-7/jconfig.bcc +0 -48
- data/src/jpeg-7/jconfig.cfg +0 -45
- data/src/jpeg-7/jconfig.dj +0 -38
- data/src/jpeg-7/jconfig.mac +0 -43
- data/src/jpeg-7/jconfig.manx +0 -43
- data/src/jpeg-7/jconfig.mc6 +0 -52
- data/src/jpeg-7/jconfig.sas +0 -43
- data/src/jpeg-7/jconfig.st +0 -42
- data/src/jpeg-7/jconfig.txt +0 -155
- data/src/jpeg-7/jconfig.vc +0 -45
- data/src/jpeg-7/jconfig.vms +0 -37
- data/src/jpeg-7/jconfig.wat +0 -38
- data/src/jpeg-7/jcparam.c +0 -632
- data/src/jpeg-7/jcprepct.c +0 -358
- data/src/jpeg-7/jcsample.c +0 -545
- data/src/jpeg-7/jctrans.c +0 -381
- data/src/jpeg-7/jdapimin.c +0 -396
- data/src/jpeg-7/jdapistd.c +0 -275
- data/src/jpeg-7/jdarith.c +0 -762
- data/src/jpeg-7/jdatadst.c +0 -151
- data/src/jpeg-7/jdatasrc.c +0 -212
- data/src/jpeg-7/jdcoefct.c +0 -736
- data/src/jpeg-7/jdcolor.c +0 -396
- data/src/jpeg-7/jdct.h +0 -393
- data/src/jpeg-7/jddctmgr.c +0 -382
- data/src/jpeg-7/jdhuff.c +0 -1309
- data/src/jpeg-7/jdinput.c +0 -384
- data/src/jpeg-7/jdmainct.c +0 -512
- data/src/jpeg-7/jdmarker.c +0 -1360
- data/src/jpeg-7/jdmaster.c +0 -663
- data/src/jpeg-7/jdmerge.c +0 -400
- data/src/jpeg-7/jdpostct.c +0 -290
- data/src/jpeg-7/jdsample.c +0 -361
- data/src/jpeg-7/jdtrans.c +0 -136
- data/src/jpeg-7/jerror.c +0 -252
- data/src/jpeg-7/jerror.h +0 -304
- data/src/jpeg-7/jfdctflt.c +0 -174
- data/src/jpeg-7/jfdctfst.c +0 -230
- data/src/jpeg-7/jfdctint.c +0 -4348
- data/src/jpeg-7/jidctflt.c +0 -242
- data/src/jpeg-7/jidctfst.c +0 -368
- data/src/jpeg-7/jidctint.c +0 -5137
- data/src/jpeg-7/jinclude.h +0 -91
- data/src/jpeg-7/jmemansi.c +0 -167
- data/src/jpeg-7/jmemdos.c +0 -638
- data/src/jpeg-7/jmemdosa.asm +0 -379
- data/src/jpeg-7/jmemmac.c +0 -289
- data/src/jpeg-7/jmemmgr.c +0 -1118
- data/src/jpeg-7/jmemname.c +0 -276
- data/src/jpeg-7/jmemnobs.c +0 -109
- data/src/jpeg-7/jmemsys.h +0 -198
- data/src/jpeg-7/jmorecfg.h +0 -369
- data/src/jpeg-7/jpegint.h +0 -395
- data/src/jpeg-7/jpeglib.h +0 -1135
- data/src/jpeg-7/jpegtran.1 +0 -272
- data/src/jpeg-7/jpegtran.c +0 -546
- data/src/jpeg-7/jquant1.c +0 -856
- data/src/jpeg-7/jquant2.c +0 -1310
- data/src/jpeg-7/jutils.c +0 -179
- data/src/jpeg-7/jversion.h +0 -14
- data/src/jpeg-7/libjpeg.map +0 -4
- data/src/jpeg-7/libjpeg.txt +0 -3067
- data/src/jpeg-7/ltmain.sh +0 -8406
- data/src/jpeg-7/makcjpeg.st +0 -36
- data/src/jpeg-7/makdjpeg.st +0 -36
- data/src/jpeg-7/makeadsw.vc6 +0 -77
- data/src/jpeg-7/makeasln.vc9 +0 -33
- data/src/jpeg-7/makecdep.vc6 +0 -82
- data/src/jpeg-7/makecdsp.vc6 +0 -130
- data/src/jpeg-7/makecmak.vc6 +0 -159
- data/src/jpeg-7/makecvcp.vc9 +0 -186
- data/src/jpeg-7/makeddep.vc6 +0 -82
- data/src/jpeg-7/makeddsp.vc6 +0 -130
- data/src/jpeg-7/makedmak.vc6 +0 -159
- data/src/jpeg-7/makedvcp.vc9 +0 -186
- data/src/jpeg-7/makefile.ansi +0 -220
- data/src/jpeg-7/makefile.bcc +0 -291
- data/src/jpeg-7/makefile.dj +0 -226
- data/src/jpeg-7/makefile.manx +0 -220
- data/src/jpeg-7/makefile.mc6 +0 -255
- data/src/jpeg-7/makefile.mms +0 -224
- data/src/jpeg-7/makefile.sas +0 -258
- data/src/jpeg-7/makefile.unix +0 -234
- data/src/jpeg-7/makefile.vc +0 -217
- data/src/jpeg-7/makefile.vms +0 -142
- data/src/jpeg-7/makefile.wat +0 -239
- data/src/jpeg-7/makejdep.vc6 +0 -423
- data/src/jpeg-7/makejdsp.vc6 +0 -285
- data/src/jpeg-7/makejdsw.vc6 +0 -29
- data/src/jpeg-7/makejmak.vc6 +0 -425
- data/src/jpeg-7/makejsln.vc9 +0 -17
- data/src/jpeg-7/makejvcp.vc9 +0 -328
- data/src/jpeg-7/makeproj.mac +0 -213
- data/src/jpeg-7/makerdep.vc6 +0 -6
- data/src/jpeg-7/makerdsp.vc6 +0 -78
- data/src/jpeg-7/makermak.vc6 +0 -110
- data/src/jpeg-7/makervcp.vc9 +0 -133
- data/src/jpeg-7/maketdep.vc6 +0 -43
- data/src/jpeg-7/maketdsp.vc6 +0 -122
- data/src/jpeg-7/maketmak.vc6 +0 -131
- data/src/jpeg-7/maketvcp.vc9 +0 -178
- data/src/jpeg-7/makewdep.vc6 +0 -6
- data/src/jpeg-7/makewdsp.vc6 +0 -78
- data/src/jpeg-7/makewmak.vc6 +0 -110
- data/src/jpeg-7/makewvcp.vc9 +0 -133
- data/src/jpeg-7/makljpeg.st +0 -68
- data/src/jpeg-7/maktjpeg.st +0 -30
- data/src/jpeg-7/makvms.opt +0 -4
- data/src/jpeg-7/missing +0 -376
- data/src/jpeg-7/rdbmp.c +0 -439
- data/src/jpeg-7/rdcolmap.c +0 -253
- data/src/jpeg-7/rdgif.c +0 -38
- data/src/jpeg-7/rdjpgcom.1 +0 -63
- data/src/jpeg-7/rdjpgcom.c +0 -515
- data/src/jpeg-7/rdppm.c +0 -459
- data/src/jpeg-7/rdrle.c +0 -387
- data/src/jpeg-7/rdswitch.c +0 -365
- data/src/jpeg-7/rdtarga.c +0 -500
- data/src/jpeg-7/structure.txt +0 -945
- data/src/jpeg-7/testimg.bmp +0 -0
- data/src/jpeg-7/testimg.jpg +0 -0
- data/src/jpeg-7/testimg.ppm +0 -4
- data/src/jpeg-7/testimgp.jpg +0 -0
- data/src/jpeg-7/testorig.jpg +0 -0
- data/src/jpeg-7/testprog.jpg +0 -0
- data/src/jpeg-7/transupp.c +0 -1533
- data/src/jpeg-7/transupp.h +0 -205
- data/src/jpeg-7/usage.txt +0 -605
- data/src/jpeg-7/wizard.txt +0 -211
- data/src/jpeg-7/wrbmp.c +0 -442
- data/src/jpeg-7/wrgif.c +0 -399
- data/src/jpeg-7/wrjpgcom.1 +0 -103
- data/src/jpeg-7/wrjpgcom.c +0 -583
- data/src/jpeg-7/wrppm.c +0 -269
- data/src/jpeg-7/wrrle.c +0 -305
- data/src/jpeg-7/wrtarga.c +0 -253
data/src/gocr-0.48/src/ocr1.c
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
// test routines - faster to compile
|
2
|
-
#include <stdlib.h>
|
3
|
-
#include <stdio.h>
|
4
|
-
#include "pgm2asc.h"
|
5
|
-
#include "unicode.h"
|
6
|
-
#include "amiga.h"
|
7
|
-
#include "gocr.h"
|
8
|
-
|
9
|
-
// for learn_mode/analyze_mode high, with, yoffset, num of pattern_i,
|
10
|
-
// - holes (center,radius in relative coordinates) etc. => cluster analyze
|
11
|
-
// num_hole => min-volume, tolerance border
|
12
|
-
// pattern: @@ @. @@
|
13
|
-
// .@ @. ..
|
14
|
-
// regular filter for large resolutions to make edges more smooth (on boxes)
|
15
|
-
// extra-filter (only if not recognized?)
|
16
|
-
// map + same color to (#==change)
|
17
|
-
// - anti color
|
18
|
-
// . not used
|
19
|
-
// strongest neighbour pixels (3x3) => directions
|
20
|
-
// second/third run with more and more tolerance!?
|
21
|
-
|
22
|
-
/* FIXME jb: following is unused */
|
23
|
-
#if 0
|
24
|
-
struct lobj { // line-object (for fitting to near lines)
|
25
|
-
int x0,y0; // starting point (left up)
|
26
|
-
int x1,y1; // end point (right down)
|
27
|
-
int mt; // minimum thickness
|
28
|
-
int q; // quality, overlapp
|
29
|
-
};
|
30
|
-
|
31
|
-
/* FIXME jb global */
|
32
|
-
struct lobj obj1;
|
33
|
-
#endif
|
34
|
-
|
35
|
-
// that is the first draft of feature extraction
|
36
|
-
// detect main lines and bows
|
37
|
-
// seems bad implemented, looking for better algorithms (ToDo: use autotrace)
|
38
|
-
#define MAXL 10
|
39
|
-
void ocr2(pix *b,int cs){
|
40
|
-
int x1,y1,x2,y2,l,i,j,xa[MAXL],ya[MAXL],xb[MAXL],yb[MAXL],ll[MAXL];
|
41
|
-
for(i=0;i<MAXL;i++)xa[i]=ya[i]=xb[i]=yb[i]=ll[i]=0;
|
42
|
-
for(x1=0;x1<b->x;x1++) // very slowly, but simple to program
|
43
|
-
for(y1=0;y1<b->y;y1++) // brute force
|
44
|
-
for(x2=0;x2<b->x;x2++)
|
45
|
-
for(y2=y1+1;y2<b->y;y2++)
|
46
|
-
{
|
47
|
-
if( get_line2(x1,y1,x2,y2,b,cs,100)>99 )
|
48
|
-
{ // line ???
|
49
|
-
l=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1); // len
|
50
|
-
for(i=0;i<MAXL;i++)
|
51
|
-
{ // remove similar lines (same middle point) IMPROVE IT !!!!!! ???
|
52
|
-
if(
|
53
|
-
abs(x1+x2-xa[i]-xb[i])<1+b->x/2
|
54
|
-
&& abs(y1+y2-ya[i]-yb[i])<1+b->y/2
|
55
|
-
&& abs(y1-ya[i])<1+b->y/4
|
56
|
-
&& abs(x1-xa[i])<1+b->x/4
|
57
|
-
)
|
58
|
-
{
|
59
|
-
if( l>ll[i] )
|
60
|
-
{
|
61
|
-
for(j=i;j<MAXL-1;j++)
|
62
|
-
{ // shift table
|
63
|
-
xa[j]=xa[j+1];ya[j]=ya[j+1];
|
64
|
-
xb[j]=xb[j+1];yb[j]=yb[j+1];ll[j]=ll[j+1];
|
65
|
-
}
|
66
|
-
ll[MAXL-1]=0;
|
67
|
-
}
|
68
|
-
else break; // forget it if shorter
|
69
|
-
}
|
70
|
-
if( l>ll[i] ){ // insert if larger
|
71
|
-
for(j=MAXL-1;j>i;j--){ // shift table
|
72
|
-
xa[j]=xa[j-1];ya[j]=ya[j-1];
|
73
|
-
xb[j]=xb[j-1];yb[j]=yb[j-1];ll[j]=ll[j-1];
|
74
|
-
}
|
75
|
-
xa[i]=x1;ya[i]=y1;xb[i]=x2;yb[i]=y2;ll[i]=l;
|
76
|
-
break;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
for(i=0;i<MAXL;i++){
|
82
|
-
printf(" %2d %2d %2d %2d %3d\n",xa[i],ya[i],xb[i],yb[i],ll[i]);
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
data/src/gocr-0.48/src/ocr1.h
DELETED
data/src/gocr-0.48/src/otsu.c
DELETED
@@ -1,289 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
This is a Optical-Character-Recognition program
|
3
|
-
Copyright (C) 2000-2009 Joerg Schulenburg
|
4
|
-
|
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.
|
9
|
-
|
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.
|
14
|
-
|
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.
|
18
|
-
|
19
|
-
see README for EMAIL-address
|
20
|
-
|
21
|
-
the following code was send by Ryan Dibble <dibbler@umich.edu>
|
22
|
-
|
23
|
-
The algorithm is very simple but works good hopefully.
|
24
|
-
|
25
|
-
Compare the grayscale histogram with a mass density diagram:
|
26
|
-
I think the algorithm is a kind of
|
27
|
-
divide a body into two parts in a way that the mass
|
28
|
-
centers have the largest distance from each other,
|
29
|
-
the function is weighted in a way that same masses have a advantage
|
30
|
-
|
31
|
-
- otsu algorithm is failing on diskrete multi color images
|
32
|
-
|
33
|
-
TODO:
|
34
|
-
RGB: do the same with all colors (CMYG?) seperately
|
35
|
-
|
36
|
-
test: hardest case = two colors
|
37
|
-
bbg: test done, using a two color gray file. Output:
|
38
|
-
# threshold: Value = 43 gmin=43 gmax=188
|
39
|
-
|
40
|
-
my changes:
|
41
|
-
- float -> double
|
42
|
-
- debug option added (vvv & 1..2)
|
43
|
-
- **image => *image, &image[i][1] => &image[i*cols+1]
|
44
|
-
- do only count pixels near contrast regions
|
45
|
-
this makes otsu much better for shadowed fonts or multi colored text
|
46
|
-
on white background
|
47
|
-
|
48
|
-
(m) Joerg Schulenburg (see README for email address)
|
49
|
-
|
50
|
-
ToDo:
|
51
|
-
- measure contrast
|
52
|
-
- detect low-contrast regions
|
53
|
-
|
54
|
-
*/
|
55
|
-
|
56
|
-
#include <stdio.h>
|
57
|
-
#include <string.h>
|
58
|
-
|
59
|
-
#define Abs(x) ((x<0)?-(x):x)
|
60
|
-
|
61
|
-
/*======================================================================*
|
62
|
-
* global thresholding routine *
|
63
|
-
* takes a 2D unsigned char array pointer, number of rows, and *
|
64
|
-
* number of cols in the array. returns the value of the threshold *
|
65
|
-
* x0,y0,x0+dx,y0+dy are the edgepoints of the interesting region *
|
66
|
-
* vvv is the verbosity for debugging purpose *
|
67
|
-
*======================================================================*/
|
68
|
-
int
|
69
|
-
otsu (unsigned char *image, int rows, int cols,
|
70
|
-
int x0, int y0, int dx, int dy, int vvv) {
|
71
|
-
|
72
|
-
unsigned char *np; // pointer to position in the image we are working with
|
73
|
-
unsigned char op1, op2; // predecessor of pixel *np (start value)
|
74
|
-
int maxc=0; // maximum contrast (start value)
|
75
|
-
int thresholdValue=1; // value we will threshold at
|
76
|
-
int ihist[256]; // image histogram
|
77
|
-
int chist[256]; // contrast histogram
|
78
|
-
|
79
|
-
int i, j, k; // various counters
|
80
|
-
int is, i1, i2, ns, n1, n2, gmin, gmax;
|
81
|
-
double m1, m2, sum, csum, fmax, sb;
|
82
|
-
|
83
|
-
// zero out histogram ...
|
84
|
-
memset(ihist, 0, sizeof(ihist));
|
85
|
-
memset(chist, 0, sizeof(chist));
|
86
|
-
op1=op2=0;
|
87
|
-
|
88
|
-
gmin=255; gmax=0; k=dy/512+1;
|
89
|
-
// v0.43 first get max contrast, dont do it together with next step
|
90
|
-
// because it failes if we have pattern as background (on top)
|
91
|
-
for (i = 0; i < dy ; i+=k) {
|
92
|
-
np = &image[(y0+i)*cols+x0];
|
93
|
-
for (j = 0; j < dx ; j++) {
|
94
|
-
ihist[*np]++;
|
95
|
-
if(*np > gmax) gmax=*np;
|
96
|
-
if(*np < gmin) gmin=*np;
|
97
|
-
if (Abs(*np-op1)>maxc) maxc=Abs(*np-op1); /* new maximum contrast */
|
98
|
-
if (Abs(*np-op2)>maxc) maxc=Abs(*np-op2); /* new maximum contrast */
|
99
|
-
/* we hope that maxc will be find its maximum very fast */
|
100
|
-
op2=op1; /* shift old pixel to next older */
|
101
|
-
op1=*np; /* store old pixel for contrast check */
|
102
|
-
np++; /* next pixel */
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
// generate the histogram
|
107
|
-
// Aug06 images with large white or black homogeneous
|
108
|
-
// areas give bad results, so we only add pixels on contrast edges
|
109
|
-
for (i = 0; i < dy ; i+=k) {
|
110
|
-
np = &image[(y0+i)*cols+x0];
|
111
|
-
for (j = 0; j < dx ; j++) {
|
112
|
-
if (Abs(*np-op1)>maxc/4
|
113
|
-
|| Abs(*np-op2)>maxc/4)
|
114
|
-
chist[*np]++; // count only relevant pixels
|
115
|
-
op2=op1; /* shift old pixel to next older */
|
116
|
-
op1=*np; /* store old pixel for contrast check */
|
117
|
-
np++; /* next pixel */
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
// set up everything
|
122
|
-
sum = csum = 0.0;
|
123
|
-
ns = 0;
|
124
|
-
is = 0;
|
125
|
-
|
126
|
-
for (k = 0; k <= 255; k++) {
|
127
|
-
sum += (double) k * (double) chist[k]; /* x*f(x) cmass moment */
|
128
|
-
ns += chist[k]; /* f(x) cmass */
|
129
|
-
is += ihist[k]; /* f(x) imass */
|
130
|
-
// Debug: output to out_hist.dat?
|
131
|
-
// fprintf(stderr,"\chistogram %3d %6d (brightness weight)", k, ihist[k]);
|
132
|
-
}
|
133
|
-
|
134
|
-
if (!ns) {
|
135
|
-
// if n has no value we have problems...
|
136
|
-
fprintf (stderr, "NOT NORMAL, thresholdValue = 160\n");
|
137
|
-
return (160);
|
138
|
-
}
|
139
|
-
|
140
|
-
// ToDo: only care about extremas in a 3 pixel environment
|
141
|
-
// check if there are more than 2 mass centers (more colors)
|
142
|
-
// return object colors and color radius instead of threshold value
|
143
|
-
// also the reagion, where colored objects are found
|
144
|
-
// what if more than one background color? no otsu at all?
|
145
|
-
// whats background? box with lot of other boxes in it
|
146
|
-
// threshold each box (examples/invers.png,colors.png)
|
147
|
-
// get maximum white and minimum black pixel color (possible range)
|
148
|
-
// check range between them for low..high contrast ???
|
149
|
-
// typical scenes (which must be covered):
|
150
|
-
// - white page with text of different colors (gray values)
|
151
|
-
// - binear page: background (gray=1) + black text (gray=0)
|
152
|
-
// - text mixed with big (dark) images
|
153
|
-
// ToDo: recursive clustering for maximum multipol moments?
|
154
|
-
// idea: normalize ihist to max=1024 before otsu?
|
155
|
-
|
156
|
-
// do the otsu global thresholding method
|
157
|
-
|
158
|
-
if ((vvv&1)) // Debug
|
159
|
-
fprintf(stderr,"# threshold: value ihist chist mass_dipol_moment\n");
|
160
|
-
fmax = -1.0;
|
161
|
-
n1 = 0;
|
162
|
-
for (k = 0; k < 255; k++) {
|
163
|
-
n1 += chist[k]; // left mass (integration)
|
164
|
-
if (!n1) continue; // we need at least one foreground pixel
|
165
|
-
n2 = ns - n1; // right mass (num pixels - left mass)
|
166
|
-
if (n2 == 0) break; // we need at least one background pixel
|
167
|
-
csum += (double) k *chist[k]; // left mass moment
|
168
|
-
m1 = csum / n1; // left mass center (black chars)
|
169
|
-
m2 = (sum - csum) / n2; // right mass center (white background)
|
170
|
-
// max. dipol moment?
|
171
|
-
// orig: sb = (double) n1 *(double) n2 * (m1 - m2) * (m1 - m2);
|
172
|
-
sb = (double) n1 *(double) n2 * (m2 - m1); // seems to be better Aug06
|
173
|
-
/* bbg: note: can be optimized. */
|
174
|
-
if (sb > fmax) {
|
175
|
-
fmax = sb;
|
176
|
-
thresholdValue = k + 1;
|
177
|
-
// thresholdValue = (m1 + 3 * m2) / 4;
|
178
|
-
}
|
179
|
-
if ((vvv&1) && ihist[k]) // Debug
|
180
|
-
fprintf(stderr,"# threshold: %3d %6d %6d %8.2f\n",
|
181
|
-
k, ihist[k], chist[k],
|
182
|
-
sb/(dx*dy)); /* normalized dipol moment */
|
183
|
-
}
|
184
|
-
// ToDo: error = left/right point where sb is 90% of maximum?
|
185
|
-
// now we count all pixels for background detection
|
186
|
-
i1 = 0;
|
187
|
-
for (k = 0; k < thresholdValue; k++) {
|
188
|
-
i1 += ihist[k]; // left mass (integration)
|
189
|
-
}
|
190
|
-
i2 = is - i1; // right mass (num pixels - left mass)
|
191
|
-
|
192
|
-
// at this point we have our thresholding value
|
193
|
-
// black_char: value<cs, white_background: value>=cs
|
194
|
-
|
195
|
-
// can it happen? check for sureness
|
196
|
-
if (thresholdValue > gmax) {
|
197
|
-
fprintf(stderr,"# threshold: Value >gmax\n");
|
198
|
-
thresholdValue = gmax;
|
199
|
-
}
|
200
|
-
if (thresholdValue <= gmin) {
|
201
|
-
fprintf(stderr,"# threshold: Value<=gmin\n");
|
202
|
-
thresholdValue = gmin+1;
|
203
|
-
}
|
204
|
-
|
205
|
-
// debug code to display thresholding values
|
206
|
-
if ( vvv & 1 )
|
207
|
-
fprintf(stderr,"# threshold: Value = %d gmin=%d gmax=%d cmax=%d"
|
208
|
-
" b/w= %d %d\n",
|
209
|
-
thresholdValue, gmin, gmax, maxc, i1, i2);
|
210
|
-
|
211
|
-
// this is a primitive criteria for inversion and should be improved
|
212
|
-
// old: i1 >= 4*i2, but 0811qemu1.png has a bit above 1/4
|
213
|
-
if (2*i1 > 7*i2) { // more black than white, obviously black is background
|
214
|
-
if ( vvv & 1 )
|
215
|
-
fprintf(stderr,"# threshold: invert the image\n");
|
216
|
-
// we do inversion here (no data lost)
|
217
|
-
for (i = 0; i < dy ; i++) {
|
218
|
-
np = &image[(y0+i)*cols+x0];
|
219
|
-
for (j = 0; j < dx ; j++) {
|
220
|
-
*np=255-*np;
|
221
|
-
np++; /* next pixel */
|
222
|
-
}
|
223
|
-
}
|
224
|
-
thresholdValue=255-thresholdValue+1;
|
225
|
-
}
|
226
|
-
|
227
|
-
return(thresholdValue);
|
228
|
-
/* range: 0 < thresholdValue <= 255, example: 1 on b/w images */
|
229
|
-
/* 0..threshold-1 is foreground */
|
230
|
-
/* threshold..255 is background */
|
231
|
-
/* ToDo: min=blackmasscenter/2,thresh,max=(whitemasscenter+255)/2 */
|
232
|
-
}
|
233
|
-
|
234
|
-
/*======================================================================*/
|
235
|
-
/* thresholding the image (set threshold to 128+32=160=0xA0) */
|
236
|
-
/* now we have a fixed thresholdValue good to recognize on gray image */
|
237
|
-
/* - so lower bits can used for other things (bad design?) */
|
238
|
-
/* ToDo: different foreground colors, gray on black/white background */
|
239
|
-
/*======================================================================*/
|
240
|
-
int
|
241
|
-
thresholding (unsigned char *image, int rows, int cols,
|
242
|
-
int x0, int y0, int dx, int dy, int thresholdValue) {
|
243
|
-
|
244
|
-
unsigned char *np; // pointer to position in the image we are working with
|
245
|
-
|
246
|
-
int i, j; // various counters
|
247
|
-
int gmin=255,gmax=0;
|
248
|
-
int nmin=255,nmax=0;
|
249
|
-
|
250
|
-
// calculate min/max (twice?)
|
251
|
-
for (i = y0 + 1; i < y0 + dy - 1; i++) {
|
252
|
-
np = &image[i*cols+x0+1];
|
253
|
-
for (j = x0 + 1; j < x0 + dx - 1; j++) {
|
254
|
-
if(*np > gmax) gmax=*np;
|
255
|
-
if(*np < gmin) gmin=*np;
|
256
|
-
np++; /* next pixel */
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
/* allowed_threshold=gmin+1..gmax v0.43 */
|
261
|
-
if (thresholdValue<=gmin || thresholdValue>gmax){
|
262
|
-
thresholdValue=(gmin+gmax+1)/2; /* range=0..1 -> threshold=1 */
|
263
|
-
fprintf(stderr,"# thresholdValue out of range %d..%d, reset to %d\n",
|
264
|
-
gmin, gmax, thresholdValue);
|
265
|
-
}
|
266
|
-
|
267
|
-
/* b/w: min=0,tresh=1,max=1 v0.43 */
|
268
|
-
// actually performs the thresholding of the image...
|
269
|
-
// later: grayvalues should also be used, only rescaling threshold=160=0xA0
|
270
|
-
// sometimes images have no contrast (thresholdValue == gmin)
|
271
|
-
for (i = y0; i < y0+dy; i++) {
|
272
|
-
np = &image[i*cols+x0];
|
273
|
-
for (j = x0; j < x0+dx; j++) {
|
274
|
-
*np = (unsigned char) (*np >= thresholdValue || thresholdValue == gmin ?
|
275
|
-
(255-(gmax - *np)* 80/(gmax - thresholdValue + 1)) :
|
276
|
-
( 0+(*np - gmin)*150/(thresholdValue - gmin )) );
|
277
|
-
if(*np > nmax) nmax=*np;
|
278
|
-
if(*np < nmin) nmin=*np;
|
279
|
-
np++;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
// fprintf(stderr,"# thresholding: nmin=%d nmax=%d\n", nmin, nmax);
|
284
|
-
|
285
|
-
return(128+32); // return the new normalized threshold value
|
286
|
-
/* 0..159 is foreground */
|
287
|
-
/* 160..255 is background */
|
288
|
-
}
|
289
|
-
|
data/src/gocr-0.48/src/otsu.h
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
|
3
|
-
see README for EMAIL-address
|
4
|
-
|
5
|
-
*/
|
6
|
-
|
7
|
-
|
8
|
-
/*======================================================================*/
|
9
|
-
/* OTSU global thresholding routine */
|
10
|
-
/* takes a 2D unsigned char array pointer, number of rows, and */
|
11
|
-
/* number of cols in the array. returns the value of the threshold */
|
12
|
-
/*======================================================================*/
|
13
|
-
int
|
14
|
-
otsu (unsigned char *image, int rows, int cols, int x0, int y0, int dx, int dy, int vvv);
|
15
|
-
|
16
|
-
|
17
|
-
/*======================================================================*/
|
18
|
-
/* thresholding the image (set threshold to 128+32=160=0xA0) */
|
19
|
-
/* now we have a fixed thresholdValue good to recognize on gray image */
|
20
|
-
/* - so lower bits can used for other things (bad design?) */
|
21
|
-
/*======================================================================*/
|
22
|
-
int
|
23
|
-
thresholding (unsigned char *image, int rows, int cols, int x0, int y0, int dx, int dy, int thresholdValue);
|
data/src/gocr-0.48/src/output.c
DELETED
@@ -1,289 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
This is a Optical-Character-Recognition program
|
3
|
-
Copyright (C) 2000-2009 Joerg Schulenburg
|
4
|
-
|
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.
|
9
|
-
|
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.
|
14
|
-
|
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.
|
18
|
-
|
19
|
-
see README for EMAIL address
|
20
|
-
*/
|
21
|
-
|
22
|
-
#include <string.h>
|
23
|
-
#include "unicode.h"
|
24
|
-
#include "output.h"
|
25
|
-
#include "pcx.h"
|
26
|
-
#include "gocr.h" /* extern job_t JOB; */
|
27
|
-
|
28
|
-
/* function is only for debugging and for developing
|
29
|
-
it prints out a part of pixmap b at point x0,y0 to stderr
|
30
|
-
using dots .,; if no pixel, and @xoO for pixels
|
31
|
-
modify n_run and print out what would happen on 2nd, 3th loop!
|
32
|
-
new: output original and copied pixmap in the same figure
|
33
|
-
*/
|
34
|
-
void out_b(struct box *px, pix *b, int x0, int y0, int dx, int dy, int cs ){
|
35
|
-
int x,y,x2,y2,yy0,tx,ty,n1,i;
|
36
|
-
char c1, c2;
|
37
|
-
yy0=y0;
|
38
|
-
if (px) { /* overwrite rest of arguments */
|
39
|
-
if (!b) {
|
40
|
-
b=px->p;
|
41
|
-
x0=px->x0; dx=px->x1-px->x0+1;
|
42
|
-
y0=px->y0; dy=px->y1-px->y0+1; yy0=y0;
|
43
|
-
}
|
44
|
-
if(cs==0) cs=JOB->cfg.cs;
|
45
|
-
fprintf(stderr,"\n# list box x= %4d %4d d= %3d %3d r= %3d %3d"
|
46
|
-
" nrun=%d p=%p", /* ToDo: r,nrun is obsolete */
|
47
|
-
px->x0, px->y0, px->x1 - px->x0 + 1, px->y1 - px->y0 + 1,
|
48
|
-
px->x - px->x0, px->y - px->y0, JOB->tmp.n_run, (void*)px);
|
49
|
-
fprintf(stderr,"\n# dots=%d boxes=%d subboxes=%d c=%s mod=%s"
|
50
|
-
" line=%d m= %d %d %d %d",
|
51
|
-
px->dots, px->num_boxes, px->num_subboxes,
|
52
|
-
decode(px->c,ASCII), decode(px->modifier,ASCII), px->line,
|
53
|
-
px->m1 - px->y0, px->m2 - px->y0, px->m3 - px->y0, px->m4 - px->y0);
|
54
|
-
if (px->num_frames) {
|
55
|
-
int i,j,jo;
|
56
|
-
fprintf(stderr,"\n# frames= %d (sumvects=%d)",px->num_frames,
|
57
|
-
((px->num_frames)?px->num_frame_vectors[px->num_frames-1]:-1));
|
58
|
-
for (jo=j=i=0; i<px->num_frames; i++, jo=j) {
|
59
|
-
fprintf(stderr,"\n# frame %d (%+4d,%3d,%2d) ",
|
60
|
-
i, px->frame_vol[i], px->frame_per[i],
|
61
|
-
px->num_frame_vectors[i]-jo);
|
62
|
-
/* print only the first vectors of each frame */
|
63
|
-
for (;j<px->num_frame_vectors[i] && j<MaxFrameVectors; j++)
|
64
|
-
fprintf(stderr," #%02d %2d %2d", j,
|
65
|
-
px->frame_vector[j][0] - px->x0,
|
66
|
-
px->frame_vector[j][1] - px->y0);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
if (px->num_ac){ /* output table of chars and its probabilities */
|
70
|
-
fprintf(stderr,"\n# list box char: ");
|
71
|
-
for(i=0;i<px->num_ac && i<NumAlt;i++)
|
72
|
-
/* output the (xml-)string (picture position, barcodes, glyphs, ...) */
|
73
|
-
if (px->tas[i])
|
74
|
-
fprintf(stderr," %s(%d)", px->tas[i] ,px->wac[i]);
|
75
|
-
else
|
76
|
-
fprintf(stderr," %s(%d)",decode(px->tac[i],ASCII),px->wac[i]);
|
77
|
-
}
|
78
|
-
fprintf(stderr,"\n");
|
79
|
-
if (px->m2 && px->m1<y0 && (px->dots || y0>px->m2)) {
|
80
|
-
yy0=px->m1; dy=px->y1-yy0+1;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
tx=dx/80+1;
|
84
|
-
ty=dy/40+1; /* step, usually 1, but greater on large maps */
|
85
|
-
fprintf(stderr,"# list pattern x= %4d %4d d= %3d %3d t= %d %d yy0= %d\n",
|
86
|
-
x0,y0,dx,dy,tx,ty,yy0);
|
87
|
-
if (dx>0)
|
88
|
-
for(y=yy0;y<yy0+dy;y+=ty) { /* reduce the output to max 78x40 */
|
89
|
-
/* first image is the copied and modified bitmap of the box */
|
90
|
-
if (px)
|
91
|
-
for(x=x0;x<x0+dx;x+=tx){ /* by merging sub-pixels */
|
92
|
-
n1=0; c1='.';
|
93
|
-
for(y2=y;y2<y+ty && y2<y0+dy;y2++) /* sub-pixels */
|
94
|
-
for(x2=x;x2<x+tx && x2<x0+dx;x2++)
|
95
|
-
{
|
96
|
-
if((getpixel(px->p,x2-x0+px->x0,
|
97
|
-
y2-y0+px->y0)<cs)) c1='@';
|
98
|
-
}
|
99
|
-
if (px->num_frames) { /* mark vectors */
|
100
|
-
int i;
|
101
|
-
if (c1!='$' && c1!='S') /* dont mark twice */
|
102
|
-
for (i=0;i<px->num_frame_vectors[px->num_frames-1];i++)
|
103
|
-
if ((px->frame_vector[i][0]-px->x0)/tx==(x-x0)/tx
|
104
|
-
&& (px->frame_vector[i][1]-px->y0)/ty==(y-y0)/ty)
|
105
|
-
{ c1=((c1=='@')?'$':'S'); break; }
|
106
|
-
}
|
107
|
-
fprintf(stderr,"%c", c1 );
|
108
|
-
}
|
109
|
-
|
110
|
-
/* 2nd image is the boxframe in the original bitmap */
|
111
|
-
if (dx<40) fprintf(stderr," ");
|
112
|
-
if (dx<40) /* do it only, if we have enough place */
|
113
|
-
for(x=x0;x<x0+dx;x+=tx){ /* by merging sub-pixels */
|
114
|
-
c1='.';
|
115
|
-
for(y2=y;y2<y+ty && y2<y0+dy;y2++) /* sub-pixels */
|
116
|
-
for(x2=x;x2<x+tx && x2<x0+dx;x2++)
|
117
|
-
{ if((getpixel(b,x2,y2)<cs)) c1='@'; }
|
118
|
-
fprintf(stderr,"%c", c1 );
|
119
|
-
}
|
120
|
-
|
121
|
-
c1=c2=' ';
|
122
|
-
/* mark lines with < */
|
123
|
-
if (px) if (y-y0+px->y0==px->m1 || y-y0+px->y0==px->m2
|
124
|
-
|| y-y0+px->y0==px->m3 || y-y0+px->y0==px->m4) c1='<';
|
125
|
-
if (y==y0 || y==yy0+dy-1) c2='-'; /* boxmarks */
|
126
|
-
|
127
|
-
fprintf(stderr,"%c%c\n",c1,c2);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
/* same as out_b, but for faster use, only a box as argument
|
132
|
-
*/
|
133
|
-
void out_x(struct box *px) {
|
134
|
-
out_b(px,NULL,0, 0, 0, 0, JOB->cfg.cs);
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
/* print out two boxes side by side, for debugging comparision algos */
|
139
|
-
void out_x2(struct box *box1, struct box *box2){
|
140
|
-
int x,y,i,tx,ty,dy;
|
141
|
-
/*FIXME jb static*/static char *c1="OXXXXxx@.,,,,,,,";
|
142
|
-
pix *b=&JOB->src.p;
|
143
|
-
dy=(box1->y1-box1->y0+1);
|
144
|
-
if(dy<box2->y1-box2->y0+1)dy=box2->y1-box2->y0+1;
|
145
|
-
tx=(box1->x1-box1->x0)/40+1;
|
146
|
-
ty=(box1->y1-box1->y0)/40+1; /* step, usually 1, but greater on large maps */
|
147
|
-
if(box2)fprintf(stderr,"\n# list 2 patterns");
|
148
|
-
for(i=0;i<dy;i+=ty) { /* reduce the output to max 78x40??? */
|
149
|
-
fprintf(stderr,"\n"); y=box1->y0+i;
|
150
|
-
for(x=box1->x0;x<=box1->x1;x+=tx)
|
151
|
-
fprintf(stderr,"%c", c1[ ((getpixel(b,x,y)<JOB->cfg.cs)?0:8)+marked(b,x,y) ] );
|
152
|
-
if(!box2) continue;
|
153
|
-
fprintf(stderr," "); y=box2->y0+i;
|
154
|
-
for(x=box2->x0;x<=box2->x1;x+=tx)
|
155
|
-
fprintf(stderr,"%c", c1[ ((getpixel(b,x,y)<JOB->cfg.cs)?0:8)+marked(b,x,y) ] );
|
156
|
-
}
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
|
-
/* ---- list output ---- for debugging ---
|
161
|
-
* list all boxes where the results can be found within the c-option
|
162
|
-
*/
|
163
|
-
int output_list(job_t *job) {
|
164
|
-
int i = 0, j;
|
165
|
-
struct box *box2;
|
166
|
-
pix *pp = &job->src.p;
|
167
|
-
char *lc = job->cfg.lc;
|
168
|
-
|
169
|
-
fprintf(stderr,"\n# list shape for charlist %s",lc);
|
170
|
-
for_each_data(&(JOB->res.boxlist)) {
|
171
|
-
box2 = (struct box *) list_get_current(&(JOB->res.boxlist));
|
172
|
-
for (j=0; j<box2->num_ac; j++)
|
173
|
-
if (!lc || (box2->tac[j] && strchr(lc, box2->tac[j]))
|
174
|
-
|| (box2->tas[j] && strstr(lc, box2->tas[j]))) break;
|
175
|
-
if (j<box2->num_ac)
|
176
|
-
fprintf(stderr,"\n# box found in charlist");
|
177
|
-
if (!lc || (strchr(lc, box2->c) && box2->c < 256 && box2->c)
|
178
|
-
|| (strchr(lc, '_') && box2->c==UNKNOWN) /* for compability */
|
179
|
-
|| j<box2->num_ac ){ /* also list alternative chars */
|
180
|
-
if (!pp) pp=box2->p;
|
181
|
-
fprintf(stderr,
|
182
|
-
"\n# list shape %3d x=%4d %4d d= %3d %3d vf=%d ac=%d %04x %s",
|
183
|
-
i, box2->x0, box2->y0,
|
184
|
-
box2->x1 - box2->x0 + 1,
|
185
|
-
box2->y1 - box2->y0 + 1,
|
186
|
-
box2->num_frames, box2->num_ac,
|
187
|
-
(int)box2->c, /* wchar_t -> char ???? */
|
188
|
-
decode(box2->c,ASCII) );
|
189
|
-
if (JOB->cfg.verbose & 4) out_x(box2);
|
190
|
-
}
|
191
|
-
i++;
|
192
|
-
} end_for_each(&(JOB->res.boxlist));
|
193
|
-
fprintf(stderr,"\n");
|
194
|
-
return 0;
|
195
|
-
}
|
196
|
-
|
197
|
-
/* --- output of image incl. corored lines usefull for developers ---
|
198
|
-
* debugging
|
199
|
-
* bit 0+1 is used for color coding (optical marker)
|
200
|
-
* color/gray: 0x01=red, 0x02=blue, 0x04=green???
|
201
|
-
* opt: 1 - mark unknown boxes red (first pass)
|
202
|
-
* 2 - mark unknown boxes more red (final pass)
|
203
|
-
* 4 - mark lines blue
|
204
|
-
* 8 - reset coloring (remove old marker)
|
205
|
-
*/
|
206
|
-
int debug_img(char *fname, struct job_s *job, int opt) {
|
207
|
-
struct box *box2;
|
208
|
-
int x, y, ic, dx, i, j, col;
|
209
|
-
unsigned char *np;
|
210
|
-
pix *pp = &job->tmp.ppo;
|
211
|
-
|
212
|
-
if ( opt & 8 ) { /* clear debug bits in image */
|
213
|
-
for(y=0;y<pp->y;y++) {
|
214
|
-
np=&pp->p[(pp->x)*y];
|
215
|
-
for(x=0;x<pp->x;x++) {
|
216
|
-
*np = *np & 0xF1;
|
217
|
-
np++;
|
218
|
-
}
|
219
|
-
}
|
220
|
-
}
|
221
|
-
|
222
|
-
/* mark longest line which was used to estimate the rotation angle */
|
223
|
-
if ((job->cfg.verbose&32) && job->res.lines.dx)
|
224
|
-
for(i=0;i<pp->x;i++) {
|
225
|
-
y=pp->y/2;
|
226
|
-
if (job->res.lines.dx) y+=job->res.lines.dy*i/job->res.lines.dx;
|
227
|
-
x=i;
|
228
|
-
if (x<0 || x>=pp->x || y<0 || y>=pp->y) continue;
|
229
|
-
np=&pp->p[x + (pp->x)*y];
|
230
|
-
if (*np<160) continue;
|
231
|
-
if((x&7)<5 && !(x&1)) /* dotted line */
|
232
|
-
put(pp,x,y,255,8);
|
233
|
-
}
|
234
|
-
|
235
|
-
ic = ((opt & 2) ? 1 : 2); /* obsolete */
|
236
|
-
for_each_data(&(job->res.boxlist)) {
|
237
|
-
box2 = (struct box *) list_get_current(&(job->res.boxlist));
|
238
|
-
/* mark boxes in 32=0x40=blue */
|
239
|
-
if (box2->c == ' ' || box2->c == '\n') continue;
|
240
|
-
/* mark chars with green left and under line */
|
241
|
-
col = 4; /* green */
|
242
|
-
if (box2->c == UNKNOWN && (opt & 3)) col=2; /* red */
|
243
|
-
if (box2->x0>1)
|
244
|
-
for (y = box2->y0; y <= box2->y1; y++) {
|
245
|
-
np=&pp->p[box2->x0-1 + y * pp->x]; if (*np<160) continue; *np|=col; }
|
246
|
-
if (box2->y1+1<pp->y)
|
247
|
-
for (x = box2->x0; x <= box2->x1; x++) {
|
248
|
-
np=&pp->p[x + (box2->y1+1) * pp->x]; if (*np<160) continue; *np|=col; }
|
249
|
-
/* mark pictures by green cross */
|
250
|
-
if (box2->c == PICTURE)
|
251
|
-
for (x = 0; x < box2->x1-box2->x0+1; x++){
|
252
|
-
y=(box2->y1-box2->y0+1)*x/(box2->x1-box2->x0+1);
|
253
|
-
pp->p[(box2->x0+x) + (box2->y0+y) * pp->x] |= 4;
|
254
|
-
pp->p[(box2->x1-x) + (box2->y0+y) * pp->x] |= 4;
|
255
|
-
}
|
256
|
-
} end_for_each(&(job->res.boxlist));
|
257
|
-
|
258
|
-
if( opt & 4 )
|
259
|
-
{
|
260
|
-
struct tlines *lines = &job->res.lines;
|
261
|
-
int yr;
|
262
|
-
if (job->cfg.verbose)
|
263
|
-
fprintf(stderr, "# mark lines for %s.ppm\n", fname);
|
264
|
-
/* or read from outside??? */
|
265
|
-
for (i = 0; i < lines->num; i++) { /* mark lines by 0x08 = blue */
|
266
|
-
dx = lines->x1[i] - lines->x0[i] + 1;
|
267
|
-
for (j = -1; j < dx+1; j++) {
|
268
|
-
x = lines->x0[i] + j;
|
269
|
-
if (x<0 || x>=pp->x) continue;
|
270
|
-
for (y=lines->m1[i];y<=lines->m4[i];y++) {
|
271
|
-
/* box arround m2-m3 */
|
272
|
-
if (y>=lines->m2[i] && y<=lines->m3[i] && j>-1 && j<dx) continue;
|
273
|
-
yr = y; /* y.rotated */
|
274
|
-
if (lines->dx) yr += lines->dy * x / (lines->dx);
|
275
|
-
if (yr<0 || yr>=pp->y) continue;
|
276
|
-
np = &(pp->p[x + (pp->x)*yr]);
|
277
|
-
if (*np<160) continue; /* do not touch dark pixels */
|
278
|
-
if ((*np&6)!=0) continue; /* only change white pixels */
|
279
|
-
put(pp, x, yr, 255, 6); /* UPN: 255 and 6 or */
|
280
|
-
}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
}
|
284
|
-
|
285
|
-
if (job->cfg.verbose&1)
|
286
|
-
fprintf(stderr,"# writing %s.ppm\n", fname);
|
287
|
-
writeppm(fname, pp);
|
288
|
-
return 0;
|
289
|
-
}
|