From d7b7938706b0338930f98039b588d1223ff0fb53 Mon Sep 17 00:00:00 2001 From: ariva00 Date: Wed, 15 Nov 2023 10:53:30 +0100 Subject: [PATCH] Fix #92287: focal legth not correctly computed when tracking vertial videos The motion tracking always operates with horizontal sensor mapping, but conversion code form tracking camera to Blender camera was not setting the sensor fitting to Horizontal (Python code was leaving sensor fitting unchanged, C code was setting it to Auto). Additionally, the Python code was not handling camera shift, making it so non-centered optical center was not handled correctly. The reason why the code is written in two places is because C code is used when conversion from tracking camera to Blender happens after solving the motion, and the Python code is used for the "Setup Tracking Scene". It is possible to unify some code, but it is not that much of an importance at this time. Pull Request: https://projects.blender.org/blender/blender/pulls/114253 --- scripts/startup/bl_operators/clip.py | 10 ++++++++++ source/blender/blenkernel/intern/tracking.cc | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/startup/bl_operators/clip.py b/scripts/startup/bl_operators/clip.py index 442f48c76d5..de346087afa 100644 --- a/scripts/startup/bl_operators/clip.py +++ b/scripts/startup/bl_operators/clip.py @@ -609,8 +609,18 @@ class CLIP_OT_setup_tracking_scene(Operator): con.influence = 1.0 cam.sensor_width = tracking.camera.sensor_width + cam.sensor_fit = 'HORIZONTAL' cam.lens = tracking.camera.focal_length + # Convert shift from motion tracking to Blender camera. + # Note that the normalization always happens along the X axis. This is + # how the camera shift in Blender is denoted. + width = clip.size[0] + height = clip.size[1] + principal_point_px = tracking.camera.principal_point_pixels + cam.shift_x = (0.5 * width - principal_point_px[0]) / width + cam.shift_y = (0.5 * height - principal_point_px[1]) / width + @staticmethod def _setupViewport(context): sc = context.space_data diff --git a/source/blender/blenkernel/intern/tracking.cc b/source/blender/blenkernel/intern/tracking.cc index b6c9801344a..8c80cf49427 100644 --- a/source/blender/blenkernel/intern/tracking.cc +++ b/source/blender/blenkernel/intern/tracking.cc @@ -2124,7 +2124,7 @@ void BKE_tracking_camera_to_blender( float focal = tracking->camera.focal; camera->sensor_x = tracking->camera.sensor_width; - camera->sensor_fit = CAMERA_SENSOR_FIT_AUTO; + camera->sensor_fit = CAMERA_SENSOR_FIT_HOR; camera->lens = focal * camera->sensor_x / width; scene->r.xsch = width;