22 #include "leptonica/allheaders.h" 32 class QuickTest :
public testing::Test {
34 virtual void SetUp() {
35 start_time_ = time(NULL);
37 virtual void TearDown() {
38 const time_t end_time = time(NULL);
39 EXPECT_TRUE(end_time - start_time_ <=25) <<
"The test took too long - " << ::testing::PrintToString(end_time - start_time_);
44 void OCRTester(
const char* imgname,
const char* groundtruth,
const char* tessdatadir,
const char*
lang) {
48 std::ifstream file(groundtruth);
50 std::string gtText((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
52 ASSERT_FALSE(api->
Init(tessdatadir, lang)) <<
"Could not initialize tesseract.";
53 Pix *image = pixRead(imgname);
54 ASSERT_TRUE(image !=
nullptr) <<
"Failed to read test image.";
57 EXPECT_EQ(gtText,outText) <<
"Phototest.tif OCR does not match ground truth for " << ::testing::PrintToString(lang);
63 class MatchGroundTruth :
public QuickTest ,
64 public ::testing::WithParamInterface<const char*> {
67 TEST_P(MatchGroundTruth, FastPhototestOCR) {
68 OCRTester(TESTING_DIR
"/phototest.tif",
69 TESTING_DIR
"/phototest.txt",
70 TESSDATA_DIR
"_fast", GetParam());
73 INSTANTIATE_TEST_CASE_P( EngLatinDevaArabLang, MatchGroundTruth,
74 ::testing::Values(
"eng",
"script/Latin",
"script/Devanagari",
"script/Arabic") );
76 class EuroText :
public QuickTest {
79 TEST_F(EuroText, FastOCR) {
80 OCRTester(TESTING_DIR
"/eurotext.tif",
81 TESTING_DIR
"/eurotext.txt",
82 TESSDATA_DIR
"_fast",
"script/Latin");
struct TessBaseAPI TessBaseAPI
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)
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)