mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-18 14:41:36 +08:00
Add files via upload
This commit is contained in:
parent
6f13d75534
commit
88e4c62b39
62
unittest/Makefile.am
Normal file
62
unittest/Makefile.am
Normal file
@ -0,0 +1,62 @@
|
||||
AUTOMAKE_OPTIONS = subdir-objects
|
||||
|
||||
AM_CPPFLAGS += \
|
||||
-DUSE_STD_NAMESPACE -DPANGO_ENABLE_ENGINE \
|
||||
-I$(top_srcdir)/ccmain -I$(top_srcdir)/api \
|
||||
-I$(top_srcdir)/ccutil -I$(top_srcdir)/ccstruct \
|
||||
-I$(top_srcdir)/lstm -I$(top_srcdir)/arch \
|
||||
-I$(top_srcdir)/viewer \
|
||||
-I$(top_srcdir)/textord -I$(top_srcdir)/dict \
|
||||
-I$(top_srcdir)/classify -I$(top_srcdir)/display \
|
||||
-I$(top_srcdir)/wordrec -I$(top_srcdir)/cutil
|
||||
|
||||
# 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
|
52
unittest/apiexample_test.cc
Normal file
52
unittest/apiexample_test.cc
Normal file
@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// File: apiexample.cpp
|
||||
// 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)
|
||||
{
|
||||
const char* imagefile = "../testing/phototest.tif";
|
||||
const char* groundtruth = "testfiles/phototest.txt";
|
||||
char *outText;
|
||||
std::locale loc("en_US.UTF-8");
|
||||
std::ifstream file(groundtruth);
|
||||
file.imbue(loc);
|
||||
std::string gtText((std::istreambuf_iterator<char>(file)),
|
||||
std::istreambuf_iterator<char>());
|
||||
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
|
||||
if (api->Init(NULL, "eng")) {
|
||||
fprintf(stderr, "Could not initialize tesseract.\n");
|
||||
exit(1);
|
||||
}
|
||||
Pix *image = pixRead(imagefile);
|
||||
api->SetImage(image);
|
||||
api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
|
||||
outText = api->GetUTF8Text();
|
||||
ASSERT_EQ(gtText,outText) << "Phototest.tif with default values OCR does not match ground truth";
|
||||
api->End();
|
||||
delete [] outText;
|
||||
pixDestroy(&image);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue
Block a user