Refactor template matching logic in VideoEditor to utilize transformed frames
This commit updates the template matching process in the VideoEditor to apply tracking on the already transformed frame, which includes crop, zoom, and rotation adjustments. This change enhances tracking accuracy by ensuring that the template can locate the object in its modified position, while also improving code clarity and performance during video editing sessions.
This commit is contained in:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user