import cv2
import numpy as np
objectPoints = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 1, 1], [0, 1, 1]],dtype=np.float32)
imagePoints = np.array([[10, 20], [30, 50], [20, 70], [50, 40],[20, 80], [30, 40]], dtype=np.float32)
cameraMatrix = np.array([[386, 0, 327], [0, 386, 244], [0, 0, 1]], dtype=np.float32)
distCoeffs = np.array([0, 0, 0, 0, 0], dtype=np.float32)
ret, rvec, tvec = cv2.solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs)
if ret:
print("Rotation vector:\n", rvec)
print("Translation vector:\n", tvec)
else:
print("Failed to solve PnP.")