tesseract  3.05.02
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 {
25  BlobData() : blob(NULL), choices(NULL) {}
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  for (int b = 0; b < blobs.size(); ++b) {
54  *blobs[b].choices =
55  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
56  }
57  } else {
58  // TODO(AMD) parallelize this.
59  for (int b = 0; b < blobs.size(); ++b) {
60  *blobs[b].choices =
61  blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
62  }
63  }
64 }
65 
66 } // namespace tesseract.
67 
68 
Tesseract * tesseract
Definition: par_control.cpp:32
T & get(int index) const
BlobData(int index, Tesseract *tess, const WERD_RES &word)
Definition: par_control.cpp:26
int push_back(T object)
TWERD * chopped_word
Definition: pageres.h:201
int NumBlobs() const
Definition: blobs.h:425
BLOB_CHOICE_LIST ** choices
Definition: par_control.cpp:33
int size() const
Definition: genericvector.h:72
Definition: blobs.h:261
void PrerecAllWordsPar(const GenericVector< WordData > &words)
Definition: par_control.cpp:36
Definition: callcpp.h:34