Skip to content

Commit 88e4c62

Browse files
authored
Add files via upload
1 parent 6f13d75 commit 88e4c62

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

unittest/Makefile.am

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
AUTOMAKE_OPTIONS = subdir-objects
2+
3+
AM_CPPFLAGS += \
4+
-DUSE_STD_NAMESPACE -DPANGO_ENABLE_ENGINE \
5+
-I$(top_srcdir)/ccmain -I$(top_srcdir)/api \
6+
-I$(top_srcdir)/ccutil -I$(top_srcdir)/ccstruct \
7+
-I$(top_srcdir)/lstm -I$(top_srcdir)/arch \
8+
-I$(top_srcdir)/viewer \
9+
-I$(top_srcdir)/textord -I$(top_srcdir)/dict \
10+
-I$(top_srcdir)/classify -I$(top_srcdir)/display \
11+
-I$(top_srcdir)/wordrec -I$(top_srcdir)/cutil
12+
13+
# Build googletest:
14+
check_LTLIBRARIES = libgtest.la libgtest_main.la
15+
libgtest_la_SOURCES = ../googletest/googletest/src/gtest-all.cc
16+
libgtest_la_CPPFLAGS = -I$(top_srcdir)/googletest/googletest/include -I$(top_srcdir)/googletest/googletest -pthread
17+
libgtest_main_la_SOURCES = ../googletest/googletest/src/gtest_main.cc
18+
## libgtest_main_la_LIBADD = libgtest.la
19+
20+
# Build unittests
21+
GTEST_LIBS = libgtest.la libgtest_main.la
22+
AM_CPPFLAGS += -isystem $(top_srcdir)/googletest/googletest/include
23+
24+
check_PROGRAMS = \
25+
apiexample_test \
26+
tesseracttests \
27+
matrix_test
28+
29+
TESTS = $(check_PROGRAMS)
30+
31+
#List of source files needed to build the executable:
32+
33+
tesseracttests_SOURCES = ../tests/tesseracttests.cpp
34+
tesseracttests_LDADD = $(GTEST_LIBS)
35+
36+
matrix_test_SOURCES = matrix_test.cc
37+
matrix_test_LDADD = $(GTEST_LIBS)
38+
39+
apiexample_test_SOURCES = apiexample_test.cc
40+
#apiexample_test_LDFLAGS = -static
41+
apiexample_test_LDFLAGS = $(OPENCL_LDFLAGS)
42+
43+
if USING_MULTIPLELIBS
44+
apiexample_test_LDADD = \
45+
$(top_srcdir)/ccutil/libtesseract_ccutil.la \
46+
$(top_srcdir)/ccstruct/libtesseract_ccstruct.la
47+
else
48+
apiexample_test_LDADD = \
49+
$(top_srcdir)/api/libtesseract.la
50+
endif
51+
52+
apiexample_test_LDADD += $(LEPTONICA_LIBS)
53+
apiexample_test_LDADD += $(GTEST_LIBS)
54+
55+
# for windows
56+
if T_WIN
57+
apiexample_test_LDADD += -lws2_32
58+
matrix_test_LDADD += -lws2_32
59+
tesseracttests_LDADD += -lws2_32
60+
61+
AM_CPPFLAGS += -I$(top_srcdir)/vs2010/port
62+
endif

unittest/apiexample_test.cc

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
///////////////////////////////////////////////////////////////////////
2+
// File: apiexample.cpp
3+
// Description: Api Example for Tesseract.
4+
// Author: ShreeDevi Kumar
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
///////////////////////////////////////////////////////////////////////
16+
#include "gtest/gtest.h"
17+
#include "tesseract/baseapi.h"
18+
#include "leptonica/allheaders.h"
19+
#include <iostream>
20+
#include <string>
21+
#include <fstream>
22+
#include <locale>
23+
24+
TEST(TesseractTest, ApiExample)
25+
{
26+
const char* imagefile = "../testing/phototest.tif";
27+
const char* groundtruth = "testfiles/phototest.txt";
28+
char *outText;
29+
std::locale loc("en_US.UTF-8");
30+
std::ifstream file(groundtruth);
31+
file.imbue(loc);
32+
std::string gtText((std::istreambuf_iterator<char>(file)),
33+
std::istreambuf_iterator<char>());
34+
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
35+
if (api->Init(NULL, "eng")) {
36+
fprintf(stderr, "Could not initialize tesseract.\n");
37+
exit(1);
38+
}
39+
Pix *image = pixRead(imagefile);
40+
api->SetImage(image);
41+
api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
42+
outText = api->GetUTF8Text();
43+
ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth";
44+
api->End();
45+
delete [] outText;
46+
pixDestroy(&image);
47+
}
48+
49+
int main(int argc, char **argv) {
50+
::testing::InitGoogleTest(&argc, argv);
51+
return RUN_ALL_TESTS();
52+
}

0 commit comments

Comments
 (0)