diff --git a/croppa/main.py b/croppa/main.py index 85f7464..da89614 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -2252,10 +2252,6 @@ class VideoEditor: def track_template(self, frame): """Track the template in the current frame""" - # First, try to select the best template for current frame - if not self._select_best_template_for_frame(self.current_frame): - return None - if self.tracking_template is None: return None @@ -2444,10 +2440,11 @@ class VideoEditor: 'end_frame': end_frame } - # Set as current template + # Set as current template and enable template matching self.current_template_id = template_id self.tracking_template = template.copy() self.template_region = region + self.template_matching_enabled = True # Enable template matching when template is created self.show_feedback_message(f"Template {template_id} added (frames {start_frame}-{end_frame})") return template_id @@ -2460,6 +2457,13 @@ class VideoEditor: # If we removed the current template, find a new one if self.current_template_id == template_id: self._select_best_template_for_frame(self.current_frame) + + # If no templates left, disable template matching + if not self.templates: + self.template_matching_enabled = False + self.tracking_template = None + self.template_region = None + self.current_template_id = None self.show_feedback_message(f"Template {template_id} removed") return True @@ -3308,22 +3312,6 @@ class VideoEditor: conf_text = f"{confidence:.2f}" cv2.putText(canvas, conf_text, (sx + 10, sy - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1) - # Draw template dots for all templates - if not self.is_image_mode and self.templates: - for template_id, template_data in self.templates.items(): - # Only draw if this template covers the current frame - if (template_data['start_frame'] <= self.current_frame <= template_data['end_frame']): - # Get template center position from region - x, y, w, h = template_data['region'] - center_x = x + w // 2 - center_y = y + h // 2 - - # Map to screen coordinates - sx, sy = self._map_rotated_to_screen(center_x, center_y) - - # Draw template dot (same style as motion tracking points) - cv2.circle(canvas, (sx, sy), 6, (0, 255, 0), -1) # Green circle - cv2.circle(canvas, (sx, sy), 6, (255, 255, 255), 1) # White border # Draw selection rectangles for feature extraction/deletion if self.selective_feature_extraction_rect: