崔中浩
2022-01-26 23:24
采纳率: 0%
浏览 251
已结题

大疆无人机世界坐标系转像素坐标系

我想把实地的地物点标注到大疆无人机拍摄的照片上,用的是cgcs2000坐标系,我将坐标输入,返回的像素坐标和实际的地物点不能匹配上
import numpy as np
import math
from pyexiv2 import Image
import cv2
#获取了像片拍摄时云台的姿态角
def readJpgXmp(path):
 
    file_name = path
    test = Image(file_name)
    f = test.read_xmp()
    lat = f["Xmp.drone-dji.GpsLatitude"] #纬度
    lon = f["Xmp.drone-dji.GpsLongitude"] # 经度
    height = f["Xmp.drone-dji.AbsoluteAltitude"] #
    roll = f["Xmp.drone-dji.GimbalRollDegree"] #roll
    yaw = f["Xmp.drone-dji.GimbalYawDegree"] # yaw
    pitch = f["Xmp.drone-dji.GimbalPitchDegree"] # pitch
    return float(roll),float(yaw),float(pitch)
#姿态角导入到下面的函数中创建旋转矩阵
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, R_y, R_x)
    return R
#计算相机的内参
def neican(pix,size,f):
    #8194*5460 #像片的尺寸(像素)
    #35.9*24 # cmos的尺寸(毫米)
    #35 #焦距(毫米)
    u0 = pix[0]/2
    v0 = pix[1]/2
    dx = size[0]/pix[0]
    dy = size[1]/pix[1]
    fx = f/dx
    fy = f/dy
    return np.array([[fx, 0, u0], [0, fy, v0], [0, 0, 1]])
#读取像片的姿态角 roll,yaw,pitch
xmpInfo = readJpgXmp(r'C:\Users\Administrator\Desktop\DJI_20210521160101_0211.JPG')
roll,yaw,pitch = xmpInfo
#旋转矩阵
r = eulerAnglesToRotationMatrix([math.radians(roll),math.radians(pitch),math.radians(yaw)]) #旋转矩阵
print(r)
#平移矩阵
t = np.array([[511914.760791,3372600.750728,231]]).T
#内参矩阵
ins = neican([8194,5460],[35.9,24],35)#内参
#世界坐标系中的地物点
list1 = np.float32([[511914.760791,3372600.750728,0]]) #3d点
#将地物点,旋转矩阵,平移矩阵,内参,传入 cv2.projectPoints()函数里
result2, _ = cv2.projectPoints(list1,r,t,ins,0)

print(result2)

返回的像素坐标不是我想要对应的地物点,请问是什么原因呢?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

10条回答 默认 最新

相关推荐 更多相似问题