From a2dc4a218662db28c5ac8005865f190e2223c375 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 26 Sep 2025 14:48:17 +0200 Subject: [PATCH] Refactor tracking position calculation in VideoEditor to compute the average of all available positions from manual, template, and feature tracking methods. This change simplifies the logic by aggregating positions instead of calculating weighted offsets, enhancing accuracy and clarity in tracking results. Debug messages have been updated to reflect the new averaging process. --- croppa/main.py | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index eb9dcc3..7a4995a 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -1696,31 +1696,30 @@ class VideoEditor: ) break - # Combine tracking methods: base + offsets + # Combine tracking methods: average of all available positions + positions = [] + + # Add manual tracking position if base_pos: - base_x, base_y = base_pos - offset_x, offset_y = 0, 0 - - # Add template matching offset - if template_offset: - template_x, template_y = template_offset - # Calculate offset from base position - offset_x += (template_x - base_x) * 0.5 # Weight template matching - offset_y += (template_y - base_y) * 0.5 - - # Add feature tracking offset - if feature_offset: - feature_x, feature_y = feature_offset - # Calculate offset from base position - offset_x += (feature_x - base_x) * 0.3 # Weight feature tracking - offset_y += (feature_y - base_y) * 0.3 - - # Apply combined offset - final_x = base_x + offset_x - final_y = base_y + offset_y - - print(f"DEBUG: Combined tracking - Base: ({base_x:.1f}, {base_y:.1f}) + Offset: ({offset_x:.1f}, {offset_y:.1f}) = Final: ({final_x:.1f}, {final_y:.1f})") - return (final_x, final_y) + positions.append(base_pos) + print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})") + + # Add template matching position + if template_offset: + positions.append(template_offset) + print(f"DEBUG: Template matching: ({template_offset[0]:.1f}, {template_offset[1]:.1f})") + + # Add feature tracking position + if feature_offset: + positions.append(feature_offset) + print(f"DEBUG: Feature tracking: ({feature_offset[0]:.1f}, {feature_offset[1]:.1f})") + + # Calculate average of all available positions + if positions: + avg_x = sum(pos[0] for pos in positions) / len(positions) + avg_y = sum(pos[1] for pos in positions) / len(positions) + print(f"DEBUG: Average of {len(positions)} positions: ({avg_x:.1f}, {avg_y:.1f})") + return (avg_x, avg_y) # Fall back to individual tracking methods if no base position if template_offset: