tesseract 4.1.1
Loading...
Searching...
No Matches
par_control.cpp
Go to the documentation of this file.
1
2// 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
24namespace tesseract {
25
26struct 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.
@ White
Definition: callcpp.h:29
int push_back(T object)
int size() const
Definition: genericvector.h:72
T & get(int index) const
BLOB_CHOICE_LIST ** choices
Definition: par_control.cpp:35
BlobData(int index, Tesseract *tess, const WERD_RES &word)
Definition: par_control.cpp:28
void PrerecAllWordsPar(const GenericVector< WordData > &words)
Definition: par_control.cpp:38
Definition: blobs.h:284
int NumBlobs() const
Definition: blobs.h:448
TWERD * chopped_word
Definition: pageres.h:212