2007-03-08 04:03:40 +08:00
|
|
|
/******************************************************************************
|
2016-11-08 02:46:33 +08:00
|
|
|
** Filename: intmatcher.h
|
|
|
|
** Purpose: Interface to high level generic classifier routines.
|
|
|
|
** Author: Robert Moss
|
|
|
|
** History: Wed Feb 13 15:24:15 MST 1991, RWM, Created.
|
2007-03-08 04:03:40 +08:00
|
|
|
**
|
2016-11-08 02:46:33 +08:00
|
|
|
** (c) Copyright Hewlett-Packard Company, 1988.
|
2007-03-08 04:03:40 +08:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef INTMATCHER_H
|
|
|
|
#define INTMATCHER_H
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "params.h"
|
2009-07-11 10:17:36 +08:00
|
|
|
|
|
|
|
// Character fragments could be present in the trained templaes
|
|
|
|
// but turned on/off on the language-by-language basis or depending
|
|
|
|
// on particular properties of the corpus (e.g. when we expect the
|
|
|
|
// images to have low exposure).
|
|
|
|
extern BOOL_VAR_H(disable_character_fragments, FALSE,
|
|
|
|
"Do not include character fragments in the"
|
|
|
|
" results of the classifier");
|
|
|
|
|
2013-09-23 23:15:06 +08:00
|
|
|
extern INT_VAR_H(classify_integer_matcher_multiplier, 10,
|
2009-07-11 10:17:36 +08:00
|
|
|
"Integer Matcher Multiplier 0-255: ");
|
|
|
|
|
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
/**----------------------------------------------------------------------------
|
|
|
|
Include Files and Type Defines
|
|
|
|
----------------------------------------------------------------------------**/
|
|
|
|
#include "intproto.h"
|
|
|
|
#include "cutoffs.h"
|
|
|
|
|
2015-05-13 08:24:34 +08:00
|
|
|
namespace tesseract {
|
2015-07-10 02:45:29 +08:00
|
|
|
struct UnicharRating;
|
2015-05-13 08:24:34 +08:00
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
struct CP_RESULT_STRUCT {
|
2014-01-28 07:48:54 +08:00
|
|
|
CP_RESULT_STRUCT() : Rating(0.0f), Class(0) {}
|
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
FLOAT32 Rating;
|
|
|
|
CLASS_ID Class;
|
2010-11-24 02:34:14 +08:00
|
|
|
};
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
Variables
|
|
|
|
-----------------------------------------------------------------------------*/
|
2009-07-11 10:17:36 +08:00
|
|
|
|
|
|
|
extern INT_VAR_H(classify_adapt_proto_thresh, 230,
|
|
|
|
"Threshold for good protos during adaptive 0-255: ");
|
|
|
|
|
|
|
|
extern INT_VAR_H(classify_adapt_feature_thresh, 230,
|
|
|
|
"Threshold for good features during adaptive 0-255: ");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/**----------------------------------------------------------------------------
|
|
|
|
Public Function Prototypes
|
|
|
|
----------------------------------------------------------------------------**/
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
#define SE_TABLE_BITS 9
|
|
|
|
#define SE_TABLE_SIZE 512
|
|
|
|
|
|
|
|
struct ScratchEvidence {
|
|
|
|
uinT8 feature_evidence_[MAX_NUM_CONFIGS];
|
|
|
|
int sum_feature_evidence_[MAX_NUM_CONFIGS];
|
|
|
|
uinT8 proto_evidence_[MAX_NUM_PROTOS][MAX_PROTO_INDEX];
|
|
|
|
|
|
|
|
void Clear(const INT_CLASS class_template);
|
|
|
|
void ClearFeatureEvidence(const INT_CLASS class_template);
|
|
|
|
void NormalizeSums(INT_CLASS ClassTemplate, inT16 NumFeatures,
|
|
|
|
inT32 used_features);
|
|
|
|
void UpdateSumOfProtoEvidences(
|
|
|
|
INT_CLASS ClassTemplate, BIT_VECTOR ConfigMask, inT16 NumFeatures);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IntegerMatcher {
|
|
|
|
public:
|
|
|
|
// Integer Matcher Theta Fudge (0-255).
|
|
|
|
static const int kIntThetaFudge = 128;
|
|
|
|
// Bits in Similarity to Evidence Lookup (8-9).
|
|
|
|
static const int kEvidenceTableBits = 9;
|
|
|
|
// Integer Evidence Truncation Bits (8-14).
|
|
|
|
static const int kIntEvidenceTruncBits = 14;
|
|
|
|
// Similarity to Evidence Table Exponential Multiplier.
|
|
|
|
static const float kSEExponentialMultiplier;
|
|
|
|
// Center of Similarity Curve.
|
|
|
|
static const float kSimilarityCenter;
|
|
|
|
|
|
|
|
IntegerMatcher() : classify_debug_level_(0) {}
|
|
|
|
|
2013-11-09 04:30:56 +08:00
|
|
|
void Init(tesseract::IntParam *classify_debug_level);
|
2010-11-24 02:34:14 +08:00
|
|
|
|
|
|
|
void Match(INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
inT16 NumFeatures,
|
2012-02-02 10:57:42 +08:00
|
|
|
const INT_FEATURE_STRUCT* Features,
|
2015-05-13 08:24:34 +08:00
|
|
|
tesseract::UnicharRating* Result,
|
2010-11-24 02:34:14 +08:00
|
|
|
int AdaptFeatureThreshold,
|
|
|
|
int Debug,
|
|
|
|
bool SeparateDebugWindows);
|
|
|
|
|
2012-02-02 10:57:42 +08:00
|
|
|
// Applies the CN normalization factor to the given rating and returns
|
|
|
|
// the modified rating.
|
|
|
|
float ApplyCNCorrection(float rating, int blob_length,
|
2013-11-09 04:30:56 +08:00
|
|
|
int normalization_factor, int matcher_multiplier);
|
2012-02-02 10:57:42 +08:00
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
int FindGoodProtos(INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
uinT16 BlobLength,
|
|
|
|
inT16 NumFeatures,
|
|
|
|
INT_FEATURE_ARRAY Features,
|
|
|
|
PROTO_ID *ProtoArray,
|
|
|
|
int AdaptProtoThreshold,
|
|
|
|
int Debug);
|
|
|
|
|
|
|
|
int FindBadFeatures(INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
uinT16 BlobLength,
|
|
|
|
inT16 NumFeatures,
|
|
|
|
INT_FEATURE_ARRAY Features,
|
|
|
|
FEATURE_ID *FeatureArray,
|
|
|
|
int AdaptFeatureThreshold,
|
|
|
|
int Debug);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int UpdateTablesForFeature(
|
|
|
|
INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
int FeatureNum,
|
2012-02-02 10:57:42 +08:00
|
|
|
const INT_FEATURE_STRUCT* Feature,
|
2010-11-24 02:34:14 +08:00
|
|
|
ScratchEvidence *evidence,
|
|
|
|
int Debug);
|
|
|
|
|
|
|
|
int FindBestMatch(INT_CLASS ClassTemplate,
|
|
|
|
const ScratchEvidence &tables,
|
2015-05-13 08:24:34 +08:00
|
|
|
tesseract::UnicharRating* Result);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
#ifndef GRAPHICS_DISABLED
|
|
|
|
void DebugFeatureProtoError(
|
|
|
|
INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
const ScratchEvidence &tables,
|
|
|
|
inT16 NumFeatures,
|
|
|
|
int Debug);
|
|
|
|
|
|
|
|
void DisplayProtoDebugInfo(
|
|
|
|
INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
const ScratchEvidence &tables,
|
|
|
|
bool SeparateDebugWindows);
|
|
|
|
|
|
|
|
void DisplayFeatureDebugInfo(
|
|
|
|
INT_CLASS ClassTemplate,
|
|
|
|
BIT_VECTOR ProtoMask,
|
|
|
|
BIT_VECTOR ConfigMask,
|
|
|
|
inT16 NumFeatures,
|
2012-02-02 10:57:42 +08:00
|
|
|
const INT_FEATURE_STRUCT* Features,
|
2010-11-24 02:34:14 +08:00
|
|
|
int AdaptFeatureThreshold,
|
|
|
|
int Debug,
|
|
|
|
bool SeparateDebugWindows);
|
|
|
|
#endif
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
private:
|
|
|
|
uinT8 similarity_evidence_table_[SE_TABLE_SIZE];
|
|
|
|
uinT32 evidence_table_mask_;
|
|
|
|
uinT32 mult_trunc_shift_bits_;
|
|
|
|
uinT32 table_trunc_shift_bits_;
|
|
|
|
tesseract::IntParam *classify_debug_level_;
|
|
|
|
uinT32 evidence_mult_mask_;
|
|
|
|
};
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/**----------------------------------------------------------------------------
|
|
|
|
Private Function Prototypes
|
|
|
|
----------------------------------------------------------------------------**/
|
|
|
|
void IMDebugConfiguration(INT_FEATURE FeatureNum,
|
2008-04-22 08:23:04 +08:00
|
|
|
uinT16 ActualProtoNum,
|
|
|
|
uinT8 Evidence,
|
2007-03-08 04:03:40 +08:00
|
|
|
BIT_VECTOR ConfigMask,
|
2008-04-22 08:23:04 +08:00
|
|
|
uinT32 ConfigWord);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
void IMDebugConfigurationSum(INT_FEATURE FeatureNum,
|
2008-04-22 08:23:04 +08:00
|
|
|
uinT8 *FeatureEvidence,
|
|
|
|
inT32 ConfigCount);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2008-02-01 08:07:59 +08:00
|
|
|
void HeapSort (int n, register int ra[], register int rb[]);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
/**----------------------------------------------------------------------------
|
|
|
|
Global Data Definitions and Declarations
|
|
|
|
----------------------------------------------------------------------------**/
|
|
|
|
#endif
|