Enhance feature tracking to handle descriptor dimension mismatches
This commit updates the feature tracking logic to check for descriptor dimension mismatches when adding features to existing entries. If a mismatch is detected, existing features are replaced instead of concatenated, ensuring data integrity. Additionally, debug messages have been added to provide better insights during the feature extraction process, improving overall user experience.
This commit is contained in:
@@ -136,11 +136,19 @@ class FeatureTracker:
|
||||
|
||||
# Add to existing features or create new entry
|
||||
if frame_number in self.features:
|
||||
# Append to existing features
|
||||
# Check if descriptor dimensions match
|
||||
existing_features = self.features[frame_number]
|
||||
existing_features['keypoints'] = np.concatenate([existing_features['keypoints'], keypoints])
|
||||
existing_features['descriptors'] = np.concatenate([existing_features['descriptors'], descriptors])
|
||||
existing_features['positions'].extend(mapped_positions)
|
||||
if existing_features['descriptors'].shape[1] != descriptors.shape[1]:
|
||||
print(f"Warning: Descriptor dimension mismatch ({existing_features['descriptors'].shape[1]} vs {descriptors.shape[1]}). Cannot concatenate. Replacing features.")
|
||||
# Replace instead of concatenate when dimensions don't match
|
||||
existing_features['keypoints'] = keypoints
|
||||
existing_features['descriptors'] = descriptors
|
||||
existing_features['positions'] = mapped_positions
|
||||
else:
|
||||
# Append to existing features
|
||||
existing_features['keypoints'] = np.concatenate([existing_features['keypoints'], keypoints])
|
||||
existing_features['descriptors'] = np.concatenate([existing_features['descriptors'], descriptors])
|
||||
existing_features['positions'].extend(mapped_positions)
|
||||
print(f"Added {len(keypoints)} features to frame {frame_number} (total: {len(existing_features['positions'])})")
|
||||
else:
|
||||
# Create new features entry
|
||||
@@ -1293,13 +1301,14 @@ class VideoEditor:
|
||||
self.load_current_frame()
|
||||
|
||||
# Auto-extract features if feature tracking is enabled and auto-tracking is on
|
||||
print(f"DEBUG: seek_to_frame {frame_number}: is_image_mode={self.is_image_mode}, tracking_enabled={self.feature_tracker.tracking_enabled}, auto_tracking={self.feature_tracker.auto_tracking}, display_frame={self.current_display_frame is not None}")
|
||||
|
||||
if (not self.is_image_mode and
|
||||
self.feature_tracker.tracking_enabled and
|
||||
self.feature_tracker.auto_tracking and
|
||||
self.current_display_frame is not None):
|
||||
|
||||
print(f"DEBUG: Auto-tracking conditions met for frame {self.current_frame}")
|
||||
print(f"DEBUG: tracking_enabled={self.feature_tracker.tracking_enabled}, auto_tracking={self.feature_tracker.auto_tracking}")
|
||||
# Only extract if we don't already have features for this frame
|
||||
if self.current_frame not in self.feature_tracker.features:
|
||||
print(f"DEBUG: Extracting features for frame {self.current_frame}")
|
||||
@@ -2591,7 +2600,11 @@ class VideoEditor:
|
||||
|
||||
# Handle Shift+Right-click+drag for selective feature extraction
|
||||
if event == cv2.EVENT_RBUTTONDOWN and (flags & cv2.EVENT_FLAG_SHIFTKEY):
|
||||
if not self.is_image_mode and self.feature_tracker.tracking_enabled:
|
||||
if not self.is_image_mode:
|
||||
# Enable feature tracking if not already enabled
|
||||
if not self.feature_tracker.tracking_enabled:
|
||||
self.feature_tracker.tracking_enabled = True
|
||||
self.show_feedback_message("Feature tracking enabled")
|
||||
self.selective_feature_extraction_start = (x, y)
|
||||
self.selective_feature_extraction_rect = None
|
||||
print(f"DEBUG: Started selective feature extraction at ({x}, {y})")
|
||||
@@ -2604,7 +2617,7 @@ class VideoEditor:
|
||||
|
||||
# Handle Shift+Right-click release for selective feature extraction
|
||||
if event == cv2.EVENT_RBUTTONUP and (flags & cv2.EVENT_FLAG_SHIFTKEY) and self.selective_feature_extraction_start:
|
||||
if not self.is_image_mode and self.feature_tracker.tracking_enabled and self.selective_feature_extraction_rect:
|
||||
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
|
||||
|
Reference in New Issue
Block a user