Tesseract  3.02
tesseract-ocr/classify/picofeat.cpp File Reference
#include "picofeat.h"
#include "classify.h"
#include "efio.h"
#include "featdefs.h"
#include "fpoint.h"
#include "mfoutline.h"
#include "ocrfeatures.h"
#include "params.h"
#include "trainingsample.h"
#include <math.h>
#include <stdio.h>

Go to the source code of this file.

Namespaces

namespace  tesseract

Functions

void ConvertSegmentToPicoFeat (FPOINT *Start, FPOINT *End, FEATURE_SET FeatureSet)
void ConvertToPicoFeatures2 (MFOUTLINE Outline, FEATURE_SET FeatureSet)
void NormalizePicoX (FEATURE_SET FeatureSet)
FEATURE_SET ExtractIntCNFeatures (TBLOB *blob, const DENORM &denorm)
FEATURE_SET ExtractIntGeoFeatures (TBLOB *blob, const DENORM &denorm)

Variables

double classify_pico_feature_length = 0.05

Function Documentation

void ConvertSegmentToPicoFeat ( FPOINT Start,
FPOINT End,
FEATURE_SET  FeatureSet 
)

---------------------------------------------------------------------------- Private Code ----------------------------------------------------------------------------

Definition at line 95 of file picofeat.cpp.

                                                      {
/*
 **     Parameters:
 **             Start           starting point of pico-feature
 **             End             ending point of pico-feature
 **             FeatureSet      set to add pico-feature to
 **     Globals:
 **             classify_pico_feature_length    length of a single pico-feature
 **     Operation: This routine converts an entire segment of an outline
 **             into a set of pico features which are added to
 **             FeatureSet.  The length of the segment is rounded to the
 **             nearest whole number of pico-features.  The pico-features
 **             are spaced evenly over the entire segment.
 **     Return: none (results are placed in FeatureSet)
 **     Exceptions: none
 **     History: Tue Apr 30 15:44:34 1991, DSJ, Created.
 */
  FEATURE Feature;
  FLOAT32 Angle;
  FLOAT32 Length;
  int NumFeatures;
  FPOINT Center;
  FPOINT Delta;
  int i;

  Angle = NormalizedAngleFrom (Start, End, 1.0);
  Length = DistanceBetween (*Start, *End);
  NumFeatures = (int) floor (Length / classify_pico_feature_length + 0.5);
  if (NumFeatures < 1)
    NumFeatures = 1;

  /* compute vector for one pico feature */
  Delta.x = XDelta (*Start, *End) / NumFeatures;
  Delta.y = YDelta (*Start, *End) / NumFeatures;

  /* compute position of first pico feature */
  Center.x = Start->x + Delta.x / 2.0;
  Center.y = Start->y + Delta.y / 2.0;

  /* compute each pico feature in segment and add to feature set */
  for (i = 0; i < NumFeatures; i++) {
    Feature = NewFeature (&PicoFeatDesc);
    Feature->Params[PicoFeatDir] = Angle;
    Feature->Params[PicoFeatX] = Center.x;
    Feature->Params[PicoFeatY] = Center.y;
    AddFeature(FeatureSet, Feature);

    Center.x += Delta.x;
    Center.y += Delta.y;
  }
}                                /* ConvertSegmentToPicoFeat */
void ConvertToPicoFeatures2 ( MFOUTLINE  Outline,
FEATURE_SET  FeatureSet 
)

Definition at line 151 of file picofeat.cpp.

                                                                       {
/*
 **     Parameters:
 **             Outline         outline to extract micro-features from
 **             FeatureSet      set of features to add pico-features to
 **     Globals:
 **             classify_pico_feature_length
 **                             length of features to be extracted
 **     Operation:
 **             This routine steps thru the specified outline and cuts it
 **             up into pieces of equal length.  These pieces become the
 **             desired pico-features.  Each segment in the outline
 **             is converted into an integral number of pico-features.
 **     Return: none (results are returned in FeatureSet)
 **     Exceptions: none
 **     History: 4/30/91, DSJ, Adapted from ConvertToPicoFeatures().
 */
  MFOUTLINE Next;
  MFOUTLINE First;
  MFOUTLINE Current;

  if (DegenerateOutline(Outline))
    return;

  First = Outline;
  Current = First;
  Next = NextPointAfter(Current);
  do {
    /* note that an edge is hidden if the ending point of the edge is
       marked as hidden.  This situation happens because the order of
       the outlines is reversed when they are converted from the old
       format.  In the old format, a hidden edge is marked by the
       starting point for that edge. */
    if (!(PointAt(Next)->Hidden))
      ConvertSegmentToPicoFeat (&(PointAt(Current)->Point),
        &(PointAt(Next)->Point), FeatureSet);

    Current = Next;
    Next = NextPointAfter(Current);
  }
  while (Current != First);

}                                /* ConvertToPicoFeatures2 */
FEATURE_SET ExtractIntCNFeatures ( TBLOB blob,
const DENORM denorm 
)

Definition at line 227 of file picofeat.cpp.

                                                                    {
/*
 ** Parameters:
 **   blob    blob to extract features from
 **   denorm  normalization/denormalization parameters.
 ** Return: Integer character-normalized features for blob.
 ** Exceptions: none
 ** History: 8/8/2011, rays, Created.
 */
  tesseract::TrainingSample* sample = GetIntFeatures(
      tesseract::NM_CHAR_ANISOTROPIC, blob, denorm);
  if (sample == NULL) return NULL;

  int num_features = sample->num_features();
  const INT_FEATURE_STRUCT* features = sample->features();
  FEATURE_SET feature_set = NewFeatureSet(num_features);
  for (int f = 0; f < num_features; ++f) {
    FEATURE feature = NewFeature(&IntFeatDesc);

    feature->Params[IntX] = features[f].X;
    feature->Params[IntY] = features[f].Y;
    feature->Params[IntDir] = features[f].Theta;
    AddFeature(feature_set, feature);
  }
  delete sample;

  return feature_set;
}                                /* ExtractIntCNFeatures */
FEATURE_SET ExtractIntGeoFeatures ( TBLOB blob,
const DENORM denorm 
)

Definition at line 257 of file picofeat.cpp.

                                                                     {
/*
 ** Parameters:
 **   blob    blob to extract features from
 **   denorm  normalization/denormalization parameters.
 ** Return: Geometric (top/bottom/width) features for blob.
 ** Exceptions: none
 ** History: 8/8/2011, rays, Created.
 */
  tesseract::TrainingSample* sample = GetIntFeatures(
      tesseract::NM_CHAR_ANISOTROPIC, blob, denorm);
  if (sample == NULL) return NULL;

  FEATURE_SET feature_set = NewFeatureSet(1);
  FEATURE feature = NewFeature(&IntFeatDesc);

  feature->Params[GeoBottom] = sample->geo_feature(GeoBottom);
  feature->Params[GeoTop] = sample->geo_feature(GeoTop);
  feature->Params[GeoWidth] = sample->geo_feature(GeoWidth);
  AddFeature(feature_set, feature);
  delete sample;

  return feature_set;
}                                /* ExtractIntGeoFeatures */
void NormalizePicoX ( FEATURE_SET  FeatureSet)

Definition at line 197 of file picofeat.cpp.

                                            {
/*
 **     Parameters:
 **             FeatureSet      pico-features to be normalized
 **     Globals: none
 **     Operation: This routine computes the average x position over all
 **             of the pico-features in FeatureSet and then renormalizes
 **             the pico-features to force this average to be the x origin
 **             (i.e. x=0).
 **     Return: none (FeatureSet is changed)
 **     Exceptions: none
 **     History: Tue Sep  4 16:50:08 1990, DSJ, Created.
 */
  int i;
  FEATURE Feature;
  FLOAT32 Origin = 0.0;

  for (i = 0; i < FeatureSet->NumFeatures; i++) {
    Feature = FeatureSet->Features[i];
    Origin += Feature->Params[PicoFeatX];
  }
  Origin /= FeatureSet->NumFeatures;

  for (i = 0; i < FeatureSet->NumFeatures; i++) {
    Feature = FeatureSet->Features[i];
    Feature->Params[PicoFeatX] -= Origin;
  }
}                                /* NormalizePicoX */

Variable Documentation

---------------------------------------------------------------------------- Include Files and Type Defines ---------------------------------------------------------------------------- "Pico Feature Length"

Definition at line 39 of file picofeat.cpp.