This commit is contained in:
2025-09-26 17:56:28 +02:00
parent e823a11929
commit 151744d144

View File

@@ -1683,17 +1683,34 @@ class VideoEditor:
template_offset = None template_offset = None
if self.template_matching_enabled and self.tracking_template is not None: if self.template_matching_enabled and self.tracking_template is not None:
if self.current_display_frame is not None: if self.current_display_frame is not None:
# Apply motion tracking offset to the frame before template matching # Use only the cropped region for much faster template matching
# This ensures template matching works on the offset frame if self.crop_rect:
offset_frame = self._apply_motion_tracking_offset(self.current_display_frame, base_pos) crop_x, crop_y, crop_w, crop_h = self.crop_rect
if offset_frame is not None: # Extract only the cropped region from raw frame
result = self.track_template(offset_frame) cropped_frame = self.current_display_frame[crop_y:crop_y+crop_h, crop_x:crop_x+crop_w]
if result: if cropped_frame is not None and cropped_frame.size > 0:
center_x, center_y, confidence = result # Apply motion tracking offset to the cropped frame
print(f"DEBUG: Template match found at ({center_x}, {center_y}) with confidence {confidence:.2f}") offset_frame = self._apply_motion_tracking_offset(cropped_frame, base_pos)
if offset_frame is not None:
# Track template in cropped and offset frame (much faster!)
result = self.track_template(offset_frame)
if result:
center_x, center_y, confidence = result
print(f"DEBUG: Template match found at ({center_x}, {center_y}) with confidence {confidence:.2f}")
# Template matching returns coordinates in offset frame space # Map from cropped frame coordinates to raw frame coordinates
template_offset = (center_x, center_y) # Add crop offset back
raw_x = center_x + crop_x
raw_y = center_y + crop_y
template_offset = (raw_x, raw_y)
else:
# No crop - use full frame with offset
offset_frame = self._apply_motion_tracking_offset(self.current_display_frame, base_pos)
if offset_frame is not None:
result = self.track_template(offset_frame)
if result:
center_x, center_y, confidence = result
template_offset = (center_x, center_y)
# Calculate offset from feature tracking if enabled # Calculate offset from feature tracking if enabled
feature_offset = None feature_offset = None
@@ -1833,13 +1850,32 @@ class VideoEditor:
# Get base position for motion tracking offset # Get base position for motion tracking offset
base_pos = self._get_manual_tracking_position(frame_number) base_pos = self._get_manual_tracking_position(frame_number)
# Apply motion tracking offset to the frame before template matching # Use only the cropped region for much faster template matching
offset_frame = self._apply_motion_tracking_offset(self.current_display_frame, base_pos) if self.crop_rect:
if offset_frame is not None: crop_x, crop_y, crop_w, crop_h = self.crop_rect
result = self.track_template(offset_frame) # Extract only the cropped region from raw frame
if result: cropped_frame = self.current_display_frame[crop_y:crop_y+crop_h, crop_x:crop_x+crop_w]
center_x, center_y, confidence = result if cropped_frame is not None and cropped_frame.size > 0:
return (center_x, center_y, confidence) # Apply motion tracking offset to the cropped frame
offset_frame = self._apply_motion_tracking_offset(cropped_frame, base_pos)
if offset_frame is not None:
# Track template in cropped and offset frame (much faster!)
result = self.track_template(offset_frame)
if result:
center_x, center_y, confidence = result
# Map from cropped frame coordinates to raw frame coordinates
# Add crop offset back
raw_x = center_x + crop_x
raw_y = center_y + crop_y
return (raw_x, raw_y, confidence)
else:
# No crop - use full frame with offset
offset_frame = self._apply_motion_tracking_offset(self.current_display_frame, base_pos)
if offset_frame is not None:
result = self.track_template(offset_frame)
if result:
center_x, center_y, confidence = result
return (center_x, center_y, confidence)
return None return None