tesseract  5.0.0-alpha-619-ge9db
tessclassifier.h
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.h
5 // Description: Tesseract implementation of a ShapeClassifier.
6 // Author: Ray Smith
7 // Created: Tue Nov 22 14:10:45 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 #ifndef THIRD_PARTY_TESSERACT_CLASSIFY_TESSCLASSIFIER_H_
23 #define THIRD_PARTY_TESSERACT_CLASSIFY_TESSCLASSIFIER_H_
24 
25 #include "shapeclassifier.h"
26 
27 namespace tesseract {
28 
29 class Classify;
30 class TrainingSample;
31 
32 // Tesseract implementation of a ShapeClassifier.
33 // Due to limitations in the content of TrainingSample, this currently
34 // only works for the static classifier and only works if the ShapeTable
35 // in classify is not nullptr.
37  public:
38  TessClassifier(bool pruner_only, tesseract::Classify* classify)
39  : pruner_only_(pruner_only), classify_(classify) {}
40  ~TessClassifier() override = default;
41 
42  // Classifies the given [training] sample, writing to results.
43  // See ShapeClassifier for a full description.
44  int UnicharClassifySample(const TrainingSample& sample, Pix* page_pix,
45  int debug, UNICHAR_ID keep_this,
46  GenericVector<UnicharRating>* results) override;
47  // Provides access to the ShapeTable that this classifier works with.
48  const ShapeTable* GetShapeTable() const override;
49  // Provides access to the UNICHARSET that this classifier works with.
50  // Only needs to be overridden if GetShapeTable() can return nullptr.
51  const UNICHARSET& GetUnicharset() const override;
52 
53  // Displays classification as the given shape_id. Creates as many windows
54  // as it feels fit, using index as a guide for placement. Adds any created
55  // windows to the windows output and returns a new index that may be used
56  // by any subsequent classifiers. Caller waits for the user to view and
57  // then destroys the windows by clearing the vector.
58  int DisplayClassifyAs(const TrainingSample& sample, Pix* page_pix,
59  int unichar_id, int index,
60  PointerVector<ScrollView>* windows) override;
61 
62  private:
63  // Indicates that this classifier is to use just the ClassPruner, or the
64  // full classifier if false.
65  bool pruner_only_;
66  // Borrowed pointer to the actual Tesseract classifier.
67  tesseract::Classify* classify_;
68 };
69 
70 
71 } // namespace tesseract
72 
73 
74 
75 
76 
77 #endif /* THIRD_PARTY_TESSERACT_CLASSIFY_TESSCLASSIFIER_H_ */
tesseract::PointerVector
Definition: genericvector.h:417
tesseract::TessClassifier
Definition: tessclassifier.h:36
tesseract::Classify
Definition: classify.h:103
tesseract::TessClassifier::GetUnicharset
const UNICHARSET & GetUnicharset() const override
Definition: tessclassifier.cpp:59
tesseract::TessClassifier::~TessClassifier
~TessClassifier() override=default
tesseract::ShapeClassifier
Definition: shapeclassifier.h:43
tesseract::TessClassifier::TessClassifier
TessClassifier(bool pruner_only, tesseract::Classify *classify)
Definition: tessclassifier.h:38
UNICHARSET
Definition: unicharset.h:145
tesseract
Definition: baseapi.h:65
UNICHAR_ID
int UNICHAR_ID
Definition: unichar.h:36
sample
Definition: cluster.h:31
GenericVector< UnicharRating >
shapeclassifier.h
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::TessClassifier::DisplayClassifyAs
int DisplayClassifyAs(const TrainingSample &sample, Pix *page_pix, int unichar_id, int index, PointerVector< ScrollView > *windows) override
Definition: tessclassifier.cpp:68
tesseract::ShapeTable
Definition: shapetable.h:261