diff --git a/croppa/main.py b/croppa/main.py index 1a70998..a8fc325 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -1248,9 +1248,21 @@ class VideoEditor: # This handles all transformations (crop, zoom, rotation) correctly display_frame = self.apply_crop_zoom_and_rotation(self.current_display_frame) if display_frame is not None: - # Store features in rotated frame coordinates (like existing motion tracking) + # Map coordinates from transformed frame to rotated frame coordinates + # Use the existing coordinate transformation system def coord_mapper(x, y): - return (int(x), int(y)) + # Map from transformed frame coordinates to screen 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 + + # Convert to screen coordinates + screen_x = x + start_x + screen_y = y + start_y + + # Use the existing coordinate transformation system + return self._map_screen_to_rotated(screen_x, screen_y) self.feature_tracker.extract_features(display_frame, self.current_frame, coord_mapper) @@ -2676,6 +2688,9 @@ class VideoEditor: self.tracking_enabled = False self.tracking_points = {} + # Reset feature tracking + self.feature_tracker.clear_features() + # Reset cut markers self.cut_start_frame = None self.cut_end_frame = None @@ -3561,13 +3576,26 @@ class VideoEditor: # This handles all transformations (crop, zoom, rotation) correctly display_frame = self.apply_crop_zoom_and_rotation(self.current_display_frame) if display_frame is not None: - # Store features in rotated frame coordinates (like existing motion tracking) - # This way we can reuse the existing display system + # Map coordinates from transformed frame to rotated frame coordinates + # Use the existing coordinate transformation system def coord_mapper(x, y): - # The transformed frame coordinates are already in the right space - # We just need to map them to rotated frame coordinates - # Since the transformed frame is what the user sees, we can use it directly - return (int(x), int(y)) + # The transformed frame coordinates are in the display frame space + # We need to map them to screen coordinates first, then use the existing + # _map_screen_to_rotated function + + # Map from transformed frame coordinates to screen coordinates + # The transformed frame is centered on the canvas + 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 + + # Convert to screen coordinates + screen_x = x + start_x + screen_y = y + start_y + + # Use the existing coordinate transformation system + return self._map_screen_to_rotated(screen_x, screen_y) success = self.feature_tracker.extract_features(display_frame, self.current_frame, coord_mapper) if success: