I greatly appreciate your consistent and helpful support. I have a follow-up question regarding the article you provided.
I’ve been attempting to simulate the transformation using the same values mentioned in the article. However, I’ve encountered a discrepancy at the general projection equation stage. According to the article, the output coordinates x and y should be in the range of <-0.5, 0.5>. In my simulation, the y-coordinate falls outside this range.
Here is the code:
import numpy as np
# Step 1: Define the camera rotation matrix (R)
R = np.array([
[-0.600806990019897, 0.799386597570746, -0.003468193376912],
[-0.210825371930633, -0.162635135620312, -0.963899618846316],
[-0.771092486861039, -0.578386445454965, 0.266243303052733]
])
# Step 2: Define the camera position in world space
position = np.array([2111.44219951044, 1607.86624656544, 2302.25896526736])
# Step 3: Calculate the translation vector (t)
t = -np.dot(R, position)
# Step 4: Create the transformation matrix (T)
T = np.hstack((R, t.reshape(3, 1)))
print(f"Camera Rotation R:\\\\n{R}")
print(f"\\\\nTranslation Vector t:\\\\n{t}")
print(f"\\\\nTransformation Matrix T:\\\\n{T}")
# Step 5: Define camera calibration parameters
focal_length_35mm = 82.2539160239028
sensor_width = 36 # Assuming 35mm equivalent
focal = focal_length_35mm * sensor_width / 36
ppU = 0.00621063808526977 # Principal point U-coordinate
ppV = -0.0214264554930412 # Principal point V-coordinate
# Step 6: Create the camera calibration matrix (K)
K = np.array([
[focal, 0, ppU],
[0, focal, ppV],
[0, 0, 1]
])
print(f"\\\\nCamera Calibration Matrix K:\\\\n{K}")
# Step 7: Define a world point (in this case, the world origin)
Pw = np.array([[0], [0], [0], [1]])
# Step 8: Transform the world point to camera coordinates
Pc = np.dot(T, Pw)
# Step 9: Project the point onto the image plane
p_uv = np.dot(K, Pc[:3])
# Step 10: Normalize the projected point
p_uv_normalized = p_uv[:2] / p_uv[2]
print(f"\\\\nNormalized Image Coordinates:\\\\n{p_uv_normalized}")
The output I’m getting is:
Normalized Image Coordinates:
[[-0.36392172]
[123.70203034]]
As you can see, the y-coordinate (123.70203034) is well outside the expected range of <-0.5, 0.5>.
Are there any problems with this code? or Is there anything wrong with the article?
Thank you once again for your time and expertise. I look forward to your response.