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