tesseract 3.04.01

ccmain/par_control.cpp

Go to the documentation of this file.
00001 
00002 // File:        par_control.cpp
00003 // Description: Control code for parallel implementation.
00004 // Author:      Ray Smith
00005 // Created:     Mon Nov 04 13:23:15 PST 2013
00006 //
00007 // (C) Copyright 2013, Google Inc.
00008 // Licensed under the Apache License, Version 2.0 (the "License");
00009 // you may not use this file except in compliance with the License.
00010 // You may obtain a copy of the License at
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 //
00019 
00020 #include "tesseractclass.h"
00021 #ifdef OPENMP
00022 #include <omp.h>
00023 #endif  // OPENMP
00024 
00025 namespace tesseract {
00026 
00027 struct BlobData {
00028   BlobData() : blob(NULL), choices(NULL) {}
00029   BlobData(int index, Tesseract* tess, const WERD_RES& word)
00030     : blob(word.chopped_word->blobs[index]),
00031       tesseract(tess),
00032       choices(&(*word.ratings)(index, index)) {}
00033 
00034   TBLOB* blob;
00035   Tesseract* tesseract;
00036   BLOB_CHOICE_LIST** choices;
00037 };
00038 
00039 void Tesseract::PrerecAllWordsPar(const GenericVector<WordData>& words) {
00040   // Prepare all the blobs.
00041   GenericVector<BlobData> blobs;
00042   for (int w = 0; w < words.size(); ++w) {
00043     if (words[w].word->ratings != NULL &&
00044         words[w].word->ratings->get(0, 0) == NULL) {
00045       for (int s = 0; s < words[w].lang_words.size(); ++s) {
00046         Tesseract* sub = s < sub_langs_.size() ? sub_langs_[s] : this;
00047         const WERD_RES& word = *words[w].lang_words[s];
00048         for (int b = 0; b < word.chopped_word->NumBlobs(); ++b) {
00049           blobs.push_back(BlobData(b, sub, word));
00050         }
00051       }
00052     }
00053   }
00054   // Pre-classify all the blobs.
00055   if (tessedit_parallelize > 1) {
00056     #pragma omp parallel for num_threads(10)
00057     for (int b = 0; b < blobs.size(); ++b) {
00058       *blobs[b].choices =
00059           blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
00060     }
00061   } else {
00062     // TODO(AMD) parallelize this.
00063     for (int b = 0; b < blobs.size(); ++b) {
00064       *blobs[b].choices =
00065           blobs[b].tesseract->classify_blob(blobs[b].blob, "par", White, NULL);
00066     }
00067   }
00068 }
00069 
00070 }  // namespace tesseract.
00071 
00072 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines