mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-20 15:59:11 +08:00
Replace microfeatures from oldlist to std::forward_list.
This commit is contained in:
parent
2e17ee7327
commit
47715e576a
@ -39,25 +39,22 @@ namespace tesseract {
|
||||
* @return Micro-features for Blob.
|
||||
*/
|
||||
FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm) {
|
||||
int NumFeatures;
|
||||
MICROFEATURES Features, OldFeatures;
|
||||
MICROFEATURE OldFeature;
|
||||
|
||||
OldFeatures = BlobMicroFeatures(Blob, cn_denorm);
|
||||
if (OldFeatures == nullptr) {
|
||||
auto features = BlobMicroFeatures(Blob, cn_denorm);
|
||||
if (features.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
NumFeatures = count(OldFeatures);
|
||||
auto FeatureSet = new FEATURE_SET_STRUCT(NumFeatures);
|
||||
int n = 0;
|
||||
for (auto &f : features) {
|
||||
++n;
|
||||
}
|
||||
auto FeatureSet = new FEATURE_SET_STRUCT(n);
|
||||
|
||||
Features = OldFeatures;
|
||||
iterate(Features) {
|
||||
OldFeature = reinterpret_cast<MICROFEATURE> first_node(Features);
|
||||
for (auto &f : features) {
|
||||
auto Feature = new FEATURE_STRUCT(&MicroFeatureDesc);
|
||||
Feature->Params[MFDirection] = OldFeature[ORIENTATION];
|
||||
Feature->Params[MFXPosition] = OldFeature[XPOSITION];
|
||||
Feature->Params[MFYPosition] = OldFeature[YPOSITION];
|
||||
Feature->Params[MFLength] = OldFeature[MFLENGTH];
|
||||
Feature->Params[MFDirection] = f[ORIENTATION];
|
||||
Feature->Params[MFXPosition] = f[XPOSITION];
|
||||
Feature->Params[MFYPosition] = f[YPOSITION];
|
||||
Feature->Params[MFLength] = f[MFLENGTH];
|
||||
|
||||
// Bulge features are deprecated and should not be used. Set to 0.
|
||||
Feature->Params[MFBulge1] = 0.0f;
|
||||
@ -73,7 +70,6 @@ FEATURE_SET ExtractMicros(TBLOB *Blob, const DENORM &cn_denorm) {
|
||||
|
||||
AddFeature(FeatureSet, Feature);
|
||||
}
|
||||
FreeMicroFeatures(OldFeatures);
|
||||
return FeatureSet;
|
||||
} /* ExtractMicros */
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
/******************************************************************************
|
||||
** Filename: mfdefs.cpp
|
||||
** Purpose: Basic routines for manipulating micro-features
|
||||
** Author: Dan Johnson
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** 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.
|
||||
******************************************************************************/
|
||||
|
||||
#include "mfdefs.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Public Code
|
||||
----------------------------------------------------------------------------**/
|
||||
|
||||
/**
|
||||
* This routine allocates and returns a new micro-feature
|
||||
* data structure.
|
||||
* @return New MICROFEATURE
|
||||
*/
|
||||
MICROFEATURE NewMicroFeature() {
|
||||
return new MFBLOCK;
|
||||
} /* NewMicroFeature */
|
||||
|
||||
/**
|
||||
* This routine deallocates all of the memory consumed by
|
||||
* a list of micro-features.
|
||||
* @param MicroFeatures list of micro-features to be freed
|
||||
*/
|
||||
void FreeMicroFeatures(MICROFEATURES MicroFeatures) {
|
||||
auto list = MicroFeatures;
|
||||
while (list != NIL_LIST) {
|
||||
delete first_node(list);
|
||||
list = pop(list);
|
||||
}
|
||||
} /* FreeMicroFeatures */
|
||||
|
||||
} // namespace tesseract
|
@ -24,15 +24,15 @@
|
||||
#include "matchdefs.h"
|
||||
#include "oldlist.h"
|
||||
|
||||
#include <array>
|
||||
#include <forward_list>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
/* definition of a list of micro-features */
|
||||
using MICROFEATURES = LIST;
|
||||
|
||||
/* definition of structure of micro-features */
|
||||
#define MFSIZE 6
|
||||
typedef float MFBLOCK[MFSIZE];
|
||||
using MICROFEATURE = float *;
|
||||
using MICROFEATURE = float;
|
||||
using MFBLOCK = std::array<MICROFEATURE, 6>;
|
||||
using MICROFEATURES = std::forward_list<MFBLOCK>;
|
||||
|
||||
/* definitions of individual micro-feature parameters */
|
||||
#define XPOSITION 0
|
||||
@ -42,20 +42,6 @@ using MICROFEATURE = float *;
|
||||
#define FIRSTBULGE 4
|
||||
#define SECONDBULGE 5
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Macros
|
||||
----------------------------------------------------------------------------**/
|
||||
|
||||
/* macros for accessing micro-feature lists */
|
||||
#define NextFeatureOf(L) ((MICROFEATURE)first_node(L))
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
----------------------------------------------------------------------------**/
|
||||
MICROFEATURE NewMicroFeature();
|
||||
|
||||
void FreeMicroFeatures(MICROFEATURES MicroFeatures);
|
||||
|
||||
} // namespace tesseract
|
||||
|
||||
#endif
|
||||
|
@ -36,7 +36,7 @@ double_VAR(classify_max_slope, 2.414213562, "Slope above which lines are called
|
||||
|
||||
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatures);
|
||||
|
||||
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End);
|
||||
MFBLOCK ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Public Code
|
||||
@ -52,7 +52,7 @@ MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End);
|
||||
* @return List of micro-features extracted from the blob.
|
||||
*/
|
||||
MICROFEATURES BlobMicroFeatures(TBLOB *Blob, const DENORM &cn_denorm) {
|
||||
auto MicroFeatures = NIL_LIST;
|
||||
MICROFEATURES MicroFeatures;
|
||||
LIST Outlines;
|
||||
LIST RemainingOutlines;
|
||||
MFOUTLINE Outline;
|
||||
@ -93,7 +93,6 @@ MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatu
|
||||
MFOUTLINE Current;
|
||||
MFOUTLINE Last;
|
||||
MFOUTLINE First;
|
||||
MICROFEATURE NewFeature;
|
||||
|
||||
if (DegenerateOutline(Outline)) {
|
||||
return (MicroFeatures);
|
||||
@ -104,15 +103,13 @@ MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatu
|
||||
do {
|
||||
Current = NextExtremity(Last);
|
||||
if (!PointAt(Current)->Hidden) {
|
||||
NewFeature = ExtractMicroFeature(Last, Current);
|
||||
if (NewFeature != nullptr) {
|
||||
MicroFeatures = push(MicroFeatures, NewFeature);
|
||||
}
|
||||
auto NewFeature = ExtractMicroFeature(Last, Current);
|
||||
MicroFeatures.push_front(NewFeature);
|
||||
}
|
||||
Last = Current;
|
||||
} while (Last != First);
|
||||
|
||||
return (MicroFeatures);
|
||||
return MicroFeatures;
|
||||
} /* ConvertToMicroFeatures */
|
||||
|
||||
/**
|
||||
@ -128,14 +125,13 @@ MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline, MICROFEATURES MicroFeatu
|
||||
* @return New micro-feature or nullptr if the feature was rejected.
|
||||
* @note Globals: none
|
||||
*/
|
||||
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End) {
|
||||
MICROFEATURE NewFeature;
|
||||
MFBLOCK ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End) {
|
||||
MFEDGEPT *P1, *P2;
|
||||
|
||||
P1 = PointAt(Start);
|
||||
P2 = PointAt(End);
|
||||
|
||||
NewFeature = NewMicroFeature();
|
||||
MFBLOCK NewFeature;
|
||||
NewFeature[XPOSITION] = AverageOf(P1->Point.x, P2->Point.x);
|
||||
NewFeature[YPOSITION] = AverageOf(P1->Point.y, P2->Point.y);
|
||||
NewFeature[MFLENGTH] = DistanceBetween(P1->Point, P2->Point);
|
||||
|
Loading…
Reference in New Issue
Block a user