-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for OSD, update apiexample test (#1359)
* Update apiexample_test.cc * Add OSD test and logging function * Add images for OSD unittest
- Loading branch information
1 parent
7972b13
commit 5845e1a
Showing
9 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/////////////////////////////////////////////////////////////////////// | ||
// File: log.h | ||
// Description: Include for custom log message for unittest for tesseract. | ||
// based on //https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework | ||
// | ||
// 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. | ||
/////////////////////////////////////////////////////////////////////// | ||
#ifndef TESSERACT_UNITTEST_LOG_H_ | ||
#define TESSERACT_UNITTEST_LOG_H_ | ||
|
||
#include <iostream> | ||
|
||
static class LOG { public: LOG() {} | ||
std::ostream& info() { | ||
std::cout << "[ LOG MSG ] "; | ||
return std::cout; | ||
} | ||
} log; | ||
|
||
#endif // TESSERACT_UNITTEST_LOG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// File: osd_test.cc | ||
// Description: OSD Tests 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. | ||
/////////////////////////////////////////////////////////////////////// | ||
|
||
//based on https://gist.github.com/amitdo/7c7a522004dd79b398340c9595b377e1 | ||
|
||
// expects clones of tessdata, tessdata_fast and tessdata_best repos | ||
|
||
#include "log.h" | ||
#include "include_gunit.h" | ||
#include "baseapi.h" | ||
#include "leptonica/allheaders.h" | ||
#include <iostream> | ||
#include <string> | ||
|
||
namespace { | ||
|
||
class TestClass : public testing::Test { | ||
protected: | ||
}; | ||
|
||
void OSDTester( int expected_deg, const char* imgname, const char* tessdatadir) { | ||
log.info() << tessdatadir << " for image: " << imgname << std::endl; | ||
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); | ||
ASSERT_FALSE(api->Init(tessdatadir, "osd")) << "Could not initialize tesseract."; | ||
Pix *image = pixRead(imgname); | ||
ASSERT_TRUE(image != nullptr) << "Failed to read test image."; | ||
api->SetImage(image); | ||
int orient_deg; | ||
float orient_conf; | ||
const char* script_name; | ||
float script_conf; | ||
bool detected = api->DetectOrientationScript(&orient_deg, &orient_conf, &script_name, &script_conf); | ||
ASSERT_FALSE(!detected) << "Failed to detect OSD."; | ||
printf("************ Orientation in degrees: %d, Orientation confidence: %.2f\n" | ||
" Script: %s, Script confidence: %.2f\n", | ||
orient_deg, orient_conf, | ||
script_name, script_conf); | ||
EXPECT_EQ(expected_deg, orient_deg); | ||
api->End(); | ||
pixDestroy(&image); | ||
} | ||
|
||
class OSDTest : public TestClass , | ||
public ::testing::WithParamInterface<std::tuple<int, const char*, const char*>> {}; | ||
|
||
TEST_P(OSDTest, MatchOrientationDegrees) { | ||
OSDTester(std::get<0>(GetParam()), std::get<1>(GetParam()), std::get<2>(GetParam())); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataEngEuroHebrew, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(0), | ||
::testing::Values("../testing/phototest.tif" , "../testing/eurotext.tif" , "../testing/hebrew.png"), | ||
::testing::Values("../../tessdata"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataBestEngEuroHebrew, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(0), | ||
::testing::Values("../testing/phototest.tif" , "../testing/eurotext.tif" , "../testing/hebrew.png"), | ||
::testing::Values("../../tessdata_best"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataFastEngEuroHebrew, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(0), | ||
::testing::Values("../testing/phototest.tif" , "../testing/eurotext.tif" , "../testing/hebrew.png"), | ||
::testing::Values("../../tessdata_fast"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataFastRotated90, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(90), | ||
::testing::Values("../testing/phototest-rotated-R.png"), | ||
::testing::Values("../../tessdata_fast"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataFastRotated180, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(180), | ||
::testing::Values("../testing/phototest-rotated-180.png"), | ||
::testing::Values("../../tessdata_fast"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataFastRotated270, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(270), | ||
::testing::Values("../testing/phototest-rotated-L.png"), | ||
::testing::Values("../../tessdata_fast"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataFastDevaRotated270, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(270), | ||
::testing::Values("../testing/devatest-rotated-270.png"), | ||
::testing::Values("../../tessdata_fast"))); | ||
|
||
INSTANTIATE_TEST_CASE_P( TessdataFastDeva, OSDTest, | ||
::testing::Combine( | ||
::testing::Values(0), | ||
::testing::Values("../testing/devatest.png"), | ||
::testing::Values("../../tessdata_fast"))); | ||
|
||
} // namespace |