Skip to content

Commit

Permalink
Merge pull request #1088 from Shreeshrii/master
Browse files Browse the repository at this point in the history
makefile.am and apiexample_test
  • Loading branch information
zdenop authored Sep 5, 2017
2 parents 3104c42 + 69ef940 commit f29498f
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif
.PHONY: install-langs ScrollView.jar install-jars training

SUBDIRS = arch ccutil viewer cutil opencl ccstruct dict classify wordrec textord lstm
SUBDIRS += ccmain api . tessdata doc
SUBDIRS += ccmain api . tessdata doc unittest

EXTRA_DIST = README.md\
aclocal.m4 config configure.ac autogen.sh contrib \
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ AC_SUBST([GENERIC_VERSION])
# ----------------------------------------

# Do not require README file (we use README.md)
AM_INIT_AUTOMAKE([foreign])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_HEADERS([config_auto.h:config/config.h.in])
AM_MAINTAINER_MODE

Expand Down Expand Up @@ -501,6 +501,7 @@ AC_CONFIG_FILES([tessdata/Makefile])
AC_CONFIG_FILES([tessdata/configs/Makefile])
AC_CONFIG_FILES([tessdata/tessconfigs/Makefile])
AC_CONFIG_FILES([testing/Makefile])
AC_CONFIG_FILES([unittest/Makefile])
AC_CONFIG_FILES([java/Makefile])
AC_CONFIG_FILES([java/com/Makefile])
AC_CONFIG_FILES([java/com/google/Makefile])
Expand Down
12 changes: 12 additions & 0 deletions testing/eurotext.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The (quick) [brown] {fox} jumps!
Over the $43,456.78 <lazy> #90 dog
& duck/goose, as 12.5% of E-mail
from [email protected] is spam.
Der „schnelle” braune Fuchs springt
über den faulen Hund. Le renard brun
«rapide» saute par-dessus le chien
paresseux. La volpe marrone rapida
salta sopra il cane pigro. El zorro
marrón rápido salta sobre el perro
perezoso. A raposa marrom rápida
salta sobre o cão preguiçoso.
9 changes: 9 additions & 0 deletions testing/phototest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.

The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox.
67 changes: 67 additions & 0 deletions unittest/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
AUTOMAKE_OPTIONS = subdir-objects

AM_CPPFLAGS += -DUSE_STD_NAMESPACE -DPANGO_ENABLE_ENGINE
AM_CPPFLAGS += -I$(top_srcdir)/api
AM_CPPFLAGS += -I$(top_srcdir)/arch
AM_CPPFLAGS += -I$(top_srcdir)/ccmain
AM_CPPFLAGS += -I$(top_srcdir)/ccstruct
AM_CPPFLAGS += -I$(top_srcdir)/ccutil
AM_CPPFLAGS += -I$(top_srcdir)/classify
AM_CPPFLAGS += -I$(top_srcdir)/cutil
AM_CPPFLAGS += -I$(top_srcdir)/dict
AM_CPPFLAGS += -I$(top_srcdir)/display
AM_CPPFLAGS += -I$(top_srcdir)/lstm
AM_CPPFLAGS += -I$(top_srcdir)/textord
AM_CPPFLAGS += -I$(top_srcdir)/viewer
AM_CPPFLAGS += -I$(top_srcdir)/wordrec

# Build googletest:
check_LTLIBRARIES = libgtest.la libgtest_main.la
libgtest_la_SOURCES = ../googletest/googletest/src/gtest-all.cc
libgtest_la_CPPFLAGS = -I$(top_srcdir)/googletest/googletest/include -I$(top_srcdir)/googletest/googletest -pthread
libgtest_main_la_SOURCES = ../googletest/googletest/src/gtest_main.cc
## libgtest_main_la_LIBADD = libgtest.la

# Build unittests
GTEST_LIBS = libgtest.la libgtest_main.la
AM_CPPFLAGS += -isystem $(top_srcdir)/googletest/googletest/include

check_PROGRAMS = \
apiexample_test \
tesseracttests \
matrix_test

TESTS = $(check_PROGRAMS)

#List of source files needed to build the executable:

tesseracttests_SOURCES = ../tests/tesseracttests.cpp
tesseracttests_LDADD = $(GTEST_LIBS)

matrix_test_SOURCES = matrix_test.cc
matrix_test_LDADD = $(GTEST_LIBS)

apiexample_test_SOURCES = apiexample_test.cc
#apiexample_test_LDFLAGS = -static
apiexample_test_LDFLAGS = $(OPENCL_LDFLAGS)

if USING_MULTIPLELIBS
apiexample_test_LDADD = \
$(top_srcdir)/ccutil/libtesseract_ccutil.la \
$(top_srcdir)/ccstruct/libtesseract_ccstruct.la
else
apiexample_test_LDADD = \
$(top_srcdir)/api/libtesseract.la
endif

apiexample_test_LDADD += $(LEPTONICA_LIBS)
apiexample_test_LDADD += $(GTEST_LIBS)

# for windows
if T_WIN
apiexample_test_LDADD += -lws2_32
matrix_test_LDADD += -lws2_32
tesseracttests_LDADD += -lws2_32

AM_CPPFLAGS += -I$(top_srcdir)/vs2010/port
endif
58 changes: 58 additions & 0 deletions unittest/apiexample_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
///////////////////////////////////////////////////////////////////////
// File: apiexample_test.cc
// Description: Api Example 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.
///////////////////////////////////////////////////////////////////////
#include "gtest/gtest.h"
#include "tesseract/baseapi.h"
#include "leptonica/allheaders.h"
#include <iostream>
#include <string>
#include <fstream>
#include <locale>

TEST(TesseractTest, ApiExample)
{
char *outText;
std::locale loc("en_US.UTF-8"); // You can also use "" for the default system locale
std::ifstream file("../testing/phototest.txt");
file.imbue(loc); // Use it for file input
std::string gtText((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}

// Open input image with leptonica library
Pix *image = pixRead("../testing/phototest.tif");
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();

ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth";

// Destroy used object and release memory
api->End();
delete [] outText;
pixDestroy(&image);

}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit f29498f

Please sign in to comment.