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