mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-07 18:02:40 +08:00
doxygen classify/clusttool.cpp
This commit is contained in:
parent
40fc4154ab
commit
6e4165c0dc
@ -26,23 +26,20 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
//---------------Global Data Definitions and Declarations--------------------
|
//---------------Global Data Definitions and Declarations--------------------
|
||||||
#define TOKENSIZE 80 //max size of tokens read from an input file
|
#define TOKENSIZE 80 //< max size of tokens read from an input file
|
||||||
#define MAXSAMPLESIZE 65535 //max num of dimensions in feature space
|
#define MAXSAMPLESIZE 65535 //< max num of dimensions in feature space
|
||||||
//#define MAXBLOCKSIZE 65535 //max num of samples in a character (block size)
|
//#define MAXBLOCKSIZE 65535 //< max num of samples in a character (block size)
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/**
|
||||||
Public Code
|
* This routine reads a single integer from the specified
|
||||||
-----------------------------------------------------------------------------*/
|
* file and checks to ensure that it is between 0 and
|
||||||
/** ReadSampleSize ***********************************************************
|
* MAXSAMPLESIZE.
|
||||||
Parameters: File open text file to read sample size from
|
* @param File open text file to read sample size from
|
||||||
Globals: None
|
* @return Sample size
|
||||||
Operation: This routine reads a single integer from the specified
|
* @note Globals: None
|
||||||
file and checks to ensure that it is between 0 and
|
* @note Exceptions: ILLEGALSAMPLESIZE illegal format or range
|
||||||
MAXSAMPLESIZE.
|
* @note History: 6/6/89, DSJ, Created.
|
||||||
Return: Sample size
|
*/
|
||||||
Exceptions: ILLEGALSAMPLESIZE illegal format or range
|
|
||||||
History: 6/6/89, DSJ, Created.
|
|
||||||
******************************************************************************/
|
|
||||||
uinT16 ReadSampleSize(FILE *File) {
|
uinT16 ReadSampleSize(FILE *File) {
|
||||||
int SampleSize;
|
int SampleSize;
|
||||||
|
|
||||||
@ -50,21 +47,22 @@ uinT16 ReadSampleSize(FILE *File) {
|
|||||||
(SampleSize < 0) || (SampleSize > MAXSAMPLESIZE))
|
(SampleSize < 0) || (SampleSize > MAXSAMPLESIZE))
|
||||||
DoError (ILLEGALSAMPLESIZE, "Illegal sample size");
|
DoError (ILLEGALSAMPLESIZE, "Illegal sample size");
|
||||||
return (SampleSize);
|
return (SampleSize);
|
||||||
} // ReadSampleSize
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** ReadParamDesc *************************************************************
|
* This routine reads textual descriptions of sets of parameters
|
||||||
Parameters: File open text file to read N parameter descriptions from
|
* which describe the characteristics of feature dimensions.
|
||||||
N number of parameter descriptions to read
|
*
|
||||||
Globals: None
|
* Exceptions:
|
||||||
Operation: This routine reads textual descriptions of sets of parameters
|
* - ILLEGALCIRCULARSPEC
|
||||||
which describe the characteristics of feature dimensions.
|
* - ILLEGALESSENTIALSPEC
|
||||||
Return: Pointer to an array of parameter descriptors.
|
* - ILLEGALMINMAXSPEC
|
||||||
Exceptions: ILLEGALCIRCULARSPEC
|
* @param File open text file to read N parameter descriptions from
|
||||||
ILLEGALESSENTIALSPEC
|
* @param N number of parameter descriptions to read
|
||||||
ILLEGALMINMAXSPEC
|
* @return Pointer to an array of parameter descriptors.
|
||||||
History: 6/6/89, DSJ, Created.
|
* @note Globals: None
|
||||||
******************************************************************************/
|
* @note History: 6/6/89, DSJ, Created.
|
||||||
|
*/
|
||||||
PARAM_DESC *ReadParamDesc(FILE *File, uinT16 N) {
|
PARAM_DESC *ReadParamDesc(FILE *File, uinT16 N) {
|
||||||
int i;
|
int i;
|
||||||
PARAM_DESC *ParamDesc;
|
PARAM_DESC *ParamDesc;
|
||||||
@ -94,23 +92,24 @@ PARAM_DESC *ReadParamDesc(FILE *File, uinT16 N) {
|
|||||||
ParamDesc[i].MidRange = (ParamDesc[i].Max + ParamDesc[i].Min) / 2;
|
ParamDesc[i].MidRange = (ParamDesc[i].Max + ParamDesc[i].Min) / 2;
|
||||||
}
|
}
|
||||||
return (ParamDesc);
|
return (ParamDesc);
|
||||||
} // ReadParamDesc
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** ReadPrototype *************************************************************
|
* This routine reads a textual description of a prototype from
|
||||||
Parameters: File open text file to read prototype from
|
* the specified file.
|
||||||
N number of dimensions used in prototype
|
*
|
||||||
Globals: None
|
* Exceptions:
|
||||||
Operation: This routine reads a textual description of a prototype from
|
* - ILLEGALSIGNIFICANCESPEC
|
||||||
the specified file.
|
* - ILLEGALSAMPLECOUNT
|
||||||
Return: List of prototypes
|
* - ILLEGALMEANSPEC
|
||||||
Exceptions: ILLEGALSIGNIFICANCESPEC
|
* - ILLEGALVARIANCESPEC
|
||||||
ILLEGALSAMPLECOUNT
|
* - ILLEGALDISTRIBUTION
|
||||||
ILLEGALMEANSPEC
|
* @param File open text file to read prototype from
|
||||||
ILLEGALVARIANCESPEC
|
* @param N number of dimensions used in prototype
|
||||||
ILLEGALDISTRIBUTION
|
* @return List of prototypes
|
||||||
History: 6/6/89, DSJ, Created.
|
* @note Globals: None
|
||||||
******************************************************************************/
|
* @note History: 6/6/89, DSJ, Created.
|
||||||
|
*/
|
||||||
PROTOTYPE *ReadPrototype(FILE *File, uinT16 N) {
|
PROTOTYPE *ReadPrototype(FILE *File, uinT16 N) {
|
||||||
char Token[TOKENSIZE];
|
char Token[TOKENSIZE];
|
||||||
int Status;
|
int Status;
|
||||||
@ -228,18 +227,17 @@ PROTOTYPE *ReadPrototype(FILE *File, uinT16 N) {
|
|||||||
DoError (ILLEGALSIGNIFICANCESPEC, "Illegal significance specification");
|
DoError (ILLEGALSIGNIFICANCESPEC, "Illegal significance specification");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
} // ReadPrototype
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/* ReadProtoStyle *************************************************************
|
* This routine reads an single token from the specified
|
||||||
Parameters: File open text file to read prototype style from
|
* text file and interprets it as a prototype specification.
|
||||||
Globals: None
|
* @param File open text file to read prototype style from
|
||||||
Operation: This routine reads an single token from the specified
|
* @return Prototype style read from text file
|
||||||
text file and interprets it as a prototype specification.
|
* @note Globals: None
|
||||||
Return: Prototype style read from text file
|
* @note Exceptions: ILLEGALSTYLESPEC illegal prototype style specification
|
||||||
Exceptions: ILLEGALSTYLESPEC illegal prototype style specification
|
* @note History: 6/8/89, DSJ, Created.
|
||||||
History: 6/8/89, DSJ, Created.
|
*/
|
||||||
*******************************************************************************/
|
|
||||||
PROTOSTYLE ReadProtoStyle(FILE *File) {
|
PROTOSTYLE ReadProtoStyle(FILE *File) {
|
||||||
char Token[TOKENSIZE];
|
char Token[TOKENSIZE];
|
||||||
PROTOSTYLE Style;
|
PROTOSTYLE Style;
|
||||||
@ -264,23 +262,22 @@ PROTOSTYLE ReadProtoStyle(FILE *File) {
|
|||||||
DoError (ILLEGALSTYLESPEC, "Illegal prototype style specification");
|
DoError (ILLEGALSTYLESPEC, "Illegal prototype style specification");
|
||||||
}
|
}
|
||||||
return (Style);
|
return (Style);
|
||||||
} // ReadProtoStyle
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** ReadNFloats *************************************************************
|
* This routine reads N floats from the specified text file
|
||||||
Parameters: File open text file to read floats from
|
* and places them into Buffer. If Buffer is NULL, a buffer
|
||||||
N number of floats to read
|
* is created and passed back to the caller. If EOF is
|
||||||
Buffer pointer to buffer to place floats into
|
* encountered before any floats can be read, NULL is
|
||||||
Globals: None
|
* returned.
|
||||||
Operation: This routine reads N floats from the specified text file
|
* @param File open text file to read floats from
|
||||||
and places them into Buffer. If Buffer is NULL, a buffer
|
* @param N number of floats to read
|
||||||
is created and passed back to the caller. If EOF is
|
* @param Buffer pointer to buffer to place floats into
|
||||||
encountered before any floats can be read, NULL is
|
* @return Pointer to buffer holding floats or NULL if EOF
|
||||||
returned.
|
* @note Globals: None
|
||||||
Return: Pointer to buffer holding floats or NULL if EOF
|
* @note Exceptions: ILLEGALFLOAT
|
||||||
Exceptions: ILLEGALFLOAT
|
* @note History: 6/6/89, DSJ, Created.
|
||||||
History: 6/6/89, DSJ, Created.
|
*/
|
||||||
******************************************************************************/
|
|
||||||
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
|
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
|
||||||
int i;
|
int i;
|
||||||
int NumFloatsRead;
|
int NumFloatsRead;
|
||||||
@ -300,20 +297,19 @@ FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Buffer;
|
return Buffer;
|
||||||
} // ReadNFloats
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** WriteParamDesc ************************************************************
|
* This routine writes an array of dimension descriptors to
|
||||||
Parameters: File open text file to write param descriptors to
|
* the specified text file.
|
||||||
N number of param descriptors to write
|
* @param File open text file to write param descriptors to
|
||||||
ParamDesc array of param descriptors to write
|
* @param N number of param descriptors to write
|
||||||
Globals: None
|
* @param ParamDesc array of param descriptors to write
|
||||||
Operation: This routine writes an array of dimension descriptors to
|
* @return None
|
||||||
the specified text file.
|
* @note Globals: None
|
||||||
Return: None
|
* @note Exceptions: None
|
||||||
Exceptions: None
|
* @note History: 6/6/89, DSJ, Created.
|
||||||
History: 6/6/89, DSJ, Created.
|
*/
|
||||||
******************************************************************************/
|
|
||||||
void
|
void
|
||||||
WriteParamDesc (FILE * File, uinT16 N, PARAM_DESC ParamDesc[]) {
|
WriteParamDesc (FILE * File, uinT16 N, PARAM_DESC ParamDesc[]) {
|
||||||
int i;
|
int i;
|
||||||
@ -331,20 +327,19 @@ WriteParamDesc (FILE * File, uinT16 N, PARAM_DESC ParamDesc[]) {
|
|||||||
|
|
||||||
fprintf (File, "%10.6f %10.6f\n", ParamDesc[i].Min, ParamDesc[i].Max);
|
fprintf (File, "%10.6f %10.6f\n", ParamDesc[i].Min, ParamDesc[i].Max);
|
||||||
}
|
}
|
||||||
} // WriteParamDesc
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** WritePrototype ************************************************************
|
* This routine writes a textual description of a prototype
|
||||||
Parameters: File open text file to write prototype to
|
* to the specified text file.
|
||||||
N number of dimensions in feature space
|
* @param File open text file to write prototype to
|
||||||
Proto prototype to write out
|
* @param N number of dimensions in feature space
|
||||||
Globals: None
|
* @param Proto prototype to write out
|
||||||
Operation: This routine writes a textual description of a prototype
|
* @return None
|
||||||
to the specified text file.
|
* @note Globals: None
|
||||||
Return: None
|
* @note Exceptions: None
|
||||||
Exceptions: None
|
* @note History: 6/12/89, DSJ, Created.
|
||||||
History: 6/12/89, DSJ, Created.
|
*/
|
||||||
*******************************************************************************/
|
|
||||||
void WritePrototype(FILE *File, uinT16 N, PROTOTYPE *Proto) {
|
void WritePrototype(FILE *File, uinT16 N, PROTOTYPE *Proto) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -382,38 +377,36 @@ void WritePrototype(FILE *File, uinT16 N, PROTOTYPE *Proto) {
|
|||||||
fprintf (File, "\n\t");
|
fprintf (File, "\n\t");
|
||||||
WriteNFloats (File, N, Proto->Variance.Elliptical);
|
WriteNFloats (File, N, Proto->Variance.Elliptical);
|
||||||
}
|
}
|
||||||
} // WritePrototype
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** WriteNFloats ***********************************************************
|
* This routine writes a text representation of N floats from
|
||||||
Parameters: File open text file to write N floats to
|
* an array to a file. All of the floats are placed on one line.
|
||||||
N number of floats to write
|
* @param File open text file to write N floats to
|
||||||
Array array of floats to write
|
* @param N number of floats to write
|
||||||
Globals: None
|
* @param Array array of floats to write
|
||||||
Operation: This routine writes a text representation of N floats from
|
* @return None
|
||||||
an array to a file. All of the floats are placed on one line.
|
* @note Globals: None
|
||||||
Return: None
|
* @note Exceptions: None
|
||||||
Exceptions: None
|
* @note History: 6/6/89, DSJ, Created.
|
||||||
History: 6/6/89, DSJ, Created.
|
*/
|
||||||
****************************************************************************/
|
|
||||||
void WriteNFloats(FILE * File, uinT16 N, FLOAT32 Array[]) {
|
void WriteNFloats(FILE * File, uinT16 N, FLOAT32 Array[]) {
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
fprintf(File, " %9.6f", Array[i]);
|
fprintf(File, " %9.6f", Array[i]);
|
||||||
fprintf(File, "\n");
|
fprintf(File, "\n");
|
||||||
} // WriteNFloats
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/** WriteProtoSyle **********************************************************
|
* This routine writes to the specified text file a word
|
||||||
Parameters: File open text file to write prototype style to
|
* which represents the ProtoStyle. It does not append
|
||||||
ProtoStyle prototype style to write
|
* a carriage return to the end.
|
||||||
Globals: None
|
* @param File open text file to write prototype style to
|
||||||
Operation: This routine writes to the specified text file a word
|
* @param ProtoStyle prototype style to write
|
||||||
which represents the ProtoStyle. It does not append
|
* @return None
|
||||||
a carriage return to the end.
|
* @note Globals: None
|
||||||
Return: None
|
* @note Exceptions: None
|
||||||
Exceptions: None
|
* @note History: 6/8/89, DSJ, Created.
|
||||||
History: 6/8/89, DSJ, Created.
|
*/
|
||||||
****************************************************************************/
|
|
||||||
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
|
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
|
||||||
switch (ProtoStyle) {
|
switch (ProtoStyle) {
|
||||||
case spherical:
|
case spherical:
|
||||||
@ -429,9 +422,25 @@ void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
|
|||||||
fprintf (File, "automatic");
|
fprintf (File, "automatic");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} // WriteProtoStyle
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This routine writes a textual description of each prototype
|
||||||
|
* in the prototype list to the specified file. It also
|
||||||
|
* writes a file header which includes the number of dimensions
|
||||||
|
* in feature space and the descriptions for each dimension.
|
||||||
|
* @param File open text file to write prototypes to
|
||||||
|
* @param N number of dimensions in feature space
|
||||||
|
* @param ParamDesc descriptions for each dimension
|
||||||
|
* @param ProtoList list of prototypes to be written
|
||||||
|
* @param WriteSigProtos TRUE to write out significant prototypes
|
||||||
|
* @param WriteInsigProtos TRUE to write out insignificants
|
||||||
|
* @note Globals: None
|
||||||
|
* @return None
|
||||||
|
* @note Exceptions: None
|
||||||
|
* @note History: 6/12/89, DSJ, Created.
|
||||||
|
*/
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
void WriteProtoList(
|
void WriteProtoList(
|
||||||
FILE *File,
|
FILE *File,
|
||||||
uinT16 N,
|
uinT16 N,
|
||||||
@ -439,30 +448,6 @@ void WriteProtoList(
|
|||||||
LIST ProtoList,
|
LIST ProtoList,
|
||||||
BOOL8 WriteSigProtos,
|
BOOL8 WriteSigProtos,
|
||||||
BOOL8 WriteInsigProtos)
|
BOOL8 WriteInsigProtos)
|
||||||
|
|
||||||
/*
|
|
||||||
** Parameters:
|
|
||||||
** File open text file to write prototypes to
|
|
||||||
** N number of dimensions in feature space
|
|
||||||
** ParamDesc descriptions for each dimension
|
|
||||||
** ProtoList list of prototypes to be written
|
|
||||||
** WriteSigProtos TRUE to write out significant prototypes
|
|
||||||
** WriteInsigProtos TRUE to write out insignificants
|
|
||||||
** Globals:
|
|
||||||
** None
|
|
||||||
** Operation:
|
|
||||||
** This routine writes a textual description of each prototype
|
|
||||||
** in the prototype list to the specified file. It also
|
|
||||||
** writes a file header which includes the number of dimensions
|
|
||||||
** in feature space and the descriptions for each dimension.
|
|
||||||
** Return:
|
|
||||||
** None
|
|
||||||
** Exceptions:
|
|
||||||
** None
|
|
||||||
** History:
|
|
||||||
** 6/12/89, DSJ, Created.
|
|
||||||
*/
|
|
||||||
|
|
||||||
{
|
{
|
||||||
PROTOTYPE *Proto;
|
PROTOTYPE *Proto;
|
||||||
|
|
||||||
@ -478,5 +463,4 @@ void WriteProtoList(
|
|||||||
( ! Proto->Significant && WriteInsigProtos ) )
|
( ! Proto->Significant && WriteInsigProtos ) )
|
||||||
WritePrototype( File, N, Proto );
|
WritePrototype( File, N, Proto );
|
||||||
}
|
}
|
||||||
} /* WriteProtoList */
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user