Interpretation projectPoints output
Hello! I am working on converting 3D real-world points (X,Y,Z) meters to image coordinates (u, v) pixels. I have access to the Camera matrix K, camera orientation (in degrees) and translation vector. I use the code below to calculate the pixel coordinates. For (X,Y,Z) = (0.04379281, 0.15902013, 0.73328906) I obtain (u, v) = (-184.52735432, -249.19158505). Is the origin of pixel coordinates in the image still top left corner? If yes, the obtained pixel location is outside the image. Is this right?
# Calculates Rotation Matrix given euler angles.
def eulerAnglesToRotationMatrix(theta):
R_x = np.array([[1, 0, 0],
[0, math.cos(theta[0]), -math.sin(theta[0])],
[0, math.sin(theta[0]), math.cos(theta[0])]
])
R_y = np.array([[math.cos(theta[1]), 0, math.sin(theta[1])],
[0, 1, 0],
[-math.sin(theta[1]), 0, math.cos(theta[1])]
])
R_z = np.array([[math.cos(theta[2]), -math.sin(theta[2]), 0],
[math.sin(theta[2]), math.cos(theta[2]), 0],
[0, 0, 1]
])
R = np.dot(R_z, np.dot(R_y, R_x))
return R
# x-roll, y-pitch, z-yaw (in degrees)
theta = [-128.41639709472657, -11.528900146484375, 53.37379837036133]
# rotation vector
rvec = eulerAnglesToRotationMatrix(theta)
# translation vector
tvec = np.array([[0.26409998536109927], [1.294700026512146], [0.017799999564886094]], np.float)
# camera matrix
cameraMatrix = np.array([[148.130859375, 0, 142.5562286376953],
[0, 148.130859375, 179.04293823242188],
[0, 0, 1]], np.float)
# Point in (X,Y,Z) meters
objPts = np.array([[0.04379281, 0.15902013, 0.73328906]], np.float)
distCoeffs = np.array([0, 0, 0, 0, 0], np.float)
imgPts, _ = cv2.projectPoints(objPts, rvec, tvec, cameraMatrix, distCoeffs)
imgPts : (-184.52735432 -249.19158505)