reference/ocr-simple/testocr.cc
author viric@llimona
Thu, 18 May 2006 23:12:51 +0200
changeset 0 6b8091ca909a
permissions -rw-r--r--
Init from working directory of svn repository.

#include "system.h"
#include "Page.h"
#include <cstdlib>
#include <iostream.h>
#include "tcl_interface.h"

void draw_bitmap(int x, int y, char * xbmfile);
/* int docommand(char* fmt, ...); */

void testocr(int argc, char ** argv)
/*** Just some test stuff for right now ***/
{
  Page * hello = new Page;
  hello->readMap("hello.tif");

  cout << "Test PixelsInRegion Functions"<< endl; 
   // This test has ranges appropriate for hello.tif    
  testPixelsInRegion(hello->bmap(), hello->rmap());  
  cout << endl;

  cout << "Now test grayscale" << endl;
  cout << "NumPixels in Region (3,5) .. (52,19) ";
  cout << hello->bmap()->pixelsInRegion(Point(3,5), Point(52,19)) << endl;
  cout << "  Area: " << (52 -3 +1)*(19-5+1) << endl;
  cout << "  GrayScale: ";
  cout <<  hello->bmap()->grayScale(Point(3, 5), Point(52,19)) << endl;

  cout << endl << "Now lets look at the property vector for this region" << endl;
  Component* c = new Component(Point(3, 5),Point(52,19));
  testProperties(c, hello->bmap());
  hello->bmap()->writeTclMap("hello",Point(0,0),Point(0,0),0);

  cout << "Now some testing with pagebw.tif " << endl;
  testLearn();  
  Page * testPage;
  testPage = new Page;
  cout << "reading map" << endl;
  testPage->readMap("/amd/nfs/cochise/home/ee/cs169/fa95/class/cs169-ab/bigtiff.tif");
  NoiseTolerance = 10;
  cout << "Finding the lines." << endl;
  testPage->setLines();
  
  if ((argc > 2) && !(strcmp(argv[2],"-ugly")));
  else
      {
	docommand(".t.f.c create bitmap 637 825 -bitmap @/amd/nfs/cochise/home/ee/cs169/fa95/class/cs169-ab/tif/pagebw");
	docommand("update");

	int centerline, width;
	for(int j=0; j < testPage->fnumLines; j++)
	  {
	    centerline = (testPage->flineinfo[j].fendrow + testPage->flineinfo[j + 1].fstartrow) / 2;
	    width = testPage->flineinfo[j + 1].fstartrow - testPage->flineinfo[j].fendrow;
	    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);
	    update();
	  }
	for(int i= 0; i < 500; i++)
	  {
	    update();
	  }
      }

  testPage->extractComponents();
  cout << "avgSpacing - " << testPage->avgSpacing() << endl;

//  testPage->printComponents();


    testPage->recognize();
    testPage->extractWords();
    testPage->printWords();
     delete testPage;
     delete hello;

}















void testExtractAndMerge()
{
  Page * testPage = new Page;
  RLEMap * newMap = new RLEMap;

  testPage->readMap("train.tif");
  testPage->rmap()->printPairs(142,145);
  RLEPairs * p = testPage->rmap()->row(144)->extract(504, 520);
  testPage->rmap()->row(143)->merge(p);
  testPage->rmap()->printPairs(142,145);
  testPage->setLines();
  testPage->extractComponents();
  testPage->printComponents();

}