Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Blueberry Points Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonTools/Images/ImageFilter.h"
#include "CommonTools/OCR/OCR_NumberReader.h"
#include "PokemonSV_BlueberryPointsReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


int read_BP_from_image(Logger& logger, const ImageViewRGB32& screen){
// Normalized coordinates for the upper-right balance on a 16:9 quest panel.
// Keep the right edge at 0.954: the old 0.957 edge included the left stroke
// of the B in "BP", making 6750 read as 67501. See the full-frame reference
// UnitTestResources/PokemonSV/BlueberryPoints/6750.png and its README.
const ImageFloatBox BP_NUMBER_BOX(0.866, 0.019, 0.088, 0.041);
// Isolate the near-white digits from the blue panel background. These are
// the existing quest-panel text thresholds, inclusive on all RGB channels.
const uint32_t BP_TEXT_MIN = combine_rgb(198, 198, 198);
const uint32_t BP_TEXT_MAX = combine_rgb(255, 255, 255);
ImageRGB32 number = to_blackwhite_rgb32_range(
extract_box_reference(screen, BP_NUMBER_BOX), true, BP_TEXT_MIN, BP_TEXT_MAX
);
return OCR::read_number(logger, number);
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Blueberry Points Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonSV_BlueberryPointsReader_H
#define PokemonAutomation_PokemonSV_BlueberryPointsReader_H

#include "Common/Cpp/Logging/AbstractLogger.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


// Read the numeric balance from a captured 16:9 quest panel; -1 on OCR failure.
int read_BP_from_image(Logger& logger, const ImageViewRGB32& screen);


}
}
}
#endif
40 changes: 40 additions & 0 deletions SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "Options/PokemonSV_BBQuests.h"
#include "Programs/Farming/PokemonSV_BlueberryQuests.h"
#include "PokemonSV_Tests.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Inference/PokemonSV_BlueberryPointsReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down Expand Up @@ -116,8 +119,45 @@ class Test_BBQuestsSlugs : public UnitTest{

}

namespace{

class Test_BlueberryPoints : public UnitTest{
public:
Test_BlueberryPoints(const std::string& image, int expected, size_t width, size_t height)
: UnitTest("PokemonSV::BlueberryPoints - " + image + " - " + std::to_string(width))
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_expected(expected), m_width(width), m_height(height)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{
ImageRGB32 reference(m_image);
ImageRGB32 image = reference.scale_to(m_width, m_height);
const int actual = read_BP_from_image(logger, image);
if (actual != m_expected){
return "Expected " + std::to_string(m_expected) + " BP, read " + std::to_string(actual);
}
return true;
}

private:
const std::string m_image;
const int m_expected;
const size_t m_width, m_height;
};

}

void add_tests(UnitTestDatabase& database){
database.add<Test_BBQuestsSlugs>();

// Full-frame references, in the CommandLineTests repo: they exercise the production
// crop, filter and OCR together.
database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6750.png", 6750, 1920, 1080);
database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6750.png", 6750, 1280, 720);

database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6740.png", 6740, 1920, 1080);
database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6740.png", 6740, 1280, 720);

add_tests_WhiteButtonDetector(database);
add_tests_BoxInfoDetector(database);
add_tests_BoxEggDetector(database);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "VideoGames/PokemonSV/Programs/PokemonSV_MenuNavigation.h"
#include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h"
#include "VideoGames/PokemonSV/Inference/PokemonSV_BlueberryQuestDetector.h"
#include "VideoGames/PokemonSV/Inference/PokemonSV_BlueberryPointsReader.h"
#include "VideoGames/PokemonSV/Programs/Eggs/PokemonSV_EggRoutines.h"
#include "VideoGames/PokemonSV/Programs/Boxes/PokemonSV_BoxRelease.h"
#include "VideoGames/PokemonSV/Inference/Boxes/PokemonSV_BoxEggDetector.h"
Expand Down Expand Up @@ -67,17 +68,12 @@ int read_BP(const ProgramInfo& info, VideoStream& stream, ProControllerContext&
context.wait_for_all_requests();

VideoSnapshot screen = stream.video().snapshot();
ImageRGB32 BP_value = to_blackwhite_rgb32_range(
extract_box_reference(screen, ImageFloatBox(0.866, 0.019, 0.091, 0.041)),
true,
combine_rgb(198, 198, 198), combine_rgb(255, 255, 255)
);

//Close panel
pbf_mash_button(context, BUTTON_B, 800ms);
context.wait_for_all_requests();

return OCR::read_number(stream.logger(), BP_value);
return read_BP_from_image(stream.logger(), screen);
}

std::vector<BBQuests> read_quests(
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,8 @@ file(GLOB LIBRARY_SOURCES
Source/VideoGames/PokemonSV/Inference/PokemonSV_AuctionItemNameReader.h
Source/VideoGames/PokemonSV/Inference/PokemonSV_BagDetector.cpp
Source/VideoGames/PokemonSV/Inference/PokemonSV_BagDetector.h
Source/VideoGames/PokemonSV/Inference/PokemonSV_BlueberryPointsReader.cpp
Source/VideoGames/PokemonSV/Inference/PokemonSV_BlueberryPointsReader.h
Source/VideoGames/PokemonSV/Inference/PokemonSV_BlueberryQuestDetector.cpp
Source/VideoGames/PokemonSV/Inference/PokemonSV_BlueberryQuestDetector.h
Source/VideoGames/PokemonSV/Inference/PokemonSV_BlueberryQuestReader.cpp
Expand Down
Loading