tesseract/ccmain/par_control.cpp
theraysmith@gmail.com d8d9b390d1 misc fixes
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@961 d0cd1f9f-072b-0410-8dd7-cf729c803f20
2014-01-09 17:49:07 +00:00

72 lines
2.4 KiB
C++

///////////////////////////////////////////////////////////////////////
// File: par_control.cpp
// Description: Control code for parallel implementation.
// Author: Ray Smith
// Created: Mon Nov 04 13:23:15 PST 2013
//
// (C) Copyright 2013, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////
#include "tesseractclass.h"
namespace tesseract {
struct BlobData {
BlobData() : blob(NULL), choices(NULL) {}
BlobData(int index, Tesseract* tess, const WERD_RES& word)
: blob(word.chopped_word->blobs[index]),
tesseract(tess),
choices(&(*word.ratings)(index, index)) {}
TBLOB* blob;
Tesseract* tesseract;
BLOB_CHOICE_LIST** choices;
};
void Tesseract::PrerecAllWordsPar(const GenericVector<WordData>& words) {
// Prepare all the blobs.
GenericVector<BlobData> blobs;
for (int w = 0; w < words.size(); ++w) {
if (words[w].word->ratings != NULL &&
words[w].word->ratings->get(0, 0) == NULL) {
for (int b = 0; b < words[w].word->chopped_word->NumBlobs(); ++b) {
blobs.push_back(BlobData(b, this, *words[w].word));
}
for (int s = 0; s < words[w].lang_words.size(); ++s) {
const WERD_RES& word = words[w].lang_words[s];
for (int b = 0; b < word.chopped_word->NumBlobs(); ++b) {
blobs.push_back(BlobData(b, sub_langs_[s], word));
}
}
}
}
// Pre-classify all the blobs.
if (tessedit_parallelize > 1) {
#pragma omp parallel for num_threads(10)
for (int b = 0; b < blobs.size(); ++b) {
*blobs[b].choices =
blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
}
} else {
// TODO(AMD) parallelize this.
for (int b = 0; b < blobs.size(); ++b) {
*blobs[b].choices =
blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
}
}
}
} // namespace tesseract.