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
|
break
|
||||||
|
|
||||||
# Combine tracking methods: base + offsets
|
# Combine tracking methods: average of all available positions
|
||||||
|
positions = []
|
||||||
|
|
||||||
|
# Add manual tracking position
|
||||||
if base_pos:
|
if base_pos:
|
||||||
base_x, base_y = base_pos
|
positions.append(base_pos)
|
||||||
offset_x, offset_y = 0, 0
|
print(f"DEBUG: Manual tracking: ({base_pos[0]:.1f}, {base_pos[1]:.1f})")
|
||||||
|
|
||||||
# Add template matching offset
|
# Add template matching position
|
||||||
if template_offset:
|
if template_offset:
|
||||||
template_x, template_y = template_offset
|
positions.append(template_offset)
|
||||||
# Calculate offset from base position
|
print(f"DEBUG: Template matching: ({template_offset[0]:.1f}, {template_offset[1]:.1f})")
|
||||||
offset_x += (template_x - base_x) * 0.5 # Weight template matching
|
|
||||||
offset_y += (template_y - base_y) * 0.5
|
|
||||||
|
|
||||||
# Add feature tracking offset
|
# Add feature tracking position
|
||||||
if feature_offset:
|
if feature_offset:
|
||||||
feature_x, feature_y = feature_offset
|
positions.append(feature_offset)
|
||||||
# Calculate offset from base position
|
print(f"DEBUG: Feature tracking: ({feature_offset[0]:.1f}, {feature_offset[1]:.1f})")
|
||||||
offset_x += (feature_x - base_x) * 0.3 # Weight feature tracking
|
|
||||||
offset_y += (feature_y - base_y) * 0.3
|
|
||||||
|
|
||||||
# Apply combined offset
|
# Calculate average of all available positions
|
||||||
final_x = base_x + offset_x
|
if positions:
|
||||||
final_y = base_y + offset_y
|
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: Combined tracking - Base: ({base_x:.1f}, {base_y:.1f}) + Offset: ({offset_x:.1f}, {offset_y:.1f}) = Final: ({final_x:.1f}, {final_y:.1f})")
|
print(f"DEBUG: Average of {len(positions)} positions: ({avg_x:.1f}, {avg_y:.1f})")
|
||||||
return (final_x, final_y)
|
return (avg_x, avg_y)
|
||||||
|
|
||||||
# Fall back to individual tracking methods if no base position
|
# Fall back to individual tracking methods if no base position
|
||||||
if template_offset:
|
if template_offset:
|
||||||
|
Reference in New Issue
Block a user