reference/ocr-new/testocr.cc
changeset 0 6b8091ca909a
equal deleted inserted replaced
-1:000000000000 0:6b8091ca909a
       
     1 #include "system.h"
       
     2 #include "Page.h"
       
     3 #include "stdlib.h"
       
     4 #include <iostream.h>
       
     5 #include "tcl_interface.h"
       
     6 
       
     7 void draw_bitmap(int x, int y, char * xbmfile);
       
     8 /* int docommand(char* fmt, ...); */
       
     9 
       
    10 void testocr(int argc, char ** argv)
       
    11 /*** Just some test stuff for right now ***/
       
    12 {
       
    13   Page * hello = new Page;
       
    14   hello->readMap("hello.tif");
       
    15 
       
    16   cout << "Test PixelsInRegion Functions"<< endl; 
       
    17    // This test has ranges appropriate for hello.tif    
       
    18   testPixelsInRegion(hello->bmap(), hello->rmap());  
       
    19   cout << endl;
       
    20 
       
    21   cout << "Now test grayscale" << endl;
       
    22   cout << "NumPixels in Region (3,5) .. (52,19) ";
       
    23   cout << hello->bmap()->pixelsInRegion(Point(3,5), Point(52,19)) << endl;
       
    24   cout << "  Area: " << (52 -3 +1)*(19-5+1) << endl;
       
    25   cout << "  GrayScale: ";
       
    26   cout <<  hello->bmap()->grayScale(Point(3, 5), Point(52,19)) << endl;
       
    27 
       
    28   cout << endl << "Now lets look at the property vector for this region" << endl;
       
    29   Component* c = new Component(Point(3, 5),Point(52,19));
       
    30   testProperties(c, hello->bmap());
       
    31   hello->bmap()->writeTclMap("hello",Point(0,0),Point(0,0),0);
       
    32 
       
    33   cout << "Now some testing with pagebw.tif " << endl;
       
    34   testLearn();  
       
    35   Page * testPage;
       
    36   testPage = new Page;
       
    37   cout << "reading map" << endl;
       
    38   testPage->readMap("/amd/nfs/cochise/home/ee/cs169/fa95/class/cs169-ab/bigtiff.tif");
       
    39   NoiseTolerance = 10;
       
    40   cout << "Finding the lines." << endl;
       
    41   testPage->setLines();
       
    42   
       
    43   if ((argc > 2) && !(strcmp(argv[2],"-ugly")));
       
    44   else
       
    45       {
       
    46 	docommand(".t.f.c create bitmap 637 825 -bitmap @/amd/nfs/cochise/home/ee/cs169/fa95/class/cs169-ab/tif/pagebw");
       
    47 	docommand("update");
       
    48 
       
    49 	int centerline, width;
       
    50 	for(int j=0; j < testPage->fnumLines; j++)
       
    51 	  {
       
    52 	    centerline = (testPage->flineinfo[j].fendrow + testPage->flineinfo[j + 1].fstartrow) / 2;
       
    53 	    width = testPage->flineinfo[j + 1].fstartrow - testPage->flineinfo[j].fendrow;
       
    54 	    docommand(".t.f.c create line %d %d %d %d -width %d -fill blue -tags project_ray -stipple @/usr/sww/share/tclX-7.3a/tkX/3.6a/demos/bitmaps/grey.25", 0, centerline, testPage->bmap()->imageWidth(), centerline, width);
       
    55 	    update();
       
    56 	  }
       
    57 	for(int i= 0; i < 500; i++)
       
    58 	  {
       
    59 	    update();
       
    60 	  }
       
    61       }
       
    62 
       
    63   testPage->extractComponents(MinHorizSeparation);
       
    64   cout << "avgSpacing - " << testPage->avgSpacing() << endl;
       
    65 
       
    66 //  testPage->printComponents();
       
    67 
       
    68 
       
    69     testPage->recognize();
       
    70     testPage->extractWords();
       
    71     testPage->printWords();
       
    72      delete testPage;
       
    73      delete hello;
       
    74 
       
    75 }
       
    76 
       
    77 
       
    78 
       
    79 
       
    80 
       
    81 
       
    82 
       
    83 
       
    84 
       
    85 
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 
       
    91 void testExtractAndMerge()
       
    92 {
       
    93   Page * testPage = new Page;
       
    94   RLEMap * newMap = new RLEMap;
       
    95 
       
    96   testPage->readMap("train.tif");
       
    97   testPage->rmap()->printPairs(142,145);
       
    98   RLEPairs * p = testPage->rmap()->row(144)->extract(504, 520);
       
    99   testPage->rmap()->row(143)->merge(p);
       
   100   testPage->rmap()->printPairs(142,145);
       
   101   testPage->setLines();
       
   102   testPage->extractComponents(MinHorizSeparation);
       
   103   testPage->printComponents();
       
   104 
       
   105 }
       
   106 
       
   107 
       
   108 
       
   109 
       
   110