/src/tesseract/src/wordrec/pieces.cpp
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * File: pieces.cpp |
4 | | * Description: |
5 | | * Author: Mark Seaman, OCR Technology |
6 | | * |
7 | | * (c) Copyright 1987, Hewlett-Packard Company. |
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 | | * |
18 | | *****************************************************************************/ |
19 | | /*---------------------------------------------------------------------- |
20 | | I n c l u d e s |
21 | | ----------------------------------------------------------------------*/ |
22 | | |
23 | | #include "blobs.h" |
24 | | #include "helpers.h" |
25 | | #include "matrix.h" |
26 | | #include "ratngs.h" |
27 | | #include "seam.h" |
28 | | #include "wordrec.h" |
29 | | |
30 | | // Include automatically generated configuration file if running autoconf. |
31 | | #ifdef HAVE_CONFIG_H |
32 | | # include "config_auto.h" |
33 | | #endif |
34 | | |
35 | | using tesseract::ScoredFont; |
36 | | |
37 | | /*---------------------------------------------------------------------- |
38 | | F u n c t i o n s |
39 | | ----------------------------------------------------------------------*/ |
40 | | |
41 | | /********************************************************************** |
42 | | * classify_piece |
43 | | * |
44 | | * Create a larger piece from a collection of smaller ones. Classify |
45 | | * it and return the results. Take the large piece apart to leave |
46 | | * the collection of small pieces un modified. |
47 | | **********************************************************************/ |
48 | | namespace tesseract { |
49 | | BLOB_CHOICE_LIST *Wordrec::classify_piece(const std::vector<SEAM *> &seams, int16_t start, |
50 | | int16_t end, const char *description, TWERD *word, |
51 | 1.96M | BlamerBundle *blamer_bundle) { |
52 | 1.96M | if (end > start) { |
53 | 981k | SEAM::JoinPieces(seams, word->blobs, start, end); |
54 | 981k | } |
55 | 1.96M | BLOB_CHOICE_LIST *choices = |
56 | 1.96M | classify_blob(word->blobs[start], description, ScrollView::WHITE, blamer_bundle); |
57 | | // Set the matrix_cell_ entries in all the BLOB_CHOICES. |
58 | 1.96M | BLOB_CHOICE_IT bc_it(choices); |
59 | 10.8M | for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) { |
60 | 8.86M | bc_it.data()->set_matrix_cell(start, end); |
61 | 8.86M | } |
62 | | |
63 | 1.96M | if (end > start) { |
64 | 981k | SEAM::BreakPieces(seams, word->blobs, start, end); |
65 | 981k | } |
66 | | |
67 | 1.96M | return (choices); |
68 | 1.96M | } |
69 | | |
70 | | template <class BLOB_CHOICE> |
71 | | int SortByUnicharID(const void *void1, const void *void2) { |
72 | | const BLOB_CHOICE *p1 = *static_cast<const BLOB_CHOICE *const *>(void1); |
73 | | const BLOB_CHOICE *p2 = *static_cast<const BLOB_CHOICE *const *>(void2); |
74 | | |
75 | | return p1->unichar_id() - p2->unichar_id(); |
76 | | } |
77 | | |
78 | | template <class BLOB_CHOICE> |
79 | | int SortByRating(const void *void1, const void *void2) { |
80 | | const BLOB_CHOICE *p1 = *static_cast<const BLOB_CHOICE *const *>(void1); |
81 | | const BLOB_CHOICE *p2 = *static_cast<const BLOB_CHOICE *const *>(void2); |
82 | | |
83 | | if (p1->rating() < p2->rating()) { |
84 | | return 1; |
85 | | } |
86 | | return -1; |
87 | | } |
88 | | |
89 | | } // namespace tesseract |