diff --git a/croppa/main.py b/croppa/main.py index 4e100d2..6c4a3f3 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -1679,15 +1679,16 @@ class VideoEditor: template_offset = None if self.template_matching_enabled and self.tracking_template is not None: if self.current_display_frame is not None: - # Apply template matching to the ORIGINAL frame (before motion tracking offset) - # This ensures the template can find the object in its original position - result = self.track_template(self.current_display_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 raw frame space - template_offset = (center_x, center_y) + # Use the already transformed frame (crop, zoom, rotation applied) + transformed_frame = self.apply_crop_zoom_and_rotation(self.current_display_frame) + if transformed_frame is not None: + result = self.track_template(transformed_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 transformed frame space + template_offset = (center_x, center_y) # Calculate offset from feature tracking if enabled feature_offset = None @@ -1781,12 +1782,13 @@ class VideoEditor: return None if self.current_display_frame is not None: - # Apply template matching to the ORIGINAL frame (before motion tracking offset) - # This ensures the template can find the object in its original position - result = self.track_template(self.current_display_frame) - if result: - center_x, center_y, confidence = result - return (center_x, center_y, confidence) + # Use the already transformed frame (crop, zoom, rotation applied) + transformed_frame = self.apply_crop_zoom_and_rotation(self.current_display_frame) + if transformed_frame is not None: + result = self.track_template(transformed_frame) + if result: + center_x, center_y, confidence = result + return (center_x, center_y, confidence) return None