mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-22 01:30:49 +08:00
Merge pull request #3206 from stweil/api
Make tmp directory for all unit tests, remove RecognizeForChopTest from public API and replace some old-style type casts
This commit is contained in:
commit
9390ff5a4a
@ -498,11 +498,6 @@ class TESS_API TessBaseAPI {
|
||||
* Recognize() or TesseractRect(). (Recognize is called implicitly if needed.)
|
||||
*/
|
||||
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
/** Variant on Recognize used for testing chopper. */
|
||||
int RecognizeForChopTest(ETEXT_DESC* monitor);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Turns images into symbolic text.
|
||||
*
|
||||
|
@ -326,11 +326,6 @@ TESS_API TessPageIterator* TessBaseAPIAnalyseLayout(TessBaseAPI* handle);
|
||||
|
||||
TESS_API int TessBaseAPIRecognize(TessBaseAPI* handle, ETEXT_DESC* monitor);
|
||||
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
TESS_API int TessBaseAPIRecognizeForChopTest(TessBaseAPI* handle,
|
||||
ETEXT_DESC* monitor);
|
||||
#endif
|
||||
|
||||
TESS_API BOOL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename,
|
||||
const char* retry_config,
|
||||
int timeout_millisec,
|
||||
|
@ -893,40 +893,6 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) {
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
/** Tests the chopper by exhaustively running chop_one_blob. */
|
||||
int TessBaseAPI::RecognizeForChopTest(ETEXT_DESC* monitor) {
|
||||
if (tesseract_ == nullptr)
|
||||
return -1;
|
||||
if (thresholder_ == nullptr || thresholder_->IsEmpty()) {
|
||||
tprintf("Please call SetImage before attempting recognition.\n");
|
||||
return -1;
|
||||
}
|
||||
if (page_res_ != nullptr)
|
||||
ClearResults();
|
||||
if (FindLines() != 0)
|
||||
return -1;
|
||||
// Additional conditions under which chopper test cannot be run
|
||||
if (tesseract_->interactive_display_mode) return -1;
|
||||
|
||||
recognition_done_ = true;
|
||||
|
||||
page_res_ = new PAGE_RES(false, block_list_,
|
||||
&(tesseract_->prev_word_best_choice_));
|
||||
|
||||
PAGE_RES_IT page_res_it(page_res_);
|
||||
|
||||
while (page_res_it.word() != nullptr) {
|
||||
WERD_RES *word_res = page_res_it.word();
|
||||
std::vector<TBOX> boxes;
|
||||
tesseract_->MaximallyChopWord(boxes, page_res_it.block()->block,
|
||||
page_res_it.row()->row, word_res);
|
||||
page_res_it.forward();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif // ndef DISABLED_LEGACY_ENGINE
|
||||
|
||||
// Takes ownership of the input pix.
|
||||
void TessBaseAPI::SetInputImage(Pix* pix) { tesseract_->set_pix_original(pix); }
|
||||
|
||||
|
@ -458,13 +458,6 @@ int TessBaseAPIRecognize(TessBaseAPI* handle,
|
||||
return handle->Recognize(monitor);
|
||||
}
|
||||
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
int TessBaseAPIRecognizeForChopTest(TessBaseAPI* handle,
|
||||
ETEXT_DESC* monitor) {
|
||||
return handle->RecognizeForChopTest(monitor);
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOL TessBaseAPIProcessPages(TessBaseAPI* handle,
|
||||
const char* filename,
|
||||
const char* retry_config,
|
||||
|
@ -877,22 +877,28 @@ CLISTIZEH_C.
|
||||
\
|
||||
CLASSNAME##_C_IT(CLASSNAME##_CLIST *list) : CLIST_ITERATOR(list) {} \
|
||||
\
|
||||
CLASSNAME *data() { return (CLASSNAME *)CLIST_ITERATOR::data(); } \
|
||||
\
|
||||
CLASSNAME *data_relative(int8_t offset) { \
|
||||
return (CLASSNAME *)CLIST_ITERATOR::data_relative(offset); \
|
||||
CLASSNAME* data() { \
|
||||
return static_cast<CLASSNAME*>(CLIST_ITERATOR::data()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *forward() { return (CLASSNAME *)CLIST_ITERATOR::forward(); } \
|
||||
\
|
||||
CLASSNAME *extract() { return (CLASSNAME *)CLIST_ITERATOR::extract(); } \
|
||||
\
|
||||
CLASSNAME *move_to_first() { \
|
||||
return (CLASSNAME *)CLIST_ITERATOR::move_to_first(); \
|
||||
CLASSNAME* data_relative(int8_t offset) { \
|
||||
return static_cast<CLASSNAME*>(CLIST_ITERATOR::data_relative(offset)); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *move_to_last() { \
|
||||
return (CLASSNAME *)CLIST_ITERATOR::move_to_last(); \
|
||||
CLASSNAME* forward() { \
|
||||
return static_cast<CLASSNAME*>(CLIST_ITERATOR::forward()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* extract() { \
|
||||
return static_cast<CLASSNAME*>(CLIST_ITERATOR::extract()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* move_to_first() { \
|
||||
return static_cast<CLASSNAME*>(CLIST_ITERATOR::move_to_first()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* move_to_last() { \
|
||||
return static_cast<CLASSNAME*>(CLIST_ITERATOR::move_to_last()); \
|
||||
} \
|
||||
};
|
||||
|
||||
@ -923,7 +929,7 @@ CLISTIZEH_C.
|
||||
DLLSYM void CLASSNAME##_c1_zapper( /*delete a link*/ \
|
||||
void *link) /*link to delete*/ \
|
||||
{ \
|
||||
delete (CLASSNAME *)link; \
|
||||
delete static_cast<CLASSNAME*>(link); \
|
||||
}
|
||||
|
||||
} // namespace tesseract
|
||||
|
@ -913,7 +913,7 @@ class DLLSYM CLASSNAME##_IT : public ELIST_ITERATOR { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST_ITERATOR::data()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* data_relative(int8_t offset) { \
|
||||
CLASSNAME* data_relative(int8_t offset) { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST_ITERATOR::data_relative(offset));\
|
||||
} \
|
||||
\
|
||||
|
@ -922,24 +922,32 @@ ELIST2IZEH_C.
|
||||
public: \
|
||||
CLASSNAME##_IT(CLASSNAME##_LIST *list) : ELIST2_ITERATOR(list) {} \
|
||||
\
|
||||
CLASSNAME *data() { return (CLASSNAME *)ELIST2_ITERATOR::data(); } \
|
||||
\
|
||||
CLASSNAME *data_relative(int8_t offset) { \
|
||||
return (CLASSNAME *)ELIST2_ITERATOR::data_relative(offset); \
|
||||
CLASSNAME* data() { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::data()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *forward() { return (CLASSNAME *)ELIST2_ITERATOR::forward(); } \
|
||||
\
|
||||
CLASSNAME *backward() { return (CLASSNAME *)ELIST2_ITERATOR::backward(); } \
|
||||
\
|
||||
CLASSNAME *extract() { return (CLASSNAME *)ELIST2_ITERATOR::extract(); } \
|
||||
\
|
||||
CLASSNAME *move_to_first() { \
|
||||
return (CLASSNAME *)ELIST2_ITERATOR::move_to_first(); \
|
||||
CLASSNAME* data_relative(int8_t offset) { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::data_relative(offset)); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME *move_to_last() { \
|
||||
return (CLASSNAME *)ELIST2_ITERATOR::move_to_last(); \
|
||||
CLASSNAME* forward() { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::forward()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* backward() { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::backward()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* extract() { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::extract()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* move_to_first() { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::move_to_first()); \
|
||||
} \
|
||||
\
|
||||
CLASSNAME* move_to_last() { \
|
||||
return reinterpret_cast<CLASSNAME*>(ELIST2_ITERATOR::move_to_last()); \
|
||||
} \
|
||||
private: \
|
||||
CLASSNAME##_IT(); \
|
||||
@ -971,7 +979,7 @@ ELIST2IZEH_C.
|
||||
DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \
|
||||
ELIST2_LINK *link) /*link to delete*/ \
|
||||
{ \
|
||||
delete (CLASSNAME *)link; \
|
||||
delete reinterpret_cast<CLASSNAME*>(link); \
|
||||
} \
|
||||
\
|
||||
/* Become a deep copy of src_list*/ \
|
||||
|
@ -25,6 +25,7 @@ class BitVectorTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
public:
|
||||
@ -117,11 +118,6 @@ TEST_F(BitVectorTest, Primes) {
|
||||
map3 = map;
|
||||
TestPrimes(map3);
|
||||
// Test file i/o too.
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
std::string filename = OutputNameToPath("primesbitvector");
|
||||
FILE* fp = fopen(filename.c_str(), "wb");
|
||||
ASSERT_TRUE(fp != nullptr);
|
||||
|
@ -35,6 +35,7 @@ class DawgTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
void LoadWordlist(const std::string& filename, std::set<std::string>* words) const {
|
||||
@ -74,11 +75,6 @@ class DawgTest : public testing::Test {
|
||||
std::string orig_wordlist = file::JoinPath(TESTING_DIR, wordlist_filename);
|
||||
std::string output_dawg = OutputNameToPath(wordlist_filename + ".dawg");
|
||||
std::string output_wordlist = OutputNameToPath(wordlist_filename);
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
LoadWordlist(orig_wordlist, &orig_words);
|
||||
EXPECT_EQ(
|
||||
RunCommand(wordlist2dawg_prog, orig_wordlist, output_dawg, unicharset), 0);
|
||||
|
@ -27,6 +27,7 @@ class ImagedataTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
ImagedataTest() {}
|
||||
@ -51,11 +52,6 @@ class ImagedataTest : public ::testing::Test {
|
||||
EXPECT_EQ(kImageSize, imagedata->MemoryUsed());
|
||||
write_doc.AddPageToDocument(imagedata);
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
// Write it to a file.
|
||||
std::string filename = file::JoinPath(
|
||||
FLAGS_test_tmpdir, absl::StrCat("documentdata", doc_id, ".lstmf"));
|
||||
|
@ -23,6 +23,14 @@ const char* FLAGS_test_tmpdir = "./tmp";
|
||||
class file : public tesseract::File {
|
||||
public:
|
||||
|
||||
static void MakeTmpdir() {
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create a file and write a string to it.
|
||||
static bool WriteStringToFile(const std::string& contents, const std::string& filename) {
|
||||
File::WriteStringToFileOrDie(contents, filename);
|
||||
|
@ -25,6 +25,7 @@ class IndexMapBiDiTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
public:
|
||||
@ -78,11 +79,6 @@ TEST_F(IndexMapBiDiTest, Primes) {
|
||||
IndexMap base_map;
|
||||
base_map.CopyFrom(map);
|
||||
TestPrimes(base_map);
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
// Test file i/o too.
|
||||
std::string filename = OutputNameToPath("primesmap");
|
||||
FILE* fp = fopen(filename.c_str(), "wb");
|
||||
|
@ -41,11 +41,7 @@ TEST(LangModelTest, AddACharacter) {
|
||||
UNICHARSET unicharset;
|
||||
EXPECT_TRUE(unicharset.load_from_file(unicharset_path.c_str()));
|
||||
std::string version_str = "TestVersion";
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
std::string output_dir = FLAGS_test_tmpdir;
|
||||
LOG(INFO) << "Output dir=" << output_dir << "\n";
|
||||
std::string lang1 = "eng";
|
||||
@ -137,11 +133,7 @@ TEST(LangModelTest, AddACharacterHindi) {
|
||||
UNICHARSET unicharset;
|
||||
EXPECT_TRUE(unicharset.load_from_file(unicharset_path.c_str()));
|
||||
std::string version_str = "TestVersion";
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
std::string output_dir = FLAGS_test_tmpdir;
|
||||
LOG(INFO) << "Output dir=" << output_dir << "\n";
|
||||
std::string lang1 = "hin";
|
||||
|
@ -35,12 +35,7 @@ class LigatureTableTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
static std::locale system_locale("");
|
||||
std::locale::global(system_locale);
|
||||
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
|
||||
lig_table_ = LigatureTable::Get();
|
||||
if (!font_map) {
|
||||
|
@ -47,12 +47,7 @@ class LSTMTrainerTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
LSTMTrainerTest() {}
|
||||
|
@ -77,6 +77,7 @@ TEST_F(LSTMTrainerTest, ConvertModel) {
|
||||
file::JoinPath(TESSDATA_BEST_DIR, "fra.traineddata");
|
||||
CHECK(mgr.Init(fra_data.c_str()));
|
||||
LOG(INFO) << "Load " << fra_data << "\n";
|
||||
file::MakeTmpdir();
|
||||
std::string model_path = file::JoinPath(FLAGS_test_tmpdir, "fra.lstm");
|
||||
CHECK(mgr.ExtractToFile(model_path.c_str()));
|
||||
LOG(INFO) << "Extract " << model_path << "\n";
|
||||
|
@ -150,6 +150,7 @@ class MasterTrainerTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
std::string TestDataNameToPath(const std::string& name) {
|
||||
|
@ -64,12 +64,7 @@ class PangoFontInfoTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
static std::locale system_locale("");
|
||||
std::locale::global(system_locale);
|
||||
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
|
||||
if (!font_map) {
|
||||
font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
|
||||
@ -192,11 +187,7 @@ TEST_F(PangoFontInfoTest, CanDropUncoveredChars) {
|
||||
class FontUtilsTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
// Creates a fake fonts.conf file that points to the testdata fonts for
|
||||
// fontconfig to initialize with.
|
||||
|
@ -50,11 +50,7 @@ class ParamsModelTest : public testing::Test {
|
||||
void TestParamsModelRoundTrip(const std::string& params_model_filename) const {
|
||||
tesseract::ParamsModel orig_model;
|
||||
tesseract::ParamsModel duplicate_model;
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
std::string orig_file = TestDataNameToPath(params_model_filename);
|
||||
std::string out_file = OutputNameToPath(params_model_filename);
|
||||
|
||||
|
@ -65,6 +65,7 @@ class RecodeBeamTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
RecodeBeamTest() : lstm_dict_(&ccutil_) {}
|
||||
|
@ -44,6 +44,7 @@ class ResultIteratorTest : public testing::Test {
|
||||
return file::JoinPath(TESSDATA_DIR, "");
|
||||
}
|
||||
std::string OutputNameToPath(const std::string& name) {
|
||||
file::MakeTmpdir();
|
||||
return file::JoinPath(FLAGS_test_tmpdir, name);
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,7 @@ class ShapeTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
};
|
||||
|
||||
@ -70,11 +71,6 @@ TEST_F(ShapeTest, BasicTest) {
|
||||
Setup352(101, &shape1);
|
||||
Expect352(101, shape1);
|
||||
// It should still work after file I/O.
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
std::string filename = TmpNameToPath("shapefile");
|
||||
FILE* fp = fopen(filename.c_str(), "wb");
|
||||
ASSERT_TRUE(fp != nullptr);
|
||||
|
@ -51,12 +51,7 @@ class StringRendererTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
static std::locale system_locale("");
|
||||
std::locale::global(system_locale);
|
||||
|
||||
#if defined(_WIN32)
|
||||
_mkdir(FLAGS_test_tmpdir);
|
||||
#else
|
||||
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
||||
#endif
|
||||
file::MakeTmpdir();
|
||||
|
||||
if (!font_map) {
|
||||
font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT);
|
||||
|
@ -34,6 +34,7 @@ const int kMinStrongTextValue = 6;
|
||||
class TextlineProjectionTest : public testing::Test {
|
||||
protected:
|
||||
std::string OutputNameToPath(const std::string& name) {
|
||||
file::MakeTmpdir();
|
||||
return file::JoinPath(FLAGS_test_tmpdir, name);
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ class UnicharcompressTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
std::locale::global(std::locale(""));
|
||||
file::MakeTmpdir();
|
||||
}
|
||||
|
||||
// Loads and compresses the given unicharset.
|
||||
|
Loading…
Reference in New Issue
Block a user