I’m working on a project to detect an object in a picture and further make different measurements on that object. For that I need to know where my camera is located. My camera is on a fixed location. So I only need to calculate that position once. Also I can make sure that I know the translation vector and also the yaw of my camera.

I just need to calculate pitch and roll. For this I’m currently using Solvepnp. So it’s the following code:

_, rvec, tvec, inliers = cv2.solvePnPRansac(objectPoints, imagePoints, mtx, distCoeffs,1, cv2.SOLVEPNP_EPNP)

Rt = cv2.Rodrigues(rvec)[0]

R = np.transpose(Rt)

r=math.atan2(R[2][1],R[2][2])*180/math.pi

p=math.atan2(-R[2][0],(math.sqrt(math.pow(R[2][1],2)+math.pow(R[2][2],2))))*180/math.pi

ya=math.atan2(R[1][0],R[0][0])*180/math.pi

As the result I get:

r=4.931548525789813, p=3.384411149422294, ya=179.73325314324563

I’m using 12 points which are located on a plane in the image (so actually z=0 for every coordinate). It’s not possible to use more points. The result is not precise enough, so I can’t make sure my measurement later has the precision I need.

I need to make my algorithm more precise. As im pretty new in coding and especially computer vision, I may miss some experience. So my question is:

Is there a way to make it more precise? Is there another method because I have a fixed translation?

Thanks for any help