~ubuntu-branches/ubuntu/lucid/swftools/lucid

« back to all changes in this revision

Viewing changes to lib/gocr/ocr1.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-04-30 05:22:19 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090430052219-l1n64qofzeq5pej8
Tags: 0.9.0-0ubuntu1
* New upstream release (LP: #369931)
  - patches/01_manpages: edited to match updated version of src/pdf2swf.1 and
    src/wav2swf.1
  - patches/02_faq: edited to match updated version of FAQ
  - patches/04_makefile: edited to delete the patch on lib/Makefile.in and 
    src/Makefile.in (applied upstream)
  - deleted patch 99_configure_for_python2.5_and_2.6 (applied upstream)
  - debian/swftools.doc: deleted installation of TODO and 
    pdf2swf/HOWTO_pdf2swf as they don't exist anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// test routines - faster to compile
 
2
#include <stdlib.h>
 
3
#include <stdio.h>
 
4
#include "pgm2asc.h"
 
5
#include "unicode.h"
 
6
#include "gocr.h"
 
7
 
 
8
// for learn_mode/analyze_mode high, with, yoffset, num of pattern_i,
 
9
//  - holes (center,radius in relative coordinates) etc. => cluster analyze
 
10
// num_hole => min-volume, tolerance border
 
11
// pattern:  @@ @. @@
 
12
//           .@ @. ..
 
13
// regular filter for large resolutions to make edges more smooth (on boxes)
 
14
// extra-filter (only if not recognized?)
 
15
//   map + same color to (#==change)
 
16
//       - anti color
 
17
//       . not used
 
18
// strongest neighbour pixels (3x3) => directions
 
19
// second/third run with more and more tolerance!?
 
20
 
 
21
/* FIXME jb: following is unused */
 
22
#if 0
 
23
struct lobj {   // line-object (for fitting to near lines)
 
24
        int x0,y0;      // starting point (left up)
 
25
        int x1,y1;      // end point      (right down)
 
26
        int mt;         // minimum thickness
 
27
        int q;          // quality, overlapp
 
28
};
 
29
 
 
30
/* FIXME jb global */
 
31
struct lobj obj1;
 
32
#endif
 
33
 
 
34
// that is the first draft of feature extraction 
 
35
// detect main lines and bows
 
36
// seems bad implemented, looking for better algorithms (ToDo: use autotrace)
 
37
#define MAXL 10
 
38
void ocr2(pix *b,int cs){
 
39
  int x1,y1,x2,y2,l,i,j,xa[MAXL],ya[MAXL],xb[MAXL],yb[MAXL],ll[MAXL];
 
40
  for(i=0;i<MAXL;i++)xa[i]=ya[i]=xb[i]=yb[i]=ll[i]=0;
 
41
  for(x1=0;x1<b->x;x1++)                // very slowly, but simple to program
 
42
  for(y1=0;y1<b->y;y1++)         // brute force
 
43
  for(x2=0;x2<b->x;x2++)
 
44
  for(y2=y1+1;y2<b->y;y2++)
 
45
  {
 
46
    if( get_line2(x1,y1,x2,y2,b,cs,100)>99 )
 
47
    {  // line ???
 
48
      l=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);  // len
 
49
      for(i=0;i<MAXL;i++)
 
50
      {  // remove similar lines (same middle point) IMPROVE IT !!!!!! ???
 
51
        if(
 
52
            abs(x1+x2-xa[i]-xb[i])<1+b->x/2
 
53
         && abs(y1+y2-ya[i]-yb[i])<1+b->y/2
 
54
         && abs(y1-ya[i])<1+b->y/4
 
55
         && abs(x1-xa[i])<1+b->x/4
 
56
          )
 
57
        {
 
58
          if( l>ll[i] )
 
59
          {
 
60
            for(j=i;j<MAXL-1;j++)
 
61
            {  // shift table
 
62
              xa[j]=xa[j+1];ya[j]=ya[j+1];
 
63
              xb[j]=xb[j+1];yb[j]=yb[j+1];ll[j]=ll[j+1];
 
64
            }
 
65
            ll[MAXL-1]=0;
 
66
          }
 
67
          else break; // forget it if shorter
 
68
        }
 
69
        if( l>ll[i] ){ // insert if larger
 
70
          for(j=MAXL-1;j>i;j--){  // shift table
 
71
            xa[j]=xa[j-1];ya[j]=ya[j-1];
 
72
            xb[j]=xb[j-1];yb[j]=yb[j-1];ll[j]=ll[j-1];
 
73
          }
 
74
          xa[i]=x1;ya[i]=y1;xb[i]=x2;yb[i]=y2;ll[i]=l;
 
75
          break;
 
76
        }
 
77
      }
 
78
    }
 
79
  }
 
80
  for(i=0;i<MAXL;i++){
 
81
    printf(" %2d %2d %2d %2d %3d\n",xa[i],ya[i],xb[i],yb[i],ll[i]);
 
82
  }  
 
83
}
 
84