Tesseract  3.02
tesseract-ocr/classify/cutoffs.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    cutoffs.c
00003  **     Purpose:     Routines to manipulate an array of class cutoffs.
00004  **     Author:      Dan Johnson
00005  **     History:     Wed Feb 20 09:28:51 1991, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  ******************************************************************************/
00021 #include "cutoffs.h"
00022 
00023 #include <stdio.h>
00024 
00025 #include "classify.h"
00026 #include "efio.h"
00027 #include "globals.h"
00028 #include "helpers.h"
00029 #include "scanutils.h"
00030 #include "serialis.h"
00031 #include "unichar.h"
00032 
00033 #define REALLY_QUOTE_IT(x) QUOTE_IT(x)
00034 
00035 #define MAX_CUTOFF      1000
00036 
00040 /*---------------------------------------------------------------------------*/
00041 namespace tesseract {
00042 void Classify::ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset,
00043                               CLASS_CUTOFF_ARRAY Cutoffs) {
00044 /*
00045  **     Parameters:
00046  **             Filename        name of file containing cutoff definitions
00047  **             Cutoffs         array to put cutoffs into
00048  **     Globals: none
00049  **     Operation: Open Filename, read in all of the class-id/cutoff pairs
00050  **             and insert them into the Cutoffs array.  Cutoffs are
00051  **             indexed in the array by class id.  Unused entries in the
00052  **             array are set to an arbitrarily high cutoff value.
00053  **     Return: none
00054  **     Exceptions: none
00055  **     History: Wed Feb 20 09:38:26 1991, DSJ, Created.
00056  */
00057   char Class[UNICHAR_LEN + 1];
00058   CLASS_ID ClassId;
00059   int Cutoff;
00060   int i;
00061 
00062   if (shape_table_ != NULL) {
00063     if (!shapetable_cutoffs_.DeSerialize(swap, CutoffFile)) {
00064       tprintf("Error during read of shapetable pffmtable!\n");
00065     }
00066   }
00067   for (i = 0; i < MAX_NUM_CLASSES; i++)
00068     Cutoffs[i] = MAX_CUTOFF;
00069 
00070   while ((end_offset < 0 || ftell(CutoffFile) < end_offset) &&
00071          fscanf(CutoffFile, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d",
00072                 Class, &Cutoff) == 2) {
00073     if (strcmp(Class, "NULL") == 0) {
00074       ClassId = unicharset.unichar_to_id(" ");
00075     } else {
00076       ClassId = unicharset.unichar_to_id(Class);
00077     }
00078     Cutoffs[ClassId] = Cutoff;
00079     SkipNewline(CutoffFile);
00080   }
00081 }                                /* ReadNewCutoffs */
00082 
00083 }  // namespace tesseract