tesseract  5.0.0-alpha-619-ge9db
tessclassifier.cpp
Go to the documentation of this file.
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // Author: rays@google.com (Ray Smith)
4 // File: tessclassifier.cpp
5 // Description: Tesseract implementation of a ShapeClassifier.
6 // Author: Ray Smith
7 // Created: Tue Nov 22 14:16:25 PST 2011
8 //
9 // (C) Copyright 2011, Google Inc.
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
21 
22 #include "tessclassifier.h"
23 
24 #include "classify.h"
25 #include "trainingsample.h"
26 
27 namespace tesseract {
28 
29 // Classifies the given [training] sample, writing to results.
30 // See ShapeClassifier for a full description.
32  const TrainingSample& sample, Pix* page_pix, int debug,
33  UNICHAR_ID keep_this, GenericVector<UnicharRating>* results) {
34  const int old_matcher_level = classify_->matcher_debug_level;
35  const int old_matcher_flags = classify_->matcher_debug_flags;
36  const int old_classify_level = classify_->classify_debug_level;
37  if (debug) {
38  // Explicitly set values of various control parameters to generate debug
39  // output if required, restoring the old values after classifying.
40  classify_->matcher_debug_level.set_value(2);
41  classify_->matcher_debug_flags.set_value(25);
42  classify_->classify_debug_level.set_value(3);
43  }
44  classify_->CharNormTrainingSample(pruner_only_, keep_this, sample, results);
45  if (debug) {
46  classify_->matcher_debug_level.set_value(old_matcher_level);
47  classify_->matcher_debug_flags.set_value(old_matcher_flags);
48  classify_->classify_debug_level.set_value(old_classify_level);
49  }
50  return results->size();
51 }
52 
53 // Provides access to the ShapeTable that this classifier works with.
55  return classify_->shape_table();
56 }
57 // Provides access to the UNICHARSET that this classifier works with.
58 // Only needs to be overridden if GetShapeTable() can return nullptr.
60  return classify_->unicharset;
61 }
62 
63 // Displays classification as the given shape_id. Creates as many windows
64 // as it feels fit, using index as a guide for placement. Adds any created
65 // windows to the windows output and returns a new index that may be used
66 // by any subsequent classifiers. Caller waits for the user to view and
67 // then destroys the windows by clearing the vector.
69  const TrainingSample& sample, Pix* page_pix, int unichar_id, int index,
70  PointerVector<ScrollView>* windows) {
71  int shape_id = unichar_id;
72  // TODO(rays) Fix this so it works with both flat and real shapetables.
73  // if (GetShapeTable() != nullptr)
74  // shape_id = BestShapeForUnichar(sample, page_pix, unichar_id, nullptr);
75  if (shape_id < 0) return index;
76  if (UnusedClassIdIn(classify_->PreTrainedTemplates, shape_id)) {
77  tprintf("No built-in templates for class/shape %d\n", shape_id);
78  return index;
79  }
80  classify_->ShowBestMatchFor(shape_id, sample.features(),
81  sample.num_features());
82  return index;
83 }
84 
85 } // namespace tesseract
tesseract::Classify::matcher_debug_level
int matcher_debug_level
Definition: classify.h:453
tesseract::PointerVector
Definition: genericvector.h:417
tesseract::Classify::shape_table
const ShapeTable * shape_table() const
Definition: classify.h:111
tesseract::TessClassifier::GetUnicharset
const UNICHARSET & GetUnicharset() const override
Definition: tessclassifier.cpp:59
tesseract::CCUtil::unicharset
UNICHARSET unicharset
Definition: ccutil.h:57
trainingsample.h
UNICHARSET
Definition: unicharset.h:145
tesseract
Definition: baseapi.h:65
UNICHAR_ID
int UNICHAR_ID
Definition: unichar.h:36
sample
Definition: cluster.h:31
tessclassifier.h
GenericVector< UnicharRating >
tesseract::TessClassifier::GetShapeTable
const ShapeTable * GetShapeTable() const override
Definition: tessclassifier.cpp:54
tesseract::TessClassifier::UnicharClassifySample
int UnicharClassifySample(const TrainingSample &sample, Pix *page_pix, int debug, UNICHAR_ID keep_this, GenericVector< UnicharRating > *results) override
Definition: tessclassifier.cpp:31
tesseract::TrainingSample
Definition: trainingsample.h:53
tesseract::Classify::CharNormTrainingSample
int CharNormTrainingSample(bool pruner_only, int keep_this, const TrainingSample &sample, GenericVector< UnicharRating > *results)
Definition: adaptmatch.cpp:1329
tesseract::TessClassifier::DisplayClassifyAs
int DisplayClassifyAs(const TrainingSample &sample, Pix *page_pix, int unichar_id, int index, PointerVector< ScrollView > *windows) override
Definition: tessclassifier.cpp:68
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
tesseract::ShapeTable
Definition: shapetable.h:261
tesseract::Classify::PreTrainedTemplates
INT_TEMPLATES PreTrainedTemplates
Definition: classify.h:514
classify.h
tesseract::Classify::matcher_debug_flags
int matcher_debug_flags
Definition: classify.h:454
tesseract::Classify::ShowBestMatchFor
void ShowBestMatchFor(int shape_id, const INT_FEATURE_STRUCT *features, int num_features)
Definition: adaptmatch.cpp:2159
UnusedClassIdIn
#define UnusedClassIdIn(T, c)
Definition: intproto.h:176
GenericVector::size
int size() const
Definition: genericvector.h:71
tesseract::Classify::classify_debug_level
int classify_debug_level
Definition: classify.h:430