@@ -165,11 +165,12 @@ BoxDetector::BoxDetector(Color color, VideoOverlay* overlay)
165165 , m_plus_button(color, ButtonType::ButtonPlus, {0.581 , 0.940 , 0.310 , 0.046 }, overlay)
166166{
167167 for (size_t row = 0 ; row < 6 ; row++){
168- double y = (row == 0 ? 0.122 : 0.333 + (0.797 - 0.331 )/ 4.0 * (row-1 ));
168+ double y = (row == 0 ? 0.122 : 0.333 + (0.797 - 0.331 )/ 4.0 * (row-1 ));
169169 for (size_t col = 0 ; col < 6 ; col++){
170170 double x = 0.058 + col * (0.386 - 0.059 )/5.0 ;
171171 m_arrow_boxes.emplace_back (x, y, 0.018 , 0.026 );
172- m_lifted_arrow_boxes.emplace_back (x+0.011 , y-0.010 , 0.023 , 0.032 );
172+ // m_lifted_arrow_boxes.emplace_back(x+0.011, y-0.010, 0.023, 0.032);
173+ m_gaps_for_lifted.emplace_back (x+0.011 , y+0.010 , 0.023 , 0.004 );
173174 }
174175 }
175176}
@@ -184,7 +185,11 @@ void BoxDetector::make_overlays(VideoOverlaySet& items) const{
184185
185186// detect arrow's white interior first
186187// then use subobject template matcher BoxCellSelectionArrowMatcher to detect the whole arrow
187- bool BoxDetector::detect_at_cell (const Resolution& screen_resolution, const ImageViewRGB32& image_crop){
188+ bool BoxDetector::detect_at_cell (uint8_t cell_idx, const ImageViewRGB32& screen){
189+ #if 0
190+ const auto& box = (m_holding_pokemon ? m_lifted_arrow_boxes[cell_idx] : m_arrow_boxes[cell_idx]);
191+ ImageViewRGB32 image_crop = extract_box_reference(screen, box);
192+
188193 if (m_holding_pokemon){
189194 // If the box cursor is holding a pokemon, it will be a green downard arrow with white interior.
190195 // This green arrow may appear on top of the bottom part of a pokemon on the upper row of the box.
@@ -195,7 +200,7 @@ bool BoxDetector::detect_at_cell(const Resolution& screen_resolution, const Imag
195200 {combine_rgb(170, 230, 50), combine_rgb(200, 255, 100)},
196201 {combine_rgb(140, 180, 0), combine_rgb(200, 255, 100)},
197202 };
198- const double screen_rel_size = (screen_resolution .height / 1080.0 );
203+ const double screen_rel_size = (screen .height() / 1080.0);
199204 const size_t min_area = static_cast<size_t>(250 * screen_rel_size * screen_rel_size);
200205 const double rmsd_threshold = 70.0;
201206 const bool detected = match_template_by_waterfill(
@@ -213,6 +218,25 @@ bool BoxDetector::detect_at_cell(const Resolution& screen_resolution, const Imag
213218 return true;
214219 }
215220 }
221+ #else
222+ if (m_holding_pokemon){
223+ // If the box cursor is holding a pokemon, it will be a green downward arrow with white interior.
224+ // This green arrow may appear on top of the bottom part of a pokemon on the upper row of the box.
225+ // If the pokemon above has white bottom part, like a regular-color Spewpa, the arrrow white interior
226+ // blends in with the Spewpa white color and make it impossible to find the arrow interior using
227+ // waterfill. If the held pokemon is green (e.g. shiny Scizor) it will blend with the green part of
228+ // the arrow, making waterfill impossible. So we have to use this alternative detection:
229+ // Use the stddev of a cross section of the green-white arrow.
230+ // If there is an arrow, the bright green and white color makes the stddev quite high (>= 100)
231+ // while without the arrow, it is the background, which are the blurred overworld view which
232+ // typically has stddev lower than 50.
233+ ImageViewRGB32 image_crop = extract_box_reference (screen, m_gaps_for_lifted[cell_idx]);
234+ const auto stats = image_stats (image_crop);
235+ return stats.stddev .sum () > 80 ;
236+ }
237+
238+ ImageViewRGB32 image_crop = extract_box_reference (screen, m_arrow_boxes[cell_idx]);
239+ #endif
216240
217241 // The box curosr either is not holding a pokemon, or it is holding a pokemon but the background of the cursor
218242 // happens to be green (bottom part of a green pokemon) failing the arrow green part waterfill detection.
@@ -327,16 +351,15 @@ bool BoxDetector::detect(const ImageViewRGB32& screen){
327351 }
328352 cout << "row = " << (int)row << ", col = " << (int)col << endl;
329353#endif
330- const auto & box = (m_holding_pokemon ? m_lifted_arrow_boxes[cell_idx] : m_arrow_boxes[cell_idx]);
331- ImageViewRGB32 image_crop = extract_box_reference (screen, box);
332354 // image_crop.save("cell_" + std::to_string(row) + "_" + std::to_string(col) + ".png");
333- const uint8_t debug_cell_row = 255 , debug_cell_col = 255 ;
355+ const uint8_t debug_cell_row = PreloadSettings::debug ().BOX_SYSTEM_CELL_ROW ;
356+ const uint8_t debug_cell_col = PreloadSettings::debug ().BOX_SYSTEM_CELL_COL ;
334357 if (row == debug_cell_row && col == debug_cell_col){
335358 debug_switch = true ;
336359 cout << " start debugging switch at " << int (row) << " , " << int (col) << endl;
337360 PreloadSettings::debug ().IMAGE_TEMPLATE_MATCHING = true ;
338361 }
339- const bool detected = detect_at_cell (screen. size (), image_crop );
362+ const bool detected = detect_at_cell (cell_idx, screen );
340363 if (row == debug_cell_row && col == debug_cell_col){
341364 debug_switch = false ;
342365 PreloadSettings::debug ().IMAGE_TEMPLATE_MATCHING = false ;
0 commit comments