提交 47cd8b55 编写于 作者: T theraysmith

Changed classifier debug mode to allow debug on any Unicode character.

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@80 d0cd1f9f-072b-0410-8dd7-cf729c803f20
上级 2f4a43b4
...@@ -26,12 +26,16 @@ ...@@ -26,12 +26,16 @@
#include "const.h" #include "const.h"
#include "ndminx.h" #include "ndminx.h"
#include "adaptmatch.h" #include "adaptmatch.h"
#include "globals.h"
//extern GetPicoFeatureLength(); //extern GetPicoFeatureLength();
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#ifdef __UNIX__
#include <unistd.h>
#endif
/* match debug display constants*/ /* match debug display constants*/
#define DISPLAY_OFFSET (0.5 * INT_CHAR_NORM_RANGE) #define DISPLAY_OFFSET (0.5 * INT_CHAR_NORM_RANGE)
...@@ -631,7 +635,8 @@ void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) { ...@@ -631,7 +635,8 @@ void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) {
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos) { INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos,
const UNICHARSET& target_unicharset) {
/* /*
** Parameters: ** Parameters:
** FloatProtos prototypes in old floating pt format ** FloatProtos prototypes in old floating pt format
...@@ -651,11 +656,10 @@ INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos) { ...@@ -651,11 +656,10 @@ INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos) {
IntTemplates = NewIntTemplates (); IntTemplates = NewIntTemplates ();
for (ClassId = 0; ClassId < NUMBER_OF_CLASSES; ClassId++) { for (ClassId = 0; ClassId < target_unicharset.size(); ClassId++) {
FClass = &(FloatProtos[ClassId]); FClass = &(FloatProtos[ClassId]);
if (NumProtosIn (FClass) > 0) { if (NumProtosIn (FClass) > 0) {
assert (UnusedClassIdIn (IntTemplates, ClassId)); assert (UnusedClassIdIn (IntTemplates, ClassId));
IClass = NewIntClass (NumProtosIn (FClass), NumConfigsIn (FClass)); IClass = NewIntClass (NumProtosIn (FClass), NumConfigsIn (FClass));
AddIntClass(IntTemplates, ClassId, IClass); AddIntClass(IntTemplates, ClassId, IClass);
...@@ -867,6 +871,7 @@ INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) { ...@@ -867,6 +871,7 @@ INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) {
*/ */
int i, j, x, y, z; int i, j, x, y, z;
int nread; int nread;
int unicharset_size;
INT_TEMPLATES Templates; INT_TEMPLATES Templates;
CLASS_PRUNER Pruner; CLASS_PRUNER Pruner;
INT_CLASS Class; INT_CLASS Class;
...@@ -876,30 +881,38 @@ INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) { ...@@ -876,30 +881,38 @@ INT_TEMPLATES ReadIntTemplates(FILE *File, BOOL8 swap) {
/* first read the high level template struct */ /* first read the high level template struct */
Templates = NewIntTemplates (); Templates = NewIntTemplates ();
// Read Templates in parts for 64 bit compatibility. // Read Templates in parts for 64 bit compatibility.
if (fread(&unicharset_size, sizeof(int), 1, File) != 1)
cprintf ("Bad read of inttemp!\n");
if (fread(&Templates->NumClasses, sizeof(int), 1, File) != 1 || if (fread(&Templates->NumClasses, sizeof(int), 1, File) != 1 ||
fread(&Templates->NumClassPruners, sizeof(int), 1, File) != 1) fread(&Templates->NumClassPruners, sizeof(int), 1, File) != 1)
cprintf ("Bad read of inttemp!\n"); cprintf ("Bad read of inttemp!\n");
for (i = 0; i <= MAX_CLASS_ID; ++i) { // Swap status is determined automatically.
swap = Templates->NumClassPruners < 0 ||
Templates->NumClassPruners > MAX_NUM_CLASS_PRUNERS;
if (swap) {
reverse32 (&Templates->NumClassPruners);
reverse32 (&Templates->NumClasses);
reverse32 (&unicharset_size);
}
if (unicharset_size != unicharset.size()) {
cprintf("Error: %d classes in inttemp while "
"unicharset contains %d unichars.\n",
unicharset_size, unicharset.size());
exit(1);
}
for (i = 0; i < unicharset_size; ++i) {
if (fread(&Templates->IndexFor[i], sizeof(CLASS_INDEX), 1, File) != 1) if (fread(&Templates->IndexFor[i], sizeof(CLASS_INDEX), 1, File) != 1)
cprintf("Bad read of inttemp!\n"); cprintf("Bad read of inttemp!\n");
} }
for (i = 0; i < MAX_NUM_CLASSES; ++i) { for (i = 0; i < NumClassesIn (Templates); ++i) {
if (fread(&Templates->ClassIdFor[i], sizeof(CLASS_ID), 1, File) != 1) if (fread(&Templates->ClassIdFor[i], sizeof(CLASS_ID), 1, File) != 1)
cprintf("Bad read of inttemp!\n"); cprintf("Bad read of inttemp!\n");
} }
for (i = 0; i < MAX_NUM_CLASSES + MAX_NUM_CLASS_PRUNERS; ++i) {
int junk;
if (fread(&junk, sizeof(junk), 1, File) != 1)
cprintf("Bad read of inttemp!\n");
}
// Swap status is determined automatically.
swap = Templates->NumClassPruners < 0 ||
Templates->NumClassPruners > MAX_NUM_CLASS_PRUNERS;
if (swap) { if (swap) {
reverse32 (&Templates->NumClassPruners);
reverse32 (&Templates->NumClasses);
for (i = 0; i < MAX_CLASS_ID + 1; i++) for (i = 0; i < MAX_CLASS_ID + 1; i++)
reverse16 (&Templates->IndexFor[i]); reverse16 (&Templates->IndexFor[i]);
for (i = 0; i < MAX_NUM_CLASSES; i++)
reverse32 (&Templates->ClassIdFor[i]);
} }
/* then read in the class pruners */ /* then read in the class pruners */
...@@ -1042,7 +1055,8 @@ void ShowMatchDisplay() { ...@@ -1042,7 +1055,8 @@ void ShowMatchDisplay() {
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates) { void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
const UNICHARSET& target_unicharset) {
/* /*
** Parameters: ** Parameters:
** File open file to write templates to ** File open file to write templates to
...@@ -1057,9 +1071,16 @@ void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates) { ...@@ -1057,9 +1071,16 @@ void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates) {
*/ */
int i, j; int i, j;
INT_CLASS Class; INT_CLASS Class;
int unicharset_size = target_unicharset.size();
/* first write the high level template struct */ /* first write the high level template struct */
fwrite ((char *) Templates, sizeof (INT_TEMPLATES_STRUCT), 1, File); fwrite((char *) &unicharset_size, sizeof (int), 1, File);
fwrite((char *) &Templates->NumClasses, sizeof (int), 1, File);
fwrite((char *) &Templates->NumClassPruners, sizeof (int), 1, File);
fwrite((char *) &Templates->IndexFor[0], sizeof (CLASS_INDEX),
unicharset_size, File);
fwrite((char *) &Templates->ClassIdFor[0], sizeof (CLASS_ID),
NumClassesIn (Templates), File);
/* then write out the class pruners */ /* then write out the class pruners */
for (i = 0; i < NumClassPrunersIn (Templates); i++) for (i = 0; i < NumClassPrunersIn (Templates); i++)
...@@ -1302,8 +1323,31 @@ CLASS_ID GetClassToDebug(const char *Prompt) { ...@@ -1302,8 +1323,31 @@ CLASS_ID GetClassToDebug(const char *Prompt) {
** Exceptions: none ** Exceptions: none
** History: Thu Mar 21 16:55:13 1991, DSJ, Created. ** History: Thu Mar 21 16:55:13 1991, DSJ, Created.
*/ */
return window_wait (IntMatchWindow); char c = 0;
do
c = window_wait(IntMatchWindow);
while (c != 0 && c != '\n');
#ifdef __UNIX__
// Temp sychronization.
if (c == '\n' && input_unicode[0] == 0) {
sleep(1);
}
#endif
char utf8[kInputSize * UNICHAR_LEN];
int offset = 0;
int i;
for (i = 0; i < kInputSize && input_unicode[i] != 0; ++i) {
UNICHAR ch(input_unicode[i]);
int len = ch.utf8_len();
for (int j = 0; j < len; ++j) {
utf8[offset++] = ch.utf8()[j];
}
}
cprintf("unicode len = %d, 1st code=%d, utf8 len = %d, 1st code=%d\n",
i, input_unicode[0], offset, utf8[0]);
input_unicode[0] = 0;
return c == '\n' ? unicharset.unichar_to_id(utf8, offset) : 0;
} /* GetClassToDebug */ } /* GetClassToDebug */
#endif #endif
......
...@@ -36,6 +36,7 @@ void def_overlap_picture_ops(BOOL8 update); ...@@ -36,6 +36,7 @@ void def_overlap_picture_ops(BOOL8 update);
WINCREATEFUNC create_func = WINFD::create; WINCREATEFUNC create_func = WINFD::create;
void (*overlap_func) (BOOL8) = def_overlap_picture_ops; void (*overlap_func) (BOOL8) = def_overlap_picture_ops;
int input_unicode[kInputSize];
/********************************************************************** /**********************************************************************
* line_color_index * line_color_index
...@@ -741,7 +742,7 @@ void WINFD::Destroy_window() { /*destroy a window */ ...@@ -741,7 +742,7 @@ void WINFD::Destroy_window() { /*destroy a window */
return; return;
} }
else { else {
Clear_event_queue(); Clear_event_queue();
sbfds[fd].used = FALSE; /*it is not in use */ sbfds[fd].used = FALSE; /*it is not in use */
sbfds[fd].click_handler = NULL; sbfds[fd].click_handler = NULL;
...@@ -921,7 +922,7 @@ void WINFD::Make_picture_current() { /*update window */ ...@@ -921,7 +922,7 @@ void WINFD::Make_picture_current() { /*update window */
ONEOP *newop; /*message structure */ ONEOP *newop; /*message structure */
if (this == NULL || fd <= 0) { if (this == NULL || fd <= 0) {
overlap_picture_ops(TRUE); overlap_picture_ops(TRUE);
} }
else { else {
/*get some space */ /*get some space */
......
...@@ -76,6 +76,8 @@ BOOL8 moveon, BOOL8 upon, BOOL8 keyon); ...@@ -76,6 +76,8 @@ BOOL8 moveon, BOOL8 upon, BOOL8 keyon);
extern WINCREATEFUNC create_func; extern WINCREATEFUNC create_func;
extern void (*overlap_func) (BOOL8); extern void (*overlap_func) (BOOL8);
extern WINDOW (*await_event_func) (WINDOW, BOOL8, INT8, GRAPHICS_EVENT *); extern WINDOW (*await_event_func) (WINDOW, BOOL8, INT8, GRAPHICS_EVENT *);
const int kInputSize = 16;
extern int input_unicode[kInputSize];
class DLLSYM WINFD class DLLSYM WINFD
{ {
...@@ -182,11 +184,11 @@ class DLLSYM WINFD ...@@ -182,11 +184,11 @@ class DLLSYM WINFD
float rotation, /*rotation of arc */ float rotation, /*rotation of arc */
INT16 close_type); /*type of closure */ INT16 close_type); /*type of closure */
/*destroy a window */ /*destroy a window */
virtual void Destroy_window(); virtual void Destroy_window();
/*clear window */ /*clear window */
virtual void Clear_view_surface(); virtual void Clear_view_surface();
/*Mark need to recalc */ /*Mark need to recalc */
virtual void Re_compute_colourmap(); virtual void Re_compute_colourmap();
virtual void Vdc_extent( /*set window focus */ virtual void Vdc_extent( /*set window focus */
float xmin, /*min values */ float xmin, /*min values */
float ymin, /*min values */ float ymin, /*min values */
...@@ -197,7 +199,7 @@ class DLLSYM WINFD ...@@ -197,7 +199,7 @@ class DLLSYM WINFD
float xorig, /*min values */ float xorig, /*min values */
float yorig); /*min values */ float yorig); /*min values */
/*update window */ /*update window */
virtual void Make_picture_current(); virtual void Make_picture_current();
/*flush output */ /*flush output */
friend void def_overlap_picture_ops(BOOL8 update); /*send make_ */ friend void def_overlap_picture_ops(BOOL8 update); /*send make_ */
/*set line colour */ /*set line colour */
...@@ -224,7 +226,7 @@ class DLLSYM WINFD ...@@ -224,7 +226,7 @@ class DLLSYM WINFD
void Set_click_handler( //set callback function void Set_click_handler( //set callback function
EVENT_HANDLER handler); //handler function EVENT_HANDLER handler); //handler function
/*delete all events */ /*delete all events */
virtual void Clear_event_queue(); virtual void Clear_event_queue();
//internal maintenance functions //internal maintenance functions
friend void add_event( /*add an event */ friend void add_event( /*add an event */
...@@ -244,15 +246,15 @@ class DLLSYM WINFD ...@@ -244,15 +246,15 @@ class DLLSYM WINFD
//callback function //callback function
EVENT_HANDLER destroy_handler; EVENT_HANDLER destroy_handler;
private: private:
void get_lock() { void get_lock() {
} //wait for lock } //wait for lock
void get_lock_for_draw() { void get_lock_for_draw() {
} //kill draw thread } //kill draw thread
void release_lock() { void release_lock() {
} //let it go } //let it go
void get_core_lock() { void get_core_lock() {
} //wait for lock } //wait for lock
void release_core_lock() { void release_core_lock() {
} //let it go } //let it go
INT16 fd; //"file descriptor" INT16 fd; //"file descriptor"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册