Skip to content

Commit a3bda14

Browse files
author
Gin
committed
fix box cursor detection
1 parent 30bfe7e commit a3bda14

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.cpp

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

77
#include "Common/Cpp/Exceptions.h"
8+
#include "CommonFramework/Exceptions/FatalProgramException.h"
89
#include "CommonFramework/ImageTools/ImageStats.h"
910
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
1011
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
@@ -102,7 +103,7 @@ bool BoxDetector::detect_at_cell(const ImageViewRGB32& image_crop){
102103

103104
const size_t total_crop_area = image_crop.width() * image_crop.height();
104105
const size_t min_area = static_cast<size_t>(total_crop_area / 60.0);
105-
const size_t max_area = static_cast<size_t>(total_crop_area / 15.0);
106+
const size_t max_area = static_cast<size_t>(total_crop_area / 10.0);
106107

107108
int saved_object_id = 0;
108109
if (debug_switch){
@@ -181,17 +182,19 @@ bool BoxDetector::detect(const ImageViewRGB32& screen){
181182
debug_switch = false;
182183
}
183184
if (detected){
184-
// if (arrow_found){
185-
// throw FatalProgramException(ErrorReport::SEND_ERROR_REPORT,
186-
// "Multiple box selection arrows detected!", nullptr, screen.copy());
187-
// }
185+
if (arrow_found && m_debug_mode){
186+
cout << "Multiple box selection arrows detected! First detection (" << int(m_found_row) << ", " << int(m_found_col) << ")"
187+
<< " second detection (" << int(row) << ", " << int(col) << ")" << endl;
188+
throw FatalProgramException(ErrorReport::SEND_ERROR_REPORT,
189+
"Multiple box selection arrows detected!", nullptr, screen.copy());
190+
}
188191
arrow_found = true;
189192
m_found_row = row;
190193
m_found_col = col;
191194
break;
192195
}
193196
}
194-
if (arrow_found){
197+
if (arrow_found && !m_debug_mode){
195198
break;
196199
}
197200
}

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class BoxDetector : public StaticScreenDetector{
5555
uint8_t row, uint8_t col
5656
);
5757

58+
// Under debug mode, will throw FatalProgramException when more than one box cell
59+
// detects a cursor. This is used for debugging.
60+
void set_debug_mode(bool debug_mode) { m_debug_mode = debug_mode; }
61+
5862
private:
5963
// called for each box cell to check if the selection arrow is above that cell
6064
bool detect_at_cell(const ImageViewRGB32& image_crop);
@@ -65,6 +69,7 @@ class BoxDetector : public StaticScreenDetector{
6569
std::vector<ImageFloatBox> m_arrow_boxes; // all 6 x 6 potential locations of the arrow interiors on box view
6670
uint8_t m_found_row = 0;
6771
uint8_t m_found_col = 0;
72+
bool m_debug_mode = false;
6873
};
6974

7075
class BoxWatcher : public DetectorToFinder<BoxDetector>{

SerialPrograms/Source/PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ bool BoxAlphaDetector::detect(const ImageViewRGB32& screen){
127127
size_t min_area = size_t(screen_rel_size_2 * min_area_1080p);
128128

129129
const std::vector<std::pair<uint32_t, uint32_t>> FILTERS = {
130-
{combine_rgb(200, 50, 50), combine_rgb(255, 150, 100)},
130+
// {combine_rgb(200, 50, 50), combine_rgb(255, 150, 150)},
131+
{combine_rgb(200, 50, 50), combine_rgb(255, 150, 150)},
131132
{combine_rgb(200, 50, 50), combine_rgb(255, 100, 100)},
132133
{combine_rgb(150, 0, 0), combine_rgb(255, 100, 100)},
133134
};

SerialPrograms/Source/Tests/CommandLineTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ void print_equals(){
5353
_ret = test_func(file_path); \
5454
} catch (const std::exception& e) { \
5555
cout << "Test: " << (file_path) << " threw exception: " << e.what() << endl; \
56+
_ret = 1; \
5657
} catch (const Exception& e) {\
5758
cout << "Test: " << (file_path) << " threw " << e.name() << ": <<<" << e.message() << ">>>" << endl; \
59+
_ret = 1; \
5860
} \
5961
if (_ret > 0) {\
6062
print_equals(); \

SerialPrograms/Source/Tests/PokemonLZA_Tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ int test_pokemonLZA_BoxCellInfoDetector(const ImageViewRGB32& image, const std::
195195

196196
// Test BoxDetector for row and col
197197
BoxDetector box_detector(COLOR_RED, &overlay);
198+
box_detector.set_debug_mode(true);
198199
bool in_box_system = box_detector.detect(image);
199200
if (!in_box_system){
200201
cerr << "Error: BoxDetector did not detect box system view." << endl;

0 commit comments

Comments
 (0)