我正在尝试解决几个俯瞰阿拉斯加冰川的延时摄影机的姿势。到目前为止,所有估计的姿势都非常不准确。我用于真实世界坐标的单位是 UTM(东/北)和高程。我相信我的问题在于单位错误,或者世界坐标与图像坐标不匹配。
这是我的焦距和地面控制:
焦距:5740.0 像素
世界:[3.93610609e+05 6.69557833e+06 7.82287000e+02] 图片:[479. 2448.]
世界:[3.93506713e+05 6.69585564e+06 9.61337000e+02] 图片:[164. 1398.]
世界:[3.94569509e+05 6.69555068e+06 6.21075000e+02] 图片:[2812。3853.]
世界:[3.97774e+05 6.69986e+06 1.64200e+03] 图片:[6310. 1398.]
self.tvec = (393506.713,6695855.641,961.337) self.rvec = (np.radians(0),np.radians(0),np.radians(15))
def estimatePose(self):
print("Estimating Pose for ", str(self.instance),"\n")
_,self.rvec,self.tvec,_ = cv2.solvePnPRansac(self.worldGCP,self.imgGCP,self.cameraMatrix,iterationsCount=10000,distCoeffs=None,rvec=self.rvec,tvec=self.tvec,useExtrinsicGuess=1)
self.R = np.zeros((3,3))
cv2.Rodrigues(self.rvec,self.R)
angle = np.degrees(self.rotationMatrixToEulerAngles(self.R))
self.R = np.append(self.R,self.tvec,1)
self.world2img = self.cameraMatrix@self.R
def rotationMatrixToEulerAngles(self, R) :
sy = math.sqrt(R[0,0] * R[0,0] + R[1,0] * R[1,0])
singular = sy < 1e-6
if not singular :
x = math.atan2(R[2,1] , R[2,2])
y = math.atan2(-R[2,0], sy)
z = math.atan2(R[1,0], R[0,0])
else :
x = math.atan2(-R[1,2], R[1,1])
y = math.atan2(-R[2,0], sy)
z = 0
return np.array([x, y, z])
def extract_metadata(self):
self.metaData = {}
exif_info = self.image._getexif()
if exif_info:
print("Found Meta Data!","\n")
for (tag, value) in exif_info.items():
tagname = TAGS.get(tag,tag)
self.metaData[tagname] = value
self.focal_length = int(self.metaData['FocalLength'][0]/self.metaData['FocalLength'][1])*self.imagew/35.9
print("Focal :", np.round(self.focal_length), " pixels")
self.cameraMatrix = np.array([[self.focal_length,0,self.imagew/2],[0,self.focal_length,self.imageh/2],[0,0,1]])
这是我的结果:姿势(北东仰角滚动俯仰偏航):
(4221680.42,2006518.54,-4807966, 83.96,-47.243,34.061)