/src/tesseract/src/wordrec/gradechop.cpp
Line | Count | Source |
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 | | |
32 | | namespace 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 | | **********************************************************************/ |
45 | 8.80M | PRIORITY Wordrec::grade_split_length(SPLIT *split) { |
46 | 8.80M | PRIORITY grade; |
47 | 8.80M | float split_length; |
48 | | |
49 | 8.80M | split_length = split->point1->WeightedDistance(*split->point2, chop_x_y_weight); |
50 | | |
51 | 8.80M | if (split_length <= 0) { |
52 | 34.6k | grade = 0; |
53 | 8.77M | } else { |
54 | 8.77M | grade = std::sqrt(split_length) * chop_split_dist_knob; |
55 | 8.77M | } |
56 | | |
57 | 8.80M | return (std::max(0.0f, grade)); |
58 | 8.80M | } |
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 | | **********************************************************************/ |
67 | 8.80M | PRIORITY Wordrec::grade_sharpness(SPLIT *split) { |
68 | 8.80M | PRIORITY grade; |
69 | | |
70 | 8.80M | grade = point_priority(split->point1) + point_priority(split->point2); |
71 | | |
72 | 8.80M | if (grade < -360.0) { |
73 | 0 | grade = 0; |
74 | 8.80M | } else { |
75 | 8.80M | grade += 360.0; |
76 | 8.80M | } |
77 | | |
78 | 8.80M | grade *= chop_sharpness_knob; /* Values 0 to -360 */ |
79 | | |
80 | 8.80M | return (grade); |
81 | 8.80M | } |
82 | | |
83 | | } // namespace tesseract |