tesseract  5.0.0-alpha-619-ge9db
mf.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: mf.c
3  ** Purpose: Micro-feature interface to flexible feature extractor.
4  ** Author: Dan Johnson
5  ** History: Thu May 24 09:08:38 1990, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 /*----------------------------------------------------------------------------
19  Include Files and Type Defines
20 ----------------------------------------------------------------------------*/
21 #include "mf.h"
22 
23 #include "featdefs.h"
24 #include "mfdefs.h"
25 #include "mfx.h"
26 
27 #include <cmath>
28 
29 /*----------------------------------------------------------------------------
30  Global Data Definitions and Declarations
31 ----------------------------------------------------------------------------*/
32 /*----------------------------------------------------------------------------
33  Private Code
34 ----------------------------------------------------------------------------*/
43 FEATURE_SET ExtractMicros(TBLOB* Blob, const DENORM& cn_denorm) {
44  int NumFeatures;
45  MICROFEATURES Features, OldFeatures;
46  FEATURE_SET FeatureSet;
47  FEATURE Feature;
48  MICROFEATURE OldFeature;
49 
50  OldFeatures = BlobMicroFeatures(Blob, cn_denorm);
51  if (OldFeatures == nullptr)
52  return nullptr;
53  NumFeatures = count (OldFeatures);
54  FeatureSet = NewFeatureSet (NumFeatures);
55 
56  Features = OldFeatures;
57  iterate(Features) {
58  OldFeature = reinterpret_cast<MICROFEATURE>first_node (Features);
59  Feature = NewFeature (&MicroFeatureDesc);
60  Feature->Params[MFDirection] = OldFeature[ORIENTATION];
61  Feature->Params[MFXPosition] = OldFeature[XPOSITION];
62  Feature->Params[MFYPosition] = OldFeature[YPOSITION];
63  Feature->Params[MFLength] = OldFeature[MFLENGTH];
64 
65  // Bulge features are deprecated and should not be used. Set to 0.
66  Feature->Params[MFBulge1] = 0.0f;
67  Feature->Params[MFBulge2] = 0.0f;
68 
69 #ifndef _WIN32
70  // Assert that feature parameters are well defined.
71  int i;
72  for (i = 0; i < Feature->Type->NumParams; i++) {
73  ASSERT_HOST(!std::isnan(Feature->Params[i]));
74  }
75 #endif
76 
77  AddFeature(FeatureSet, Feature);
78  }
79  FreeMicroFeatures(OldFeatures);
80  return FeatureSet;
81 } /* ExtractMicros */
mfx.h
mfdefs.h
MFBulge1
Definition: mf.h:42
AddFeature
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:39
ExtractMicros
FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mf.cpp:43
first_node
#define first_node(l)
Definition: oldlist.h:84
ASSERT_HOST
#define ASSERT_HOST(x)
Definition: errcode.h:87
list_rec
Definition: oldlist.h:73
FreeMicroFeatures
void FreeMicroFeatures(MICROFEATURES MicroFeatures)
Definition: mfdefs.cpp:41
mf.h
FEATURE_STRUCT
Definition: ocrfeatures.h:58
XPOSITION
#define XPOSITION
Definition: mfdefs.h:35
MFXPosition
Definition: mf.h:41
ORIENTATION
#define ORIENTATION
Definition: mfdefs.h:38
FEATURE_DESC_STRUCT::NumParams
uint16_t NumParams
Definition: ocrfeatures.h:52
MFBulge2
Definition: mf.h:42
MFLength
Definition: mf.h:42
FEATURE_STRUCT::Params
float Params[1]
Definition: ocrfeatures.h:60
FEATURE_STRUCT::Type
const FEATURE_DESC_STRUCT * Type
Definition: ocrfeatures.h:59
MicroFeatureDesc
const FEATURE_DESC_STRUCT MicroFeatureDesc
NewFeature
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc)
Definition: ocrfeatures.cpp:77
FEATURE_SET_STRUCT
Definition: ocrfeatures.h:64
YPOSITION
#define YPOSITION
Definition: mfdefs.h:36
NewFeatureSet
FEATURE_SET NewFeatureSet(int NumFeatures)
Definition: ocrfeatures.cpp:93
count
int count(LIST var_list)
Definition: oldlist.cpp:79
TBLOB
Definition: blobs.h:282
featdefs.h
iterate
#define iterate(l)
Definition: oldlist.h:92
BlobMicroFeatures
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mfx.cpp:60
MFDirection
Definition: mf.h:42
MFYPosition
Definition: mf.h:41
MFLENGTH
#define MFLENGTH
Definition: mfdefs.h:37
MICROFEATURE
float * MICROFEATURE
Definition: mfdefs.h:32
DENORM
Definition: normalis.h:49