Refactor template tracking in VideoEditor to use raw display frame
This commit modifies the template tracking logic in the VideoEditor to utilize the raw display frame instead of applying transformations, improving accuracy in tracking. It updates the coordinate mapping to account for various rotation angles, ensuring correct positioning of the tracked template. This enhancement streamlines the tracking process and enhances overall functionality.
This commit is contained in:
@@ -1641,27 +1641,34 @@ class VideoEditor:
|
||||
# First try template matching if enabled (much better than optical flow)
|
||||
if self.template_matching_enabled and self.tracking_template is not None:
|
||||
if self.current_display_frame is not None:
|
||||
# Apply transformations to get the display frame
|
||||
display_frame = self.apply_crop_zoom_and_rotation(self.current_display_frame)
|
||||
if display_frame is not None:
|
||||
# Track template in display frame
|
||||
result = self.track_template(display_frame)
|
||||
# Use the raw display frame to avoid recursion
|
||||
raw_frame = self.current_display_frame.copy()
|
||||
if raw_frame is not None:
|
||||
# Track template in raw frame
|
||||
result = self.track_template(raw_frame)
|
||||
if result:
|
||||
center_x, center_y, confidence = result
|
||||
print(f"DEBUG: Template match found at ({center_x}, {center_y}) with confidence {confidence:.2f}")
|
||||
|
||||
# Map from display frame coordinates to rotated frame coordinates
|
||||
frame_height, frame_width = display_frame.shape[:2]
|
||||
available_height = self.window_height - (0 if self.is_image_mode else self.TIMELINE_HEIGHT)
|
||||
start_y = (available_height - frame_height) // 2
|
||||
start_x = (self.window_width - frame_width) // 2
|
||||
# Map from raw frame coordinates to rotated frame coordinates
|
||||
# We need to account for rotation and crop transformations
|
||||
if self.rotation_angle == 90:
|
||||
# 90° clockwise rotation
|
||||
rot_x = self.frame_height - center_y
|
||||
rot_y = center_x
|
||||
elif self.rotation_angle == 180:
|
||||
# 180° rotation
|
||||
rot_x = self.frame_width - center_x
|
||||
rot_y = self.frame_height - center_y
|
||||
elif self.rotation_angle == 270:
|
||||
# 270° clockwise rotation
|
||||
rot_x = center_y
|
||||
rot_y = self.frame_width - center_x
|
||||
else:
|
||||
# No rotation
|
||||
rot_x, rot_y = center_x, center_y
|
||||
|
||||
screen_x = center_x + start_x
|
||||
screen_y = center_y + start_y
|
||||
|
||||
# Map from screen coordinates to rotated frame coordinates
|
||||
rx, ry = self._map_screen_to_rotated(screen_x, screen_y)
|
||||
return (rx, ry)
|
||||
return (rot_x, rot_y)
|
||||
|
||||
# Fall back to feature tracking if enabled - but use smooth interpolation instead of averaging
|
||||
if self.feature_tracker.tracking_enabled:
|
||||
|
Reference in New Issue
Block a user