Skip to content

Commit 4caa014

Browse files
committed
Fix slider detection.
1 parent cada0c3 commit 4caa014

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch2_BinarySliderDetector.cpp

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,69 @@ std::vector<std::pair<bool, ImagePixelBox>> BinarySliderDetector::detect(const I
4242

4343
ImageViewRGB32 region = extract_box_reference(image, m_box);
4444

45-
auto matrix = compress_rgb32_to_binary_range(region, 0xffc0c0c0, 0xffffffff);
46-
auto session = make_WaterfillSession(matrix);
47-
auto iter = session->make_iterator(200);
48-
WaterfillObject object;
45+
std::vector<PackedBinaryMatrix> matrices = compress_rgb32_to_binary_range(
46+
region,
47+
{
48+
{0xffc0c0c0, 0xffffffff},
49+
{0xffd0d0d0, 0xffffffff},
50+
{0xffe0e0e0, 0xffffffff},
51+
{0xfff0f0f0, 0xffffffff},
52+
}
53+
);
4954

50-
std::vector<std::pair<bool, ImagePixelBox>> ret;
55+
auto session = make_WaterfillSession();
5156

52-
while (iter->find_next(object, false)){
53-
double aspect_ratio = object.aspect_ratio();
54-
if (aspect_ratio < 0.9 || aspect_ratio > 1.1){
55-
continue;
56-
}
57-
ImageViewRGB32 cropped = extract_box_reference(region, object);
57+
std::vector<std::pair<bool, ImagePixelBox>> best;
58+
59+
for (PackedBinaryMatrix& matrix : matrices){
60+
// cout << "-----------------" << endl;
61+
session->set_source(matrix);
62+
auto iter = session->make_iterator(200);
63+
WaterfillObject object;
64+
65+
std::vector<std::pair<bool, ImagePixelBox>> sliders;
5866

59-
double best_off_rmsd = 9999;
60-
best_off_rmsd = std::min(best_off_rmsd, LIGHT_OFF_CURSOR.rmsd(cropped));
61-
best_off_rmsd = std::min(best_off_rmsd, LIGHT_OFF_NOCURSOR.rmsd(cropped));
62-
best_off_rmsd = std::min(best_off_rmsd, DARK_OFF_CURSOR.rmsd(cropped));
63-
best_off_rmsd = std::min(best_off_rmsd, DARK_OFF_NOCURSOR.rmsd(cropped));
67+
while (iter->find_next(object, false)){
68+
double aspect_ratio = object.aspect_ratio();
69+
if (aspect_ratio < 0.9 || aspect_ratio > 1.1){
70+
continue;
71+
}
72+
ImageViewRGB32 cropped = extract_box_reference(region, object);
6473

65-
double best_on_rmsd = 9999;
66-
best_on_rmsd = std::min(best_on_rmsd, LIGHT_ON_CURSOR.rmsd(cropped));
67-
best_on_rmsd = std::min(best_on_rmsd, LIGHT_ON_NOCURSOR.rmsd(cropped));
68-
best_on_rmsd = std::min(best_on_rmsd, DARK_ON_CURSOR.rmsd(cropped));
69-
best_on_rmsd = std::min(best_on_rmsd, DARK_ON_NOCURSOR.rmsd(cropped));
74+
double best_off_rmsd = 9999;
75+
best_off_rmsd = std::min(best_off_rmsd, LIGHT_OFF_CURSOR.rmsd(cropped));
76+
best_off_rmsd = std::min(best_off_rmsd, LIGHT_OFF_NOCURSOR.rmsd(cropped));
77+
best_off_rmsd = std::min(best_off_rmsd, DARK_OFF_CURSOR.rmsd(cropped));
78+
best_off_rmsd = std::min(best_off_rmsd, DARK_OFF_NOCURSOR.rmsd(cropped));
7079

71-
// cout << "best_off_rmsd = " << best_off_rmsd << endl;
72-
// cout << "best_on_rmsd = " << best_on_rmsd << endl;
80+
double best_on_rmsd = 9999;
81+
best_on_rmsd = std::min(best_on_rmsd, LIGHT_ON_CURSOR.rmsd(cropped));
82+
best_on_rmsd = std::min(best_on_rmsd, LIGHT_ON_NOCURSOR.rmsd(cropped));
83+
best_on_rmsd = std::min(best_on_rmsd, DARK_ON_CURSOR.rmsd(cropped));
84+
best_on_rmsd = std::min(best_on_rmsd, DARK_ON_NOCURSOR.rmsd(cropped));
7385

74-
bool on = best_on_rmsd < best_off_rmsd;
75-
double best = on ? best_on_rmsd : best_off_rmsd;
86+
// cout << "best_off_rmsd = " << best_off_rmsd << endl;
87+
// cout << "best_on_rmsd = " << best_on_rmsd << endl;
88+
89+
bool on = best_on_rmsd < best_off_rmsd;
90+
double best_rmsd = on ? best_on_rmsd : best_off_rmsd;
91+
92+
if (best_rmsd < 60){
93+
sliders.emplace_back(on, object);
94+
}
95+
96+
// for (auto& item : sliders){
97+
// cout << item.first << " : " << item.second.max_y << endl;
98+
// }
7699

77-
if (best < 60){
78-
ret.emplace_back(on, object);
79100
}
80101

102+
if (best.size() < sliders.size()){
103+
best = std::move(sliders);
104+
}
81105
}
82106

83-
return ret;
107+
return best;
84108
}
85109

86110

0 commit comments

Comments
 (0)