27 #include "leptonica/allheaders.h"
31 class TestClass :
public testing::Test {
35 #ifndef DISABLED_LEGACY_ENGINE
36 static void OSDTester(
int expected_deg,
const char* imgname,
const char* tessdatadir) {
39 ASSERT_FALSE(api->Init(tessdatadir,
"osd"))
40 <<
"Could not initialize tesseract.";
41 Pix* image = pixRead(imgname);
42 ASSERT_TRUE(image !=
nullptr) <<
"Failed to read test image.";
46 const char* script_name;
48 bool detected = api->DetectOrientationScript(&orient_deg, &orient_conf,
49 &script_name, &script_conf);
50 ASSERT_FALSE(!detected) <<
"Failed to detect OSD.";
52 "************ Orientation in degrees: %d, Orientation confidence: %.2f\n"
53 " Script: %s, Script confidence: %.2f\n",
54 orient_deg, orient_conf, script_name, script_conf);
55 EXPECT_EQ(expected_deg, orient_deg);
61 class OSDTest :
public TestClass,
62 public ::testing::WithParamInterface<
63 std::tuple<int, const char*, const char*>> {};
65 TEST_P(OSDTest, MatchOrientationDegrees) {
66 #ifdef DISABLED_LEGACY_ENGINE
70 OSDTester(std::get<0>(GetParam()), std::get<1>(GetParam()),
71 std::get<2>(GetParam()));
75 INSTANTIATE_TEST_CASE_P(
76 TessdataEngEuroHebrew, OSDTest,
77 ::testing::Combine(::testing::Values(0),
78 ::testing::Values(TESTING_DIR
"/phototest.tif",
79 TESTING_DIR
"/eurotext.tif",
80 TESTING_DIR
"/hebrew.png"),
81 ::testing::Values(TESSDATA_DIR)));
83 INSTANTIATE_TEST_CASE_P(
84 TessdataBestEngEuroHebrew, OSDTest,
85 ::testing::Combine(::testing::Values(0),
86 ::testing::Values(TESTING_DIR
"/phototest.tif",
87 TESTING_DIR
"/eurotext.tif",
88 TESTING_DIR
"/hebrew.png"),
89 ::testing::Values(TESSDATA_DIR
"_best")));
91 INSTANTIATE_TEST_CASE_P(
92 TessdataFastEngEuroHebrew, OSDTest,
93 ::testing::Combine(::testing::Values(0),
94 ::testing::Values(TESTING_DIR
"/phototest.tif",
95 TESTING_DIR
"/eurotext.tif",
96 TESTING_DIR
"/hebrew.png"),
97 ::testing::Values(TESSDATA_DIR
"_fast")));
99 INSTANTIATE_TEST_CASE_P(
100 TessdataFastRotated90, OSDTest,
101 ::testing::Combine(::testing::Values(90),
102 ::testing::Values(TESTING_DIR
103 "/phototest-rotated-R.png"),
104 ::testing::Values(TESSDATA_DIR
"_fast")));
106 INSTANTIATE_TEST_CASE_P(
107 TessdataFastRotated180, OSDTest,
108 ::testing::Combine(::testing::Values(180),
109 ::testing::Values(TESTING_DIR
110 "/phototest-rotated-180.png"),
111 ::testing::Values(TESSDATA_DIR
"_fast")));
113 INSTANTIATE_TEST_CASE_P(
114 TessdataFastRotated270, OSDTest,
115 ::testing::Combine(::testing::Values(270),
116 ::testing::Values(TESTING_DIR
117 "/phototest-rotated-L.png"),
118 ::testing::Values(TESSDATA_DIR
"_fast")));
120 INSTANTIATE_TEST_CASE_P(
121 TessdataFastDevaRotated270, OSDTest,
122 ::testing::Combine(::testing::Values(270),
123 ::testing::Values(TESTING_DIR
124 "/devatest-rotated-270.png"),
125 ::testing::Values(TESSDATA_DIR
"_fast")));
127 INSTANTIATE_TEST_CASE_P(
128 TessdataFastDeva, OSDTest,
129 ::testing::Combine(::testing::Values(0),
130 ::testing::Values(TESTING_DIR
"/devatest.png"),
131 ::testing::Values(TESSDATA_DIR
"_fast")));