tesseract  5.0.0-alpha-619-ge9db
par_control.cpp
Go to the documentation of this file.
1 // File: par_control.cpp
3 // Description: Control code for parallel implementation.
4 // Author: Ray Smith
5 //
6 // (C) Copyright 2013, Google Inc.
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
18 
19 #include "tesseractclass.h"
20 #ifdef _OPENMP
21 #include <omp.h>
22 #endif // _OPENMP
23 
24 namespace tesseract {
25 
26 struct BlobData {
27  BlobData() = default;
28  BlobData(int index, Tesseract* tess, const WERD_RES& word)
29  : blob(word.chopped_word->blobs[index]),
30  tesseract(tess),
31  choices(&(*word.ratings)(index, index)) {}
32 
33  TBLOB* blob = nullptr;
34  Tesseract* tesseract = nullptr;
35  BLOB_CHOICE_LIST** choices = nullptr;
36 };
37 
39  // Prepare all the blobs.
41  for (int w = 0; w < words.size(); ++w) {
42  if (words[w].word->ratings != nullptr &&
43  words[w].word->ratings->get(0, 0) == nullptr) {
44  for (int s = 0; s < words[w].lang_words.size(); ++s) {
45  Tesseract* sub = s < sub_langs_.size() ? sub_langs_[s] : this;
46  const WERD_RES& word = *words[w].lang_words[s];
47  for (int b = 0; b < word.chopped_word->NumBlobs(); ++b) {
48  blobs.push_back(BlobData(b, sub, word));
49  }
50  }
51  }
52  }
53  // Pre-classify all the blobs.
54  if (tessedit_parallelize > 1) {
55 #ifdef _OPENMP
56 #pragma omp parallel for num_threads(10)
57 #endif // _OPENMP
58  for (int b = 0; b < blobs.size(); ++b) {
59  *blobs[b].choices =
60  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, nullptr);
61  }
62  } else {
63  // TODO(AMD) parallelize this.
64  for (int b = 0; b < blobs.size(); ++b) {
65  *blobs[b].choices =
66  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, nullptr);
67  }
68  }
69 }
70 
71 } // namespace tesseract.
tesseract::BlobData::BlobData
BlobData(int index, Tesseract *tess, const WERD_RES &word)
Definition: par_control.cpp:28
tesseractclass.h
tesseract::BlobData::BlobData
BlobData()=default
tesseract::Tesseract
Definition: tesseractclass.h:172
tesseract::BlobData
Definition: par_control.cpp:26
WERD_RES
Definition: pageres.h:160
tesseract::BlobData::choices
BLOB_CHOICE_LIST ** choices
Definition: par_control.cpp:35
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
tesseract::Tesseract::PrerecAllWordsPar
void PrerecAllWordsPar(const GenericVector< WordData > &words)
Definition: par_control.cpp:38
WERD_RES::chopped_word
TWERD * chopped_word
Definition: pageres.h:206
tesseract
Definition: baseapi.h:65
tesseract::Tesseract::tessedit_parallelize
int tessedit_parallelize
Definition: tesseractclass.h:1074
GenericVector
Definition: baseapi.h:40
TBLOB
Definition: blobs.h:282
GenericVector::get
T & get(int index) const
Definition: genericvector.h:716
White
Definition: callcpp.h:28
GenericVector::size
int size() const
Definition: genericvector.h:71
tesseract::BlobData::blob
TBLOB * blob
Definition: par_control.cpp:33
TWERD::NumBlobs
int NumBlobs() const
Definition: blobs.h:446