Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions SerialPrograms/Source/CommonTools/OCR/OCR_Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* OCR Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Globals.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
// #include "Common/Cpp/Strings/Unicode.h"
#include "OCR_Routines.h"
#include "OCR_StringNormalization.h"
#include "OCR_Tests.h"

#include <iostream>
using std::cout;
using std::endl;

namespace PokemonAutomation{
namespace OCR{



void add_tests(UnitTestDatabase& database){
add_tests_raw_OCR(database);
}

class Test_RawOCR : public UnitTest{
public:
Test_RawOCR(
const std::string& image,
Language language,
const std::string& expected
)
: UnitTest("OCR::RawOCR - " + image)
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_language(language)
, m_expected(expected)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
ImageRGB32 image(m_image);

std::string result = ocr_read(m_language, image);
// cout << result << endl;

return normalize_utf32(result) == normalize_utf32(m_expected);
};

private:
std::string m_image;
Language m_language;
std::string m_expected;
};

void add_tests_raw_OCR(UnitTestDatabase& database){
database.add<Test_RawOCR>("OCR/letter-i-tall-1", Language::English, "I");
database.add<Test_RawOCR>("OCR/letter-i-tall-2", Language::English, "I");
database.add<Test_RawOCR>("OCR/letter-i-wide-1", Language::English, "I");
database.add<Test_RawOCR>("OCR/letter-i-wide-2", Language::English, "I");
}



}
}
25 changes: 25 additions & 0 deletions SerialPrograms/Source/CommonTools/OCR/OCR_Tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* OCR Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_OCR_Tests_H
#define PokemonAutomation_OCR_Tests_H

#include "Common/Cpp/TestRunners/UnitTest.h"

namespace PokemonAutomation{
namespace OCR{



void add_tests(UnitTestDatabase& database);

void add_tests_raw_OCR(UnitTestDatabase& database);



}
}
#endif
2 changes: 2 additions & 0 deletions SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "PokemonSwSh/PokemonSwSh_Tests.h"
#include "PokemonLA/PokemonLA_Tests.h"
#include "CommonTools/OCR/OCR_Tests.h"

namespace PokemonAutomation{
namespace ComputerPrograms{
Expand All @@ -28,6 +29,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){

NintendoSwitch::PokemonSwSh::add_tests(ret);
NintendoSwitch::PokemonLA::add_tests(ret);
OCR::add_tests(ret);

return ret;
}
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ file(GLOB LIBRARY_SOURCES
Source/CommonTools/OCR/OCR_StringMatchResult.h
Source/CommonTools/OCR/OCR_StringNormalization.cpp
Source/CommonTools/OCR/OCR_StringNormalization.h
Source/CommonTools/OCR/OCR_Tests.cpp
Source/CommonTools/OCR/OCR_Tests.h
Source/CommonTools/OCR/OCR_TextMatcher.cpp
Source/CommonTools/OCR/OCR_TextMatcher.h
Source/CommonTools/OCR/OCR_TrainingTools.cpp
Expand Down
Loading