reference/ocr-new/main.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 <tcl.h>
#include <tk.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "system.h"
#include "Page.h"
#include "tcl_interface.h"


#define QUIT 0
#define PAUSE 0

/*

Creates a tcl interpereter, link variable capabilities,
and "docommand" function--Thanks to: Keiji Kanazawa

To execute a line in tcl:  (set x 4)

docommand("set x 4");

also

docommand("set x %d", 4);  

or

docommand("set %s %d", "x", 4);   this might not work ("x" on the stack) 

started 10/95 Archie Russell

*/



Tcl_Interp* TCL_ip;
Tk_Window main_window;

Page* global_page = new ZonedPage;
Page* active_page= NULL;
Page* zoned_page = NULL;

int
main(int argc, char** argv)
{
  initialize_interpreter();
  initialize_command_procs();
  initialize_link_vars();
  if(ENABLE_USER_INTERFACE)
      {
	load_user_interface();
      }

  Page * testPage;
  int return_code;
  testPage = new Page;
  if(ENABLE_USER_INTERFACE)
    readLearnFiles();
  else
    {
      if(argc == 3 && strcmp(argv[2], "nolearn") == 0)
	readLearnedGroups("learnedGroups.dat");
      else
	{
	  learn("train.tif", "train.txt",0);
	  learn("4.header.tif", "4.header.txt",1);
	  learn("4.col0.tif", "4.col0.txt", 1);
	  writeLearnedGroups("learnedGroups.dat");
	}
    }
  if(!ENABLE_USER_INTERFACE) {
    testPage->readMap(argv[1]);
    testPage->deskew(0);
    testPage->setLines();
    testPage->extractComponents(MinHorizSeparation);
    testPage->recognize();
    testPage->extractWords();
    testPage->printComponents();
    testPage->writeWordPos("wordpos.out");
    testPage->writeWordbox("wordbox.out",0,0,0);
    testPage->writeAscii("ascii.out");
    testPage->addEquation(2 , 200, 4, 100);
    printf(" in eqn ? %d",testPage->inEquation(450, 105));    
    printf (" deleted? %d", testPage->deleteEquation(400, 100)); // deletes equation with this coordinate.
    delete testPage;
  }  
  if(ENABLE_USER_INTERFACE)
  while(1)
      {
	  Tk_DoOneEvent(TK_ALL_EVENTS);
      }

  exit(0);
}