tesseract v5.3.3.20231005
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 **
6 ** (c) Copyright Hewlett-Packard Company, 1988.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 ******************************************************************************/
17/*----------------------------------------------------------------------------
18 Include Files and Type Defines
19----------------------------------------------------------------------------*/
20#include "mf.h"
21
22#include "featdefs.h"
23#include "mfdefs.h"
24#include "mfx.h"
25
26#include <cmath>
27
28namespace tesseract {
29
30/*----------------------------------------------------------------------------
31 Private Code
32----------------------------------------------------------------------------*/
41FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm) {
42 auto features = BlobMicroFeatures(Blob, cn_denorm);
43 if (features.empty()) {
44 return nullptr;
45 }
46 int n = 0;
47 for ([[maybe_unused]] auto &f: features) {
48 ++n;
49 }
50 auto FeatureSet = new FEATURE_SET_STRUCT(n);
51
52 for (auto &f : features) {
53 auto Feature = new FEATURE_STRUCT(&MicroFeatureDesc);
54 for (int i = 0; i < (int)MicroFeatureParameter::MFCount; ++i)
55 Feature->Params[i] = f[i];
56 // Bulge features are deprecated and should not be used. Set to 0.
57 Feature->Params[(int)MicroFeatureParameter::MFBulge1] = 0.0f;
58 Feature->Params[(int)MicroFeatureParameter::MFBulge2] = 0.0f;
59
60#ifndef _WIN32
61 // Assert that feature parameters are well defined.
62 for (int i = 0; i < Feature->Type->NumParams; i++) {
63 ASSERT_HOST(!std::isnan(Feature->Params[i]));
64 }
65#endif
66
67 AddFeature(FeatureSet, Feature);
68 }
69 return FeatureSet;
70} /* ExtractMicros */
71
72} // namespace tesseract
#define ASSERT_HOST(x)
Definition: errcode.h:54
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mfx.cpp:54
FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm)
Definition: mf.cpp:41
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature)
Definition: ocrfeatures.cpp:40
const FEATURE_DESC_STRUCT MicroFeatureDesc