2018-05-05 19:04:26 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2018-03-04 21:52:27 +08:00
|
|
|
// File: osd_test.cc
|
|
|
|
// Description: OSD Tests for Tesseract.
|
|
|
|
// Author: ShreeDevi Kumar
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-09-29 15:19:13 +08:00
|
|
|
// based on https://gist.github.com/amitdo/7c7a522004dd79b398340c9595b377e1
|
2018-03-04 21:52:27 +08:00
|
|
|
|
|
|
|
// expects clones of tessdata, tessdata_fast and tessdata_best repos
|
|
|
|
|
2018-05-05 19:04:26 +08:00
|
|
|
//#include "log.h"
|
2018-03-04 21:52:27 +08:00
|
|
|
#include <iostream>
|
2018-11-13 16:09:23 +08:00
|
|
|
#include <memory> // std::unique_ptr
|
2018-03-04 21:52:27 +08:00
|
|
|
#include <string>
|
2019-10-30 01:01:18 +08:00
|
|
|
#include <tesseract/baseapi.h>
|
2018-09-29 15:19:13 +08:00
|
|
|
#include "include_gunit.h"
|
2021-02-13 17:17:20 +08:00
|
|
|
#include <allheaders.h>
|
2018-03-04 21:52:27 +08:00
|
|
|
|
2020-12-27 17:41:48 +08:00
|
|
|
namespace tesseract {
|
2018-03-04 21:52:27 +08:00
|
|
|
|
|
|
|
class TestClass : public testing::Test {
|
|
|
|
protected:
|
2018-09-29 15:19:13 +08:00
|
|
|
};
|
|
|
|
|
2019-05-17 00:07:32 +08:00
|
|
|
#ifndef DISABLED_LEGACY_ENGINE
|
|
|
|
static void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
|
2018-09-29 15:19:13 +08:00
|
|
|
// log.info() << tessdatadir << " for image: " << imgname << std::endl;
|
2018-11-13 16:09:23 +08:00
|
|
|
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
|
2018-09-29 15:19:13 +08:00
|
|
|
ASSERT_FALSE(api->Init(tessdatadir, "osd"))
|
|
|
|
<< "Could not initialize tesseract.";
|
|
|
|
Pix* image = pixRead(imgname);
|
|
|
|
ASSERT_TRUE(image != nullptr) << "Failed to read test image.";
|
|
|
|
api->SetImage(image);
|
|
|
|
int orient_deg;
|
|
|
|
float orient_conf;
|
|
|
|
const char* script_name;
|
|
|
|
float script_conf;
|
|
|
|
bool detected = api->DetectOrientationScript(&orient_deg, &orient_conf,
|
|
|
|
&script_name, &script_conf);
|
|
|
|
ASSERT_FALSE(!detected) << "Failed to detect OSD.";
|
|
|
|
printf(
|
|
|
|
"************ Orientation in degrees: %d, Orientation confidence: %.2f\n"
|
|
|
|
" Script: %s, Script confidence: %.2f\n",
|
|
|
|
orient_deg, orient_conf, script_name, script_conf);
|
|
|
|
EXPECT_EQ(expected_deg, orient_deg);
|
|
|
|
api->End();
|
|
|
|
pixDestroy(&image);
|
|
|
|
}
|
2019-05-17 00:07:32 +08:00
|
|
|
#endif
|
2018-09-29 15:19:13 +08:00
|
|
|
|
|
|
|
class OSDTest : public TestClass,
|
|
|
|
public ::testing::WithParamInterface<
|
|
|
|
std::tuple<int, const char*, const char*>> {};
|
|
|
|
|
|
|
|
TEST_P(OSDTest, MatchOrientationDegrees) {
|
2019-05-17 00:07:32 +08:00
|
|
|
#ifdef DISABLED_LEGACY_ENGINE
|
|
|
|
// Skip test because TessBaseAPI::DetectOrientationScript is missing.
|
|
|
|
GTEST_SKIP();
|
|
|
|
#else
|
2018-09-29 15:19:13 +08:00
|
|
|
OSDTester(std::get<0>(GetParam()), std::get<1>(GetParam()),
|
|
|
|
std::get<2>(GetParam()));
|
2019-05-17 00:07:32 +08:00
|
|
|
#endif
|
2018-09-29 15:19:13 +08:00
|
|
|
}
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataEngEuroHebrew, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(0),
|
|
|
|
::testing::Values(TESTING_DIR "/phototest.tif",
|
|
|
|
TESTING_DIR "/eurotext.tif",
|
|
|
|
TESTING_DIR "/hebrew.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR)));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataBestEngEuroHebrew, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(0),
|
|
|
|
::testing::Values(TESTING_DIR "/phototest.tif",
|
|
|
|
TESTING_DIR "/eurotext.tif",
|
|
|
|
TESTING_DIR "/hebrew.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_best")));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataFastEngEuroHebrew, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(0),
|
|
|
|
::testing::Values(TESTING_DIR "/phototest.tif",
|
|
|
|
TESTING_DIR "/eurotext.tif",
|
|
|
|
TESTING_DIR "/hebrew.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_fast")));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataFastRotated90, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(90),
|
|
|
|
::testing::Values(TESTING_DIR
|
|
|
|
"/phototest-rotated-R.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_fast")));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataFastRotated180, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(180),
|
|
|
|
::testing::Values(TESTING_DIR
|
|
|
|
"/phototest-rotated-180.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_fast")));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataFastRotated270, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(270),
|
|
|
|
::testing::Values(TESTING_DIR
|
|
|
|
"/phototest-rotated-L.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_fast")));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataFastDevaRotated270, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(270),
|
|
|
|
::testing::Values(TESTING_DIR
|
|
|
|
"/devatest-rotated-270.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_fast")));
|
|
|
|
|
2021-01-21 02:03:05 +08:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2018-09-29 15:19:13 +08:00
|
|
|
TessdataFastDeva, OSDTest,
|
|
|
|
::testing::Combine(::testing::Values(0),
|
|
|
|
::testing::Values(TESTING_DIR "/devatest.png"),
|
|
|
|
::testing::Values(TESSDATA_DIR "_fast")));
|
2017-09-17 00:47:04 +08:00
|
|
|
|
2018-03-04 21:52:27 +08:00
|
|
|
} // namespace
|