tesseract v5.3.3.20231005
pieces.cpp
Go to the documentation of this file.
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
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 **********************************************************************/
48namespace tesseract {
49BLOB_CHOICE_LIST *Wordrec::classify_piece(const std::vector<SEAM *> &seams, int16_t start,
50 int16_t end, const char *description, TWERD *word,
51 BlamerBundle *blamer_bundle) {
52 if (end > start) {
53 SEAM::JoinPieces(seams, word->blobs, start, end);
54 }
55 BLOB_CHOICE_LIST *choices =
56 classify_blob(word->blobs[start], description, ScrollView::WHITE, blamer_bundle);
57 // Set the matrix_cell_ entries in all the BLOB_CHOICES.
58 BLOB_CHOICE_IT bc_it(choices);
59 for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) {
60 bc_it.data()->set_matrix_cell(start, end);
61 }
62
63 if (end > start) {
64 SEAM::BreakPieces(seams, word->blobs, start, end);
65 }
66
67 return (choices);
68}
69
70template <class BLOB_CHOICE>
71int 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
78template <class BLOB_CHOICE>
79int 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
int SortByUnicharID(const void *void1, const void *void2)
Definition: pieces.cpp:71
int SortByRating(const void *void1, const void *void2)
Definition: pieces.cpp:79
std::vector< TBLOB * > blobs
Definition: blobs.h:462
UNICHAR_ID unichar_id() const
Definition: ratngs.h:81
float rating() const
Definition: ratngs.h:84
static void JoinPieces(const std::vector< SEAM * > &seams, const std::vector< TBLOB * > &blobs, int first, int last)
Definition: seam.cpp:204
static void BreakPieces(const std::vector< SEAM * > &seams, const std::vector< TBLOB * > &blobs, int first, int last)
Definition: seam.cpp:181
virtual BLOB_CHOICE_LIST * classify_piece(const std::vector< SEAM * > &seams, int16_t start, int16_t end, const char *description, TWERD *word, BlamerBundle *blamer_bundle)
Definition: pieces.cpp:49
BLOB_CHOICE_LIST * classify_blob(TBLOB *blob, const char *string, ScrollView::Color color, BlamerBundle *blamer_bundle)
Definition: wordclass.cpp:50