move tracker: ignore sporadic shape and position changes

The tracker may get a random result for a couple of frames occasionally.
Just report the last known position and shape instead.
This commit is contained in:
Megamouse 2024-12-12 03:06:32 +01:00
parent 55ead61ea8
commit 56a254ba9c
2 changed files with 22 additions and 4 deletions

View File

@ -444,10 +444,27 @@ void ps_move_tracker<DiagnosticsEnabled>::process_contours(ps_move_info& info, u
// Set results
set_valid(info, index, true);
info.distance_mm = distance_mm;
info.radius = sphere_radius_pixels;
info.x_pos = std::clamp(static_cast<u32>(centers[best_index].x), 0u, width);
info.y_pos = std::clamp(static_cast<u32>(centers[best_index].y), 0u, height);
const u32 x_pos = std::clamp(static_cast<u32>(centers[best_index].x), 0u, width);
const u32 y_pos = std::clamp(static_cast<u32>(centers[best_index].y), 0u, height);
// Only set new values if the new shape and position are relatively similar to the old ones.
const auto distance_travelled = [](int x1, int y1, int x2, int y2)
{
return std::sqrt(std::pow(x2 - x1, 2) + pow(y2 - y1, 2));
};
const bool shape_matches = std::abs(info.radius - sphere_radius_pixels) < (info.radius * 2) &&
distance_travelled(info.x_pos, info.y_pos, x_pos, y_pos) < (info.radius * 8);
if (shape_matches || ++m_shape_fail_count[index] >= 3)
{
info.distance_mm = distance_mm;
info.radius = sphere_radius_pixels;
info.x_pos = x_pos;
info.y_pos = y_pos;
m_shape_fail_count[index] = 0; // Reset fail count
}
if constexpr (!DiagnosticsEnabled)
return;

View File

@ -93,6 +93,7 @@ private:
std::array<std::vector<u8>, CELL_GEM_MAX_NUM> m_image_hue_filtered{};
std::array<std::vector<u8>, CELL_GEM_MAX_NUM> m_image_binary{};
std::array<u32, CELL_GEM_MAX_NUM> m_fail_count{};
std::array<u32, CELL_GEM_MAX_NUM> m_shape_fail_count{};
std::array<u32, 360> m_hues{};
std::array<ps_move_info, CELL_GEM_MAX_NUM> m_info{};