tesseract  5.0.0
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 //
8 // (C) Copyright 2011, Google Inc.
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
20 
21 #ifndef THIRD_PARTY_TESSERACT_CLASSIFY_TESSCLASSIFIER_H_
22 #define THIRD_PARTY_TESSERACT_CLASSIFY_TESSCLASSIFIER_H_
23 
24 #include "shapeclassifier.h"
25 
26 namespace tesseract {
27 
28 class Classify;
29 class TrainingSample;
30 
31 // Tesseract implementation of a ShapeClassifier.
32 // Due to limitations in the content of TrainingSample, this currently
33 // only works for the static classifier and only works if the ShapeTable
34 // in classify is not nullptr.
36 public:
37  TessClassifier(bool pruner_only, tesseract::Classify *classify)
38  : pruner_only_(pruner_only), classify_(classify) {}
39  ~TessClassifier() override = default;
40 
41  // Classifies the given [training] sample, writing to results.
42  // See ShapeClassifier for a full description.
43  int UnicharClassifySample(const TrainingSample &sample, Image page_pix, int debug,
44  UNICHAR_ID keep_this, std::vector<UnicharRating> *results) override;
45  // Provides access to the ShapeTable that this classifier works with.
46  const ShapeTable *GetShapeTable() const override;
47  // Provides access to the UNICHARSET that this classifier works with.
48  // Only needs to be overridden if GetShapeTable() can return nullptr.
49  const UNICHARSET &GetUnicharset() const override;
50 
51  // Displays classification as the given shape_id. Creates as many windows
52  // as it feels fit, using index as a guide for placement. Adds any created
53  // windows to the windows output and returns a new index that may be used
54  // by any subsequent classifiers. Caller waits for the user to view and
55  // then destroys the windows by clearing the vector.
56  int DisplayClassifyAs(const TrainingSample &sample, Image page_pix, int unichar_id, int index,
57  std::vector<ScrollView *> &windows) override;
58 
59 private:
60  // Indicates that this classifier is to use just the ClassPruner, or the
61  // full classifier if false.
62  bool pruner_only_;
63  // Borrowed pointer to the actual Tesseract classifier.
64  tesseract::Classify *classify_;
65 };
66 
67 } // namespace tesseract
68 
69 #endif /* THIRD_PARTY_TESSERACT_CLASSIFY_TESSCLASSIFIER_H_ */
int UNICHAR_ID
Definition: unichar.h:36
TessClassifier(bool pruner_only, tesseract::Classify *classify)
~TessClassifier() override=default
#define TESS_API
Definition: export.h:34