mirror of
https://github.com/unclshura/splitter.git
synced 2026-06-22 00:22:01 +00:00
EMA smoothing added
This commit is contained in:
parent
5473bc9d09
commit
9d72ede1d2
@ -20,10 +20,13 @@ public sealed class CameraController
|
|||||||
private readonly int _lostFreezeFrames;
|
private readonly int _lostFreezeFrames;
|
||||||
private readonly float _cameraEasing;
|
private readonly float _cameraEasing;
|
||||||
|
|
||||||
// --- NEW: dropout tolerance ---
|
// --- Dropout tolerance ---
|
||||||
private const int DropoutToleranceFrames = 20; // adjust as needed
|
private const int DropoutToleranceFrames = 20;
|
||||||
private int _dropoutCounter;
|
private int _dropoutCounter;
|
||||||
|
|
||||||
|
// --- NEW: EMA smoothing ---
|
||||||
|
private const float EmaFactor = 0.85f; // 0.85 = smooth but responsive
|
||||||
|
|
||||||
private int _lostFrames;
|
private int _lostFrames;
|
||||||
private Point2f _cameraCenter;
|
private Point2f _cameraCenter;
|
||||||
private TrackState _state;
|
private TrackState _state;
|
||||||
@ -75,20 +78,18 @@ public sealed class CameraController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// NEW: dropout tolerance
|
// Dropout tolerance
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
if (!objectCenter.HasValue)
|
if (!objectCenter.HasValue)
|
||||||
{
|
{
|
||||||
if (_dropoutCounter < DropoutToleranceFrames)
|
if (_dropoutCounter < DropoutToleranceFrames)
|
||||||
{
|
{
|
||||||
// Treat as still tracked
|
|
||||||
objectCenter = _kalman.LastMeasurement;
|
objectCenter = _kalman.LastMeasurement;
|
||||||
_dropoutCounter++;
|
_dropoutCounter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Reset dropout counter when detection is present
|
|
||||||
_dropoutCounter = 0;
|
_dropoutCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ public sealed class CameraController
|
|||||||
if (_lostFrames <= _lostFreezeFrames)
|
if (_lostFrames <= _lostFreezeFrames)
|
||||||
{
|
{
|
||||||
_state = TrackState.LostFreeze;
|
_state = TrackState.LostFreeze;
|
||||||
objectCenter = null; // Kalman predicts but camera won't move
|
objectCenter = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -123,11 +124,21 @@ public sealed class CameraController
|
|||||||
{
|
{
|
||||||
smoothedCenter = _kalman.Update(objectCenter);
|
smoothedCenter = _kalman.Update(objectCenter);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// NEW: EMA smoothing
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
smoothedCenter = new Point2f(
|
||||||
|
smoothedCenter.X * (1 - EmaFactor) + _cameraCenter.X * EmaFactor,
|
||||||
|
smoothedCenter.Y * (1 - EmaFactor) + _cameraCenter.Y * EmaFactor
|
||||||
|
);
|
||||||
|
|
||||||
|
// fast easing
|
||||||
float fastEasing = 0.015f;
|
float fastEasing = 0.015f;
|
||||||
_cameraCenter = new Point2f(
|
_cameraCenter = new Point2f(
|
||||||
_cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * fastEasing,
|
_cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * fastEasing,
|
||||||
_cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * fastEasing);
|
_cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * fastEasing);
|
||||||
|
|
||||||
|
// configurable easing
|
||||||
_cameraCenter = new Point2f(
|
_cameraCenter = new Point2f(
|
||||||
_cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * _cameraEasing,
|
_cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * _cameraEasing,
|
||||||
_cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * _cameraEasing);
|
_cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * _cameraEasing);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user