tesseract v5.3.3.20231005
gradechop.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * File: gradechop.cpp (Formerly gradechop.c)
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 <algorithm>
24#include <cmath>
25#include "chop.h"
26#include "wordrec.h"
27
28/*----------------------------------------------------------------------
29 M a c r o s
30----------------------------------------------------------------------*/
31
32namespace tesseract {
33
34/*----------------------------------------------------------------------
35 F u n c t i o n s
36----------------------------------------------------------------------*/
37
38/**********************************************************************
39 * grade_split_length
40 *
41 * Return a grade for the length of this split.
42 * 0 = "perfect"
43 * 100 = "no way jay"
44 **********************************************************************/
46 PRIORITY grade;
47 float split_length;
48
49 split_length = split->point1->WeightedDistance(*split->point2, chop_x_y_weight);
50
51 if (split_length <= 0) {
52 grade = 0;
53 } else {
54 grade = std::sqrt(split_length) * chop_split_dist_knob;
55 }
56
57 return (std::max(0.0f, grade));
58}
59
60/**********************************************************************
61 * grade_sharpness
62 *
63 * Return a grade for the sharpness of this split.
64 * 0 = "perfect"
65 * 100 = "no way jay"
66 **********************************************************************/
68 PRIORITY grade;
69
70 grade = point_priority(split->point1) + point_priority(split->point2);
71
72 if (grade < -360.0) {
73 grade = 0;
74 } else {
75 grade += 360.0;
76 }
77
78 grade *= chop_sharpness_knob; /* Values 0 to -360 */
79
80 return (grade);
81}
82
83} // namespace tesseract
float PRIORITY
Definition: seam.h:31
const std::vector< std::string > split(const std::string &s, char c)
Definition: helpers.h:43
PRIORITY grade_sharpness(SPLIT *split)
Definition: gradechop.cpp:67
PRIORITY grade_split_length(SPLIT *split)
Definition: gradechop.cpp:45
PRIORITY point_priority(EDGEPT *point)
Definition: chop.cpp:64