oprimised camera controiller parameters. Looks good now.

This commit is contained in:
Alexander Shabarshov 2026-05-11 20:37:00 +01:00
parent 9d72ede1d2
commit 1d337cf5bf
3 changed files with 27 additions and 33 deletions

View File

@ -17,15 +17,14 @@ public sealed class CameraController
private readonly int _cropWidth; private readonly int _cropWidth;
private readonly int _cropHeight; private readonly int _cropHeight;
private readonly KalmanTracker _kalman; private readonly KalmanTracker _kalman;
private readonly int _lostFreezeFrames;
private readonly float _cameraEasing;
// --- Dropout tolerance ---
private const int DropoutToleranceFrames = 20;
private int _dropoutCounter; private int _dropoutCounter;
// --- NEW: EMA smoothing --- // --- Dropout tolerance ---
private const float EmaFactor = 0.85f; // 0.85 = smooth but responsive private const int DropoutToleranceFrames = 20;
private const float EmaFactor = 0.65f; // smoother but responsive
private const float CameraEasing = 0.03f; // stronger follow-through
private const int LostFreezeFrames = 60; // 2 seconds at 30 FPS
private int _lostFrames; private int _lostFrames;
private Point2f _cameraCenter; private Point2f _cameraCenter;
@ -40,20 +39,17 @@ public sealed class CameraController
int videoHeight, int videoHeight,
int cropWidth, int cropWidth,
int cropHeight, int cropHeight,
KalmanTracker kalman, KalmanTracker kalman
int lostFreezeFrames, )
float cameraEasing)
{ {
_videoWidth = videoWidth; _videoWidth = videoWidth;
_videoHeight = videoHeight; _videoHeight = videoHeight;
_cropWidth = cropWidth; _cropWidth = cropWidth;
_cropHeight = cropHeight; _cropHeight = cropHeight;
_kalman = kalman; _kalman = kalman;
_lostFreezeFrames = lostFreezeFrames;
_cameraEasing = cameraEasing;
_cameraCenter = new Point2f(videoWidth / 2f, videoHeight / 2f); _cameraCenter = new Point2f(videoWidth / 2f, videoHeight / 2f);
_state = TrackState.Tracking; _state = TrackState.Tracking;
_kalman.Reset(_cameraCenter); _kalman.Reset(_cameraCenter);
} }
@ -100,7 +96,7 @@ public sealed class CameraController
{ {
_lostFrames++; _lostFrames++;
if (_lostFrames <= _lostFreezeFrames) if (_lostFrames <= LostFreezeFrames)
{ {
_state = TrackState.LostFreeze; _state = TrackState.LostFreeze;
objectCenter = null; objectCenter = null;
@ -132,16 +128,10 @@ public sealed class CameraController
smoothedCenter.Y * (1 - EmaFactor) + _cameraCenter.Y * EmaFactor smoothedCenter.Y * (1 - EmaFactor) + _cameraCenter.Y * EmaFactor
); );
// fast easing
float fastEasing = 0.015f;
_cameraCenter = new Point2f( _cameraCenter = new Point2f(
_cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * fastEasing, _cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * CameraEasing,
_cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * fastEasing); _cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * CameraEasing);
// configurable easing
_cameraCenter = new Point2f(
_cameraCenter.X + (smoothedCenter.X - _cameraCenter.X) * _cameraEasing,
_cameraCenter.Y + (smoothedCenter.Y - _cameraCenter.Y) * _cameraEasing);
} }
else if (_state == TrackState.LostFreeze) else if (_state == TrackState.LostFreeze)
{ {

View File

@ -1,6 +1,14 @@
{ {
"profiles": { "profiles": {
"splitter": { "WSL": {
"commandName": "WSL2",
"distributionName": ""
},
"Prod": {
"commandName": "Project",
"commandLineArgs": "\"C:\\Users\\uncls\\Pictures\\2026\\2026 - Secret Rule\\20260426_212004.mp4\" \"C:\\Users\\uncls\\Pictures\\2026\\2026 - Secret Rule\\Shorts\" --crop --detect=body"
},
"Debug": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "\"C:\\Users\\uncls\\Pictures\\2026\\2026 - Secret Rule\\20260426_212004.mp4\" \"C:\\Users\\uncls\\Pictures\\2026\\2026 - Secret Rule\\Shorts\" --crop --detect=body --debug --text" "commandLineArgs": "\"C:\\Users\\uncls\\Pictures\\2026\\2026 - Secret Rule\\20260426_212004.mp4\" \"C:\\Users\\uncls\\Pictures\\2026\\2026 - Secret Rule\\Shorts\" --crop --detect=body --debug --text"
} }

View File

@ -12,9 +12,6 @@ public class TrackingSplitter(
Action<double /*percent*/, TimeSpan /*duration*/, double /*fps*/> drawProgress Action<double /*percent*/, TimeSpan /*duration*/, double /*fps*/> drawProgress
) : LoggingBase(log, drawProgress) ) : LoggingBase(log, drawProgress)
{ {
private const int LostFreezeFrames = 60; // 2 seconds at 30 FPS
private const float CameraEasing = 0.03f;
public async Task TrackAndExtract( public async Task TrackAndExtract(
string srcFileName, string srcFileName,
string destFileName, string destFileName,
@ -70,9 +67,8 @@ public class TrackingSplitter(
videoHeight, videoHeight,
originalCropWidth, originalCropWidth,
originalCropHeight, originalCropHeight,
kalman, kalman
LostFreezeFrames, );
CameraEasing);
var startTime = DateTime.UtcNow; var startTime = DateTime.UtcNow;