Now actually do the thing the previous commit claims to do

This commit is contained in:
2025-11-04 12:30:44 +01:00
parent 24dc67b8ca
commit 91165056d7

View File

@@ -3772,29 +3772,29 @@ class VideoEditor:
if flags & cv2.EVENT_FLAG_CTRLKEY and event == cv2.EVENT_LBUTTONDOWN: if flags & cv2.EVENT_FLAG_CTRLKEY and event == cv2.EVENT_LBUTTONDOWN:
self.zoom_center = (x, y) self.zoom_center = (x, y)
# Handle Shift+Right-click+drag for selective feature extraction # Handle shift+right-click for placing tracking point at previous tracking point position
if event == cv2.EVENT_RBUTTONDOWN and (flags & cv2.EVENT_FLAG_SHIFTKEY): if event == cv2.EVENT_RBUTTONDOWN and (flags & cv2.EVENT_FLAG_SHIFTKEY) and not (flags & cv2.EVENT_FLAG_CTRLKEY):
if not self.is_image_mode: if not self.is_image_mode:
# Enable feature tracking if not already enabled # Get previous tracking point position
if not self.feature_tracker.tracking_enabled: prev_result = self._get_previous_tracking_point()
self.feature_tracker.tracking_enabled = True if prev_result:
self.show_feedback_message("Feature tracking enabled") prev_frame, prev_points = prev_result
self.selective_feature_extraction_start = (x, y) if prev_points:
self.selective_feature_extraction_rect = None # Use the first tracking point from the previous frame
print(f"DEBUG: Started selective feature extraction at ({x}, {y})") prev_x, prev_y = prev_points[0]
# Handle Shift+Right-click+drag for selective feature extraction # Add tracking point at same position on current frame
if event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_SHIFTKEY) and self.selective_feature_extraction_start: self.tracking_points.setdefault(self.current_frame, []).append((int(prev_x), int(prev_y)))
if not self.is_image_mode: print(f"DEBUG: Added tracking point at previous position ({prev_x}, {prev_y}) on frame {self.current_frame}")
start_x, start_y = self.selective_feature_extraction_start self.show_feedback_message("Tracking point added at previous position")
self.selective_feature_extraction_rect = (min(start_x, x), min(start_y, y), abs(x - start_x), abs(y - start_y))
# Handle Shift+Right-click release for selective feature extraction self.clear_transformation_cache()
if event == cv2.EVENT_RBUTTONUP and (flags & cv2.EVENT_FLAG_SHIFTKEY) and self.selective_feature_extraction_start: self.save_state()
if not self.is_image_mode and self.selective_feature_extraction_rect: self.display_current_frame()
self._extract_features_from_region(self.selective_feature_extraction_rect) else:
self.selective_feature_extraction_start = None self.show_feedback_message("No previous tracking points found")
self.selective_feature_extraction_rect = None else:
self.show_feedback_message("No previous tracking points found")
# Handle Ctrl+Right-click+drag for selective feature deletion # Handle Ctrl+Right-click+drag for selective feature deletion
if event == cv2.EVENT_RBUTTONDOWN and (flags & cv2.EVENT_FLAG_CTRLKEY): if event == cv2.EVENT_RBUTTONDOWN and (flags & cv2.EVENT_FLAG_CTRLKEY):
@@ -3851,6 +3851,30 @@ class VideoEditor:
self.display_needs_update = True self.display_needs_update = True
# Handle right-click for selective feature extraction when mode is active
if event == cv2.EVENT_RBUTTONDOWN and not (flags & (cv2.EVENT_FLAG_CTRLKEY | cv2.EVENT_FLAG_SHIFTKEY)):
if not self.is_image_mode and hasattr(self, 'selective_feature_extraction_mode') and self.selective_feature_extraction_mode:
# Start selective feature extraction
self.selective_feature_extraction_start = (x, y)
self.selective_feature_extraction_rect = None
print(f"DEBUG: Started selective feature extraction at ({x}, {y})")
return # Don't process regular right-click functionality
# Handle mouse move for selective feature extraction
if event == cv2.EVENT_MOUSEMOVE and hasattr(self, 'selective_feature_extraction_start') and self.selective_feature_extraction_start:
if not self.is_image_mode:
start_x, start_y = self.selective_feature_extraction_start
self.selective_feature_extraction_rect = (min(start_x, x), min(start_y, y), abs(x - start_x), abs(y - start_y))
self.display_needs_update = True
# Handle mouse release for selective feature extraction
if event == cv2.EVENT_RBUTTONUP and hasattr(self, 'selective_feature_extraction_start') and self.selective_feature_extraction_start:
if not self.is_image_mode and self.selective_feature_extraction_rect:
self._extract_features_from_region(self.selective_feature_extraction_rect)
self.selective_feature_extraction_start = None
self.selective_feature_extraction_rect = None
self.display_needs_update = True
# Handle right-click for tracking points (no modifiers) # Handle right-click for tracking points (no modifiers)
if event == cv2.EVENT_RBUTTONDOWN and not (flags & (cv2.EVENT_FLAG_CTRLKEY | cv2.EVENT_FLAG_SHIFTKEY)): if event == cv2.EVENT_RBUTTONDOWN and not (flags & (cv2.EVENT_FLAG_CTRLKEY | cv2.EVENT_FLAG_SHIFTKEY)):
if not self.is_image_mode: if not self.is_image_mode:
@@ -5124,17 +5148,21 @@ class VideoEditor:
self.show_feedback_message(f"Detector switched to {new_type}") self.show_feedback_message(f"Detector switched to {new_type}")
self.save_state() self.save_state()
elif key == ord("z"): elif key == ord("z"):
# Switch detector type (SIFT -> ORB -> SIFT) - SURF not available # Toggle selective feature extraction mode
current_type = self.feature_tracker.detector_type if not self.is_image_mode:
if current_type == 'SIFT': if not hasattr(self, 'selective_feature_extraction_mode'):
new_type = 'ORB' self.selective_feature_extraction_mode = False
elif current_type == 'ORB':
new_type = 'SIFT' self.selective_feature_extraction_mode = not self.selective_feature_extraction_mode
else: if self.selective_feature_extraction_mode:
new_type = 'SIFT' self.show_feedback_message("Selective feature extraction mode ON - Right-click and drag to select region")
self.feature_tracker.set_detector_type(new_type) # Enable feature tracking if not already enabled
self.show_feedback_message(f"Detector switched to {new_type}") if not self.feature_tracker.tracking_enabled:
self.save_state() self.feature_tracker.tracking_enabled = True
self.show_feedback_message("Feature tracking enabled")
else:
self.show_feedback_message("Selective feature extraction mode OFF")
self.save_state()
elif key == ord("o"): elif key == ord("o"):
# Toggle optical flow tracking # Toggle optical flow tracking
self.optical_flow_enabled = not self.optical_flow_enabled self.optical_flow_enabled = not self.optical_flow_enabled