tesseract  4.0.0-beta.1-59-g2cc4
osd_test.cc
Go to the documentation of this file.
1 // File: osd_test.cc
2 // Description: OSD Tests for Tesseract.
3 // Author: ShreeDevi Kumar
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 
16 //based on https://gist.github.com/amitdo/7c7a522004dd79b398340c9595b377e1
17 
18 // expects clones of tessdata, tessdata_fast and tessdata_best repos
19 
20 #include "log.h"
21 #include "include_gunit.h"
22 #include "baseapi.h"
23 #include "leptonica/allheaders.h"
24 #include <iostream>
25 #include <string>
26 
27 namespace {
28 
29 class TestClass : public testing::Test {
30  protected:
31  };
32 
33  void OSDTester( int expected_deg, const char* imgname, const char* tessdatadir) {
34  log.info() << tessdatadir << " for image: " << imgname << std::endl;
36  ASSERT_FALSE(api->Init(tessdatadir, "osd")) << "Could not initialize tesseract.";
37  Pix *image = pixRead(imgname);
38  ASSERT_TRUE(image != nullptr) << "Failed to read test image.";
39  api->SetImage(image);
40  int orient_deg;
41  float orient_conf;
42  const char* script_name;
43  float script_conf;
44  bool detected = api->DetectOrientationScript(&orient_deg, &orient_conf, &script_name, &script_conf);
45  ASSERT_FALSE(!detected) << "Failed to detect OSD.";
46  printf("************ Orientation in degrees: %d, Orientation confidence: %.2f\n"
47  " Script: %s, Script confidence: %.2f\n",
48  orient_deg, orient_conf,
49  script_name, script_conf);
50  EXPECT_EQ(expected_deg, orient_deg);
51  api->End();
52  pixDestroy(&image);
53  }
54 
55  class OSDTest : public TestClass ,
56  public ::testing::WithParamInterface<std::tuple<int, const char*, const char*>> {};
57 
58  TEST_P(OSDTest, MatchOrientationDegrees) {
59  OSDTester(std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam()));
60  }
61 
62  INSTANTIATE_TEST_CASE_P( TessdataEngEuroHebrew, OSDTest,
63  ::testing::Combine(
64  ::testing::Values(0),
65  ::testing::Values(TESTING_DIR "/phototest.tif",
66  TESTING_DIR "/eurotext.tif",
67  TESTING_DIR "/hebrew.png"),
68  ::testing::Values(TESSDATA_DIR)));
69 
70  INSTANTIATE_TEST_CASE_P( TessdataBestEngEuroHebrew, OSDTest,
71  ::testing::Combine(
72  ::testing::Values(0),
73  ::testing::Values(TESTING_DIR "/phototest.tif",
74  TESTING_DIR "/eurotext.tif",
75  TESTING_DIR "/hebrew.png"),
76  ::testing::Values(TESSDATA_DIR "_best")));
77 
78  INSTANTIATE_TEST_CASE_P( TessdataFastEngEuroHebrew, OSDTest,
79  ::testing::Combine(
80  ::testing::Values(0),
81  ::testing::Values(TESTING_DIR "/phototest.tif",
82  TESTING_DIR "/eurotext.tif",
83  TESTING_DIR "/hebrew.png"),
84  ::testing::Values(TESSDATA_DIR "_fast")));
85 
86  INSTANTIATE_TEST_CASE_P( TessdataFastRotated90, OSDTest,
87  ::testing::Combine(
88  ::testing::Values(90),
89  ::testing::Values(TESTING_DIR "/phototest-rotated-R.png"),
90  ::testing::Values(TESSDATA_DIR "_fast")));
91 
92  INSTANTIATE_TEST_CASE_P( TessdataFastRotated180, OSDTest,
93  ::testing::Combine(
94  ::testing::Values(180),
95  ::testing::Values(TESTING_DIR "/phototest-rotated-180.png"),
96  ::testing::Values(TESSDATA_DIR "_fast")));
97 
98  INSTANTIATE_TEST_CASE_P( TessdataFastRotated270, OSDTest,
99  ::testing::Combine(
100  ::testing::Values(270),
101  ::testing::Values(TESTING_DIR "/phototest-rotated-L.png"),
102  ::testing::Values(TESSDATA_DIR "_fast")));
103 
104  INSTANTIATE_TEST_CASE_P( TessdataFastDevaRotated270, OSDTest,
105  ::testing::Combine(
106  ::testing::Values(270),
107  ::testing::Values(TESTING_DIR "/devatest-rotated-270.png"),
108  ::testing::Values(TESSDATA_DIR "_fast")));
109 
110  INSTANTIATE_TEST_CASE_P( TessdataFastDeva, OSDTest,
111  ::testing::Combine(
112  ::testing::Values(0),
113  ::testing::Values(TESTING_DIR "/devatest.png"),
114  ::testing::Values(TESSDATA_DIR "_fast")));
115 
116 } // namespace
struct TessBaseAPI TessBaseAPI
Definition: capi.h:83
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:326
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
Definition: baseapi.cpp:555
bool DetectOrientationScript(int *orient_deg, float *orient_conf, const char **script_name, float *script_conf)
Definition: baseapi.cpp:1866