1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// (C) Copyright 2017, Google Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "blobs.h"
#include "normalis.h"
#include "include_gunit.h"
namespace tesseract {
class DENORMTest : public testing::Test {
protected:
void SetUp() {
std::locale::global(std::locale(""));
}
public:
void TearDown() {}
void ExpectCorrectTransform(const DENORM& denorm, const TPOINT& src,
const TPOINT& result, bool local) {
TPOINT normed;
if (local)
denorm.LocalNormTransform(src, &normed);
else
denorm.NormTransform(nullptr, src, &normed);
EXPECT_EQ(result.x, normed.x);
EXPECT_EQ(result.y, normed.y);
// Now undo
TPOINT denormed;
if (local)
denorm.LocalDenormTransform(normed, &denormed);
else
denorm.DenormTransform(nullptr, normed, &denormed);
EXPECT_EQ(src.x, denormed.x);
EXPECT_EQ(src.y, denormed.y);
}
};
// Tests a simple baseline-style normalization.
TEST_F(DENORMTest, NoRotations) {
DENORM denorm;
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
0.0f, static_cast<float>(kBlnBaselineOffset));
TPOINT pt1(1100, 2000);
TPOINT result1(200, kBlnBaselineOffset);
ExpectCorrectTransform(denorm, pt1, result1, true);
ExpectCorrectTransform(denorm, pt1, result1, false);
TPOINT pt2(900, 2100);
TPOINT result2(-200, 300 + kBlnBaselineOffset);
ExpectCorrectTransform(denorm, pt2, result2, true);
ExpectCorrectTransform(denorm, pt2, result2, false);
}
// Tests a simple baseline-style normalization with a rotation.
TEST_F(DENORMTest, WithRotations) {
DENORM denorm;
FCOORD rotation90(0.0f, 1.0f);
denorm.SetupNormalization(nullptr, &rotation90, nullptr, 1000.0f, 2000.0f, 2.0f,
3.0f, 0.0f, static_cast<float>(kBlnBaselineOffset));
TPOINT pt1(1100, 2000);
TPOINT result1(0, 200 + kBlnBaselineOffset);
ExpectCorrectTransform(denorm, pt1, result1, true);
ExpectCorrectTransform(denorm, pt1, result1, false);
TPOINT pt2(900, 2100);
TPOINT result2(-300, kBlnBaselineOffset - 200);
ExpectCorrectTransform(denorm, pt2, result2, true);
ExpectCorrectTransform(denorm, pt2, result2, false);
}
// Tests a simple baseline-style normalization with a second rotation & scale.
TEST_F(DENORMTest, Multiple) {
DENORM denorm;
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
0.0f, static_cast<float>(kBlnBaselineOffset));
DENORM denorm2;
FCOORD rotation90(0.0f, 1.0f);
denorm2.SetupNormalization(nullptr, &rotation90, &denorm, 128.0f, 128.0f, 0.5f,
0.25f, 0.0f, 0.0f);
TPOINT pt1(1050, 2000);
TPOINT result1(100, kBlnBaselineOffset);
ExpectCorrectTransform(denorm, pt1, result1, true);
ExpectCorrectTransform(denorm, pt1, result1, false);
TPOINT result2(kBlnBaselineOffset / 4, -14);
ExpectCorrectTransform(denorm2, result1, result2, true);
ExpectCorrectTransform(denorm2, pt1, result2, false);
}
} // namespace.
|