All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
22 namespace tesseract {
23 
24 struct BlobData {
26  BlobData(int index, Tesseract* tess, const WERD_RES& word)
27  : blob(word.chopped_word->blobs[index]),
28  tesseract(tess),
29  choices(&(*word.ratings)(index, index)) {}
30 
33  BLOB_CHOICE_LIST** choices;
34 };
35 
37  // Prepare all the blobs.
39  for (int w = 0; w < words.size(); ++w) {
40  if (words[w].word->ratings != NULL &&
41  words[w].word->ratings->get(0, 0) == NULL) {
42  for (int s = 0; s < words[w].lang_words.size(); ++s) {
43  Tesseract* sub = s < sub_langs_.size() ? sub_langs_[s] : this;
44  const WERD_RES& word = *words[w].lang_words[s];
45  for (int b = 0; b < word.chopped_word->NumBlobs(); ++b) {
46  blobs.push_back(BlobData(b, sub, word));
47  }
48  }
49  }
50  }
51  // Pre-classify all the blobs.
52  if (tessedit_parallelize > 1) {
53  #pragma omp parallel for num_threads(10)
54  for (int b = 0; b < blobs.size(); ++b) {
55  *blobs[b].choices =
56  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
57  }
58  } else {
59  // TODO(AMD) parallelize this.
60  for (int b = 0; b < blobs.size(); ++b) {
61  *blobs[b].choices =
62  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
63  }
64  }
65 }
66 
67 } // namespace tesseract.
68 
69 
Definition: blobs.h:261
int size() const
Definition: genericvector.h:72
Definition: callcpp.h:34
int push_back(T object)
TWERD * chopped_word
Definition: pageres.h:201
Tesseract * tesseract
Definition: par_control.cpp:32
int NumBlobs() const
Definition: blobs.h:425
BlobData(int index, Tesseract *tess, const WERD_RES &word)
Definition: par_control.cpp:26
void PrerecAllWordsPar(const GenericVector< WordData > &words)
Definition: par_control.cpp:36
#define NULL
Definition: host.h:144
BLOB_CHOICE_LIST ** choices
Definition: par_control.cpp:33
T & get(int index) const