Tesseract  3.02
tesseract-ocr/classify/flexfx.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    flexfx.c
00003  **     Purpose:     Interface to flexible feature extractor.
00004  **     Author:      Dan Johnson
00005  **     History:     Wed May 23 13:45:10 1990, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  ******************************************************************************/
00021 #include "flexfx.h"
00022 #include "featdefs.h"
00023 #include "emalloc.h"
00024 #include <string.h>
00025 #include <stdio.h>
00026 
00030 /*---------------------------------------------------------------------------*/
00031 CHAR_DESC ExtractFlexFeatures(const FEATURE_DEFS_STRUCT &FeatureDefs,
00032                               TBLOB *Blob, const DENORM& denorm) {
00033 /*
00034  **     Parameters:
00035  **             Blob            blob to extract features from
00036  **             denorm  control parameter for feature extractor
00037  **     Globals: none
00038  **     Operation: Allocate a new character descriptor and fill it in by
00039  **             calling all feature extractors which are enabled.
00040  **     Return: Structure containing features extracted from Blob.
00041  **     Exceptions: none
00042  **     History: Wed May 23 13:46:22 1990, DSJ, Created.
00043  */
00044   int Type;
00045   CHAR_DESC CharDesc;
00046 
00047   CharDesc = NewCharDescription(FeatureDefs);
00048 
00049   for (Type = 0; Type < CharDesc->NumFeatureSets; Type++)
00050     if (FeatureDefs.FeatureExtractors[Type] != NULL &&
00051         FeatureDefs.FeatureExtractors[Type]->Extractor != NULL) {
00052       CharDesc->FeatureSets[Type] =
00053         (FeatureDefs.FeatureExtractors[Type])->Extractor(Blob, denorm);
00054       if (CharDesc->FeatureSets[Type] == NULL) {
00055         FreeCharDescription(CharDesc);
00056         return NULL;
00057       }
00058     }
00059 
00060   return (CharDesc);
00061 
00062 }                                /* ExtractFlexFeatures */