Skip to content

Commit f696e53

Browse files
committed
Fix item printer. Fix premature console type conclusion due to screen transition.
1 parent 02eeb15 commit f696e53

10 files changed

+58
-13
lines changed

SerialPrograms/Source/CommonTools/InferenceCallbacks/VisualInferenceCallback.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
#include "Common/Cpp/Exceptions.h"
8-
#include "CommonFramework/ImageTypes/ImageRGB32.h"
98
#include "CommonFramework/VideoPipeline/VideoFeed.h"
109
#include "VisualInferenceCallback.h"
1110

SerialPrograms/Source/CommonTools/OCR/OCR_NumberReader.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,17 @@ std::string read_number_waterfill_no_normalization(
169169
ImageRGB32 cropped = extract_box_reference(filtered, object).copy();
170170
PackedBinaryMatrix tmp(object.packed_matrix());
171171
filter_by_mask(tmp, cropped, Color(0xffffffff), true);
172-
ImageRGB32 padded = pad_image(cropped, cropped.width(), 0xffffffff);
172+
173+
// Tesseract doesn't like numbers that are too big. So scale it down.
174+
// cout << "height = " << cropped.height() << endl;
175+
if (cropped.height() > 60){
176+
cropped = cropped.scale_to(cropped.width() * 60 / cropped.height(), 60);
177+
}
178+
179+
ImageRGB32 padded = pad_image(cropped, 1 * cropped.width(), 0xffffffff);
173180
std::string ocr = OCR::ocr_read(Language::English, padded);
174-
// padded.save("zztest-cropped" + std::to_string(c) + "-" + std::to_string(i++) + ".png");
181+
182+
// padded.save("zztest-cropped" + std::to_string(c) + "-" + std::to_string(i++) + ".png");
175183
// std::cout << ocr[0] << std::endl;
176184
if (!ocr.empty()){
177185
ocr_text += ocr[0];

SerialPrograms/Source/CommonTools/VisualDetector.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class StaticScreenDetector{
2222

2323
// This is not const so that detectors can save/cache state.
2424
virtual bool detect(const ImageViewRGB32& screen) = 0;
25+
26+
virtual void commit_state(){}
2527
};
2628

2729

@@ -85,7 +87,13 @@ class DetectorToFinder : public Detector, public VisualInferenceCallback{
8587
if (m_start_of_detection == WallClock::min()){
8688
m_start_of_detection = timestamp;
8789
}
88-
return timestamp - m_start_of_detection >= m_duration;
90+
91+
if (timestamp - m_start_of_detection >= m_duration){
92+
this->commit_state();
93+
return true;
94+
}else{
95+
return false;
96+
}
8997
case FinderType::CONSISTENT:{
9098
const bool result = this->detect(frame);
9199
const bool result_changed = (result && m_last_detected < 0) || (!result && m_last_detected > 0);
@@ -104,7 +112,12 @@ class DetectorToFinder : public Detector, public VisualInferenceCallback{
104112
if (enough_time){
105113
m_consistent_result = m_last_detected > 0;
106114
}
107-
return enough_time;
115+
if (enough_time){
116+
this->commit_state();
117+
return true;
118+
}else{
119+
return false;
120+
}
108121
}
109122
default:;
110123
}

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,25 @@ void HomeMenuDetector::make_overlays(VideoOverlaySet& items) const{
4444
// This miraculously works on both Switch 1 and Switch 2.
4545
//
4646
bool HomeMenuDetector::detect(const ImageViewRGB32& screen){
47-
if (detect_only(screen)){
48-
m_console_type.commit_to_cache();
49-
return true;
50-
}else{
47+
return detect_only(screen);
48+
49+
#if 0
50+
if (!detect_only(screen)){
5151
return false;
5252
}
53+
try{
54+
m_console_type.commit_to_cache();
55+
}catch (UserSetupError&){
56+
screen.save("HomeMenuDetector-Failure.png");
57+
throw;
58+
}
59+
return true;
60+
#endif
5361
}
62+
void HomeMenuDetector::commit_state(){
63+
m_console_type.commit_to_cache();
64+
}
65+
5466
bool HomeMenuDetector::detect_only(const ImageViewRGB32& screen){
5567
ImageStats stats_bottom_row = image_stats(extract_box_reference(screen, m_bottom_row));
5668
// cout << stats_bottom_row.average << stats_bottom_row.stddev << endl;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class HomeMenuDetector : public StaticScreenDetector{
2424

2525
virtual void make_overlays(VideoOverlaySet& items) const override;
2626
virtual bool detect(const ImageViewRGB32& screen) override;
27+
virtual void commit_state() override;
2728
bool detect_only(const ImageViewRGB32& screen);
2829

2930
private:

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ void StartGameUserSelectDetector::make_overlays(VideoOverlaySet& items) const{
3131
m_switch2.make_overlays(items);
3232
}
3333
bool StartGameUserSelectDetector::detect(const ImageViewRGB32& screen){
34+
return detect_only(screen);
35+
#if 0
3436
if (detect_only(screen)){
3537
m_console.state().set_console_type(m_console, m_console_type);
3638
return true;
3739
}else{
3840
return false;
3941
}
42+
#endif
43+
}
44+
void StartGameUserSelectDetector::commit_state(){
45+
m_console.state().set_console_type(m_console, m_console_type);
4046
}
4147
bool StartGameUserSelectDetector::detect_only(const ImageViewRGB32& screen){
4248
ConsoleType type = m_type_detector.detect_only(screen);

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class StartGameUserSelectDetector : public StaticScreenDetector{
6060

6161
virtual void make_overlays(VideoOverlaySet& items) const override;
6262
virtual bool detect(const ImageViewRGB32& screen) override;
63+
virtual void commit_state() override;
6364
bool detect_only(const ImageViewRGB32& screen);
6465

6566
private:

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ void UpdatePopupDetector::make_overlays(VideoOverlaySet& items) const{
2929
m_switch2.make_overlays(items);
3030
}
3131
bool UpdatePopupDetector::detect(const ImageViewRGB32& screen){
32+
return detect_only(screen);
33+
34+
#if 0
3235
if (detect_only(screen)){
3336
m_type_detector.commit_to_cache();
3437
return true;
3538
}else{
3639
return false;
3740
}
41+
#endif
42+
}
43+
void UpdatePopupDetector::commit_state(){
44+
m_type_detector.commit_to_cache();
3845
}
3946
bool UpdatePopupDetector::detect_only(const ImageViewRGB32& screen){
4047
ConsoleType type = m_type_detector.detect_only(screen);

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class UpdatePopupDetector : public StaticScreenDetector{
6262

6363
virtual void make_overlays(VideoOverlaySet& items) const override;
6464
virtual bool detect(const ImageViewRGB32& screen) override;
65+
virtual void commit_state() override;
6566
bool detect_only(const ImageViewRGB32& screen);
6667

6768
private:

SerialPrograms/Source/NintendoSwitch/Programs/DateManip/NintendoSwitch_DateManip.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ bool DateReader::detect(const ImageViewRGB32& screen){
7777
return m_switch2.detect(screen);
7878
}
7979

80-
throw UserSetupError(
81-
m_console,
82-
"Please select a valid Switch console type."
83-
);
80+
return false;
8481
}
8582

8683

0 commit comments

Comments
 (0)