本书是根据武汉大学出版社出版的第三版《摄影测量学》进行编写的单像空间后方交会程序
from numpy import *
data_list=[[1,-86.15,-68.99,36589.41,25273.32,2195.17],
[2,-53.40,82.21,37631.08,31324.51,728.69],
[3,-14.78,-76.63,39100.97,24934.98,2386.50],
[4,10.46,64.43,40426.54,30319.81,757.31]]
# 定义变量
fi, w, k = 0, 0, 0
WF_Matrix = None
Result = [0, 0, 0, 0, 0, 0] # 外方位元素所有改正数
scale = 50000
f = 0.15324
num_ite = 0
x = [0,0,0,0]
y = [0,0,0,0]
a = mat(zeros((8,6)))
L = mat(zeros((8,1)))
Rotate_Matrix = mat(zeros((3, 3)))#旋转矩阵
# 从文件中录入像点坐标和地面点坐标
image_list = [] # xianh
ground_list = []
for i in range(len(data_list)):
image_list.append([data_list[i][1]/1000, data_list[i][2]/1000])
ground_list.append([data_list[i][3], data_list[i][4],data_list[i][5]])
Xs = (ground_list[0][0]+ground_list[1][0]+ground_list[2][0]+ground_list[3][0])/4
Ys = (ground_list[0][1]+ground_list[1][1]+ground_list[2][1]+ground_list[3][1])/4
Zs = scale*f
while(True):
Rotate_Matrix[0,0] = cos(fi)*cos(k)-sin(fi)*sin(w)*sin(k)
Rotate_Matrix[0,1] = (-1.0) * cos(fi) * sin(k) - sin(fi) * sin(w) * cos(k)
Rotate_Matrix[0,2] = (-1.0) * sin(fi) * cos(w)
Rotate_Matrix[1, 0] = cos(w) * sin(k)
Rotate_Matrix[1, 1] = cos(w) * cos(k)
Rotate_Matrix[1, 2] = (-1.0) * sin(w)
Rotate_Matrix[2, 0] = sin(fi) * cos(k) + cos(fi) * sin(w) * sin(k)
Rotate_Matrix[2, 1] = (-1.0) * sin(fi) * sin(k) + cos(fi) * sin(w) * cos(k)
Rotate_Matrix[2, 2] = cos(fi) * cos(w)
for i in range(4):
x[i] = (-1.0) * f * (Rotate_Matrix[0,0] * (ground_list[i][0] - Xs) + Rotate_Matrix[1,0] * (ground_list[i][1] - Ys)
+ Rotate_Matrix[2,0] * (ground_list[i][2] - Zs)) / (Rotate_Matrix[0,2] * (ground_list[i][0] - Xs)+ Rotate_Matrix[1,2] * (ground_list[i][1] - Ys)
+ Rotate_Matrix[2,2] * (ground_list[i][2] - Zs)) # P73.5-1a
y[i] = (-1.0) * f * (Rotate_Matrix[0,1] * (ground_list[i][0] - Xs) + Rotate_Matrix[1,1] * (ground_list[i][1] - Ys)
+ Rotate_Matrix[2,1] * (ground_list[i][2] - Zs)) / (Rotate_Matrix[0,2] * (ground_list[i][0] - Xs)
+ Rotate_Matrix[1,2] * (ground_list[i][1] - Ys) + Rotate_Matrix[2,2] * (ground_list[i][2] - Zs))
L[i * 2,0] = image_list[i][0] - x[i]
L[i * 2 + 1,0] = image_list[i][1] - y[i]
a[i * 2,0] = (-1.0) * f / (Zs - ground_list[i][2])
a[i * 2,1] = 0.0
a[i * 2,2] = (-1.0) * x[i] / (Zs - ground_list[i][2])
a[i * 2,3] = (-1.0) * f * (1 + (x[i] * x[i]) / (f * f))
a[i * 2,4] = (-1.0) * x[i] * y[i] / f
a[i * 2,5] = y[i]
a[i * 2 + 1,0] = 0.0
a[i * 2 + 1,1] = a[i * 2,0]
a[i * 2 + 1,2] = (-1.0) * y[i] / (Zs - ground_list[i][2])
a[i * 2 + 1,3] = a[i * 2,4]
a[i * 2 + 1,4] = (-1.0) * f * (1 + (y[i] * y[i]) / (f * f))
a[i * 2 + 1,5] = (-1.0) * x[i]
Result = ((a.T*a).I*a.T)*L # 《摄影测量学》P.74--5-6
Xs += Result[0]
Ys += Result[1]
Zs += Result[2]
fi += Result[3]
w += Result[4]
k += Result[5]
num_ite+=1
if (fabs(Result[3]) < 1e-7)and(fabs(Result[4]) < 1e-7)and(fabs(Result[5]) < 1e-7):
break
Rotate_Matrix[0,0] = cos(fi)*cos(k) - sin(fi)*sin(w)*sin(k)
Rotate_Matrix[0,1] = (-1.0)*cos(fi)*sin(k) - sin(fi)*sin(w)*cos(k)
Rotate_Matrix[0,2] = (-1.0)*sin(fi)*cos(w)
Rotate_Matrix[1,0] = cos(w)*sin(k)
Rotate_Matrix[1,1] = cos(w)*cos(k)
Rotate_Matrix[1,2] = (-1.0)*sin(w)
Rotate_Matrix[2,0] = sin(fi)*cos(k) + cos(fi)*sin(w)*sin(k)
Rotate_Matrix[2,1] = (-1.0)*sin(fi)*sin(k) + cos(fi)*sin(w)*cos(k)
Rotate_Matrix[2,2] = cos(fi)*cos(w)
print("\n像片的外方位元素为:\n")
print('Xs:', Xs)
print('Ys:', Ys)
print('Zs:', Zs)
print('fi:', fi)
print('w:', w)
print('k:', k)
运行结果如下图所示:
像片的外方位元素为:
Xs: [[39795.44371602]]
Ys: [[27476.46418158]]
Zs: [[7572.68829823]]
fi: [[-0.00398556]]
w: [[0.00211367]]
k: [[-0.06757765]]
感兴趣的小伙伴可以到本人的资料下载里下载关于单像空间后方交会的代码程序,可以直接运行,里面有可以以文件的形式进行输入输出,还有各个外方位元素的改正数和精度评定,包括旋转矩阵的输出也有。欢迎大家下载。