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.
This commit is contained in:
@@ -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
|
||||
positions.append(base_pos)
|
||||
print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})")
|
||||
|
||||
# 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 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 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
|
||||
# Add feature tracking position
|
||||
if feature_offset:
|
||||
positions.append(feature_offset)
|
||||
print(f"DEBUG: Feature tracking: ({feature_offset[0]:.1f}, {feature_offset[1]:.1f})")
|
||||
|
||||
# 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)
|
||||
# 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:
|
||||
|
Reference in New Issue
Block a user