Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- """
- import sys
- from constants import *
- from numpy import *
- from surveydata import *
- class SurveyMath():
- def __init__(self):
- self.initEOP()
- self.initImagePoints()
- self.EOP, self.EOPStd, self.sigma0 = self.spaceResection(self.gps, self.pix, affPara, f, ppxo, ppyo, self.EOPo_set, 0, 0, 0, 0, 0)
- #~ self.EOPRight, self.EOPStdRight, self.sigma0Right = self.spaceResection(self.gps, self.pixR, affParaRight, fRight, ppxoRight,
- #~ ppyoRight, self.EOPo_set_right, 0, 0, 0, 0, 0)
- #~ self.spaceIntersection(self.gps, self.pixL, self.pixR, self.EOPLeft, self.EOPRight, leftIOP, rightIOP, affParaLeft, affParaRight)
- #~ self.spaceIntersection(self.gps, self.pix
- self.spaceIntersection(self.gps, self.pix, affPara, self.EOP, IOP)
- #~ print self.EOPo_set_left
- #~ print self.EOPo_set_right
- def initEOP(self):
- self.EOPo_set = array(p0_EOP, double)
- #~ self.EOPo_set_right = array(p0_right_EOP, double)
- #~ print self.EOPo_set_left[0:3]
- #~ print self.EOPo_set_right[0:3]
- self.EOPo_set[0:3] = self.EOPo_set[0:3] / 180 * pi
- #~ self.EOPo_set_right[0:3] = self.EOPo_set_right[0:3] / 180 * pi
- self.EOPo_set = self.EOPo_set[0:6]
- #~ self.EOPo_set_right = self.EOPo_set_right[0:6]
- def initImagePoints(self):
- fileImg = open('p0_leftCamA_imagePnts.txt', 'r')
- #~ fileR = open('p0_rightCam_imagePnts.txt', 'r')
- fileCtrl = open('petrieControl_NED.txt', 'r')
- pix = []
- #~ pixR = []
- gps = []
- while 1:
- line = fileImg.readline()
- #~ lineR = fileR.readline()
- lineCtrl = fileCtrl.readline()
- if not lineCtrl:
- break
- pix.append([line.split()[1], line.split()[2]])
- #~ pixR.append([lineR.split()[1], lineR.split()[2]])
- gps.append([lineCtrl.split()[1], lineCtrl.split()[2],
- lineCtrl.split()[3]])
- self.pix = array(pix, double)
- #~ self.pixR = array(pixR, double)
- self.gps = array(gps, double)
- def spaceResection(self, gps, pix, affPara, f, ppx0, ppy0, EOPo, k1, k2, k3, p1, p2):
- photoGCP = array([], double)
- length = len(gps)
- photoGCP.resize(pix.shape)
- photoGCP[:,0:1] = (affPara[1]*pix[:,0:1])+(affPara[2]*pix[:,1:2]) + affPara[0]
- photoGCP[:,1:2] = (affPara[4]*pix[:,0:1])+(affPara[5]*pix[:,1:2]) + affPara[3]
- delta = EOPo.transpose()
- tolerance = ones(len(delta), double) * 0.001
- B2 = zeros((62,6), double)
- epsilon = zeros(2*length, double)
- Xnot = EOPo
- count = 0
- while count < 50:
- row = 1
- omega = Xnot[0]
- phi = Xnot[1]
- kappa = Xnot[2]
- X1 = Xnot[3]
- Y1 = Xnot[4]
- Z1 = Xnot[5]
- M = rotation3d(omega, phi, kappa)
- i = 0
- while i < length:
- r = (M[0,0]*(gps[i,0] - X1)) + (M[0,1]*(gps[i,1] - Y1)) + (M[0,2]*(gps[i,2] - Z1))
- s = (M[1,0]*(gps[i,0] - X1)) + (M[1,1]*(gps[i,1] - Y1)) + (M[1,2]*(gps[i,2] - Z1))
- q = (M[2,0]*(gps[i,0] - X1)) + (M[2,1]*(gps[i,1] - Y1)) + (M[2,2]*(gps[i,2] - Z1))
- B2[(2*(i+1)-1)-1,0] = (f/(q**2))*((r*((-M[2,2]*(gps[i,1] - Y1))+
- (M[2,1]*(gps[i,2] - Z1))))-(q*((-M[0,2]*(gps[i,1] - Y1))+
- (M[0,1]*(gps[i,2] - Z1)))))
- B2[(2*(i+1)-1)-1,1] = (f/(q**2))*((r*((cos(phi)*(gps[i,0] - X1))+
- (sin(omega)*sin(phi)*(gps[i,1] - Y1)) - (cos(omega)*sin(phi)*
- (gps[i,2] - Z1))))-(q*((-sin(phi)*cos(kappa)*(gps[i,0] - X1))+
- (sin(omega)*cos(phi)*cos(kappa)*(gps[i,1] - Y1)) - (cos(omega)*
- cos(phi)*cos(kappa)*(gps[i,2] - Z1)))))
- B2[(2*(i+1)-1)-1,2] = (-f/q)*((M[1,0]*(gps[i,0] - X1))+(M[1,1]*
- (gps[i,1] - Y1))+(M[1,2]*(gps[i,2] - Z1)))
- B2[(2*(i+1)-1)-1,3] = -(f/(q**2))*((r*M[2,0]) - (q*M[0,0]))
- B2[(2*(i+1)-1)-1,4] = -(f/(q**2))*((r*M[2,1]) - (q*M[0,1]))
- B2[(2*(i+1)-1)-1,5] = -(f/(q**2))*((r*M[2,2]) - (q*M[0,2]))
- B2[2*(i+1)-1,0] = (f/(q**2))* ((s*((-M[2,2]*(gps[i,1] - Y1))+(M[2,1]*
- (gps[i,2] - Z1))))-(q*((-M[1,2]*(gps[i,1] - Y1))+(M[1,1]*
- (gps[i,2] - Z1)))))
- B2[2*(i+1)-1,1] = (f/(q**2))*((s*((cos(phi)*(gps[i,0] - X1))+
- (sin(omega)*sin(phi)*(gps[i,1] - Y1)) - (cos(omega)*sin(phi)*
- (gps[i,2] - Z1))))-(q*((sin(phi)*sin(kappa)*(gps[i,0] - X1))-
- (sin(omega)*cos(phi)*sin(kappa)*(gps[i,1] - Y1)) + (cos(omega)*
- cos(phi)*sin(kappa)*(gps[i,2] - Z1)))))
- B2[2*(i+1)-1,2] = (f/q)*((M[0,0]*(gps[i,0] - X1))+(M[0,1]*(gps[i,1] - Y1))
- +(M[0,2]*(gps[i,2] - Z1)))
- B2[2*(i+1)-1,3] = -(f/(q**2))*((s*M[2,0]) - (q*M[1,0]))
- B2[2*(i+1)-1,4] = -(f/(q**2))*((s*M[2,1]) - (q*M[1,1]))
- B2[2*(i+1)-1,5] = -(f/(q**2))*((s*M[2,2]) - (q*M[1,2]))
- rDist2 = ((photoGCP[i,0]**2)+(photoGCP[i,1]**2));
- deltaX = photoGCP[i,0]*rDist2*(k1+rDist2*(k2+rDist2*k3)) + p1*(rDist2+(2*photoGCP[i,0]**2)) + 2*p2*photoGCP[i,0]*photoGCP[i,1]
- deltaY = photoGCP[i,1]*rDist2*(k1+rDist2*(k2+rDist2*k3)) + p1*(rDist2+ (2*photoGCP[i,1]**2)) + 2*p2*photoGCP[i,0]*photoGCP[i,1]
- epsilon[(2*(i+1)-1)-1] = photoGCP[i,0] - ppx0 + (f*(r/q)) + deltaX
- epsilon[2*(i+1)-1] = photoGCP[i,1] - ppy0 + (f*(s/q)) + deltaY
- i +=1
- delta = dot(linalg.inv(dot(B2.transpose(), B2)), dot(B2.transpose(), epsilon.transpose()))
- Xnot += delta
- count += 1
- EOP = Xnot
- sigma0 = dot(epsilon, epsilon.transpose())
- EOPstd = sqrt(sigma0*(diag(linalg.inv(dot(B2.transpose(), B2)))))
- return EOP, EOPstd, sigma0
- def spaceIntersection(self, gps, pix, affPara, EOP, IOP):
- X = EOP[3]
- Y = EOP[4]
- Z = EOP[5]
- M = rotation3d(EOP[0],EOP[1],EOP[2])
- f = IOP[0]
- ppxo = IOP[1]
- ppyo = IOP[2]
- k1 = IOP[3]
- k2 = IOP[4]
- k3 = IOP[5]
- p1 = IOP[6]
- p2 = IOP[7]
- photo = array([], double)
- length = len(gps)
- photo.resize(pix.shape)
- photo[:,0:1] = (affPara[1]*pix[:,0:1])+(affPara[2]*pix[:,1:2]) + affPara[0]
- photo[:,1:2] = (affPara[4]*pix[:,0:1])+(affPara[5]*pix[:,1:2]) + affPara[3]
- for i in range(0,20):
- print i
- #~ def spaceIntersection(self, gps, pixL, pixR, EOPleft, EOPright, IOPleft, IOPright, affParaLeft, affParaRight):
- #~ X_left = EOPleft[3]
- #~ Y_left = EOPleft[4]
- #~ Z_left = EOPleft[5]
- #~
- #~ X_right = EOPright[3]
- #~ Y_right = EOPright[4]
- #~ Z_right = EOPright[5]
- #~
- #~ M_left = rotation3d(EOPleft[0],EOPleft[1],EOPleft[2])
- #~ M_right = rotation3d(EOPright[0],EOPright[1],EOPright[2])
- #~
- #~ fLeft = IOPleft[0]
- #~ ppxoLeft = IOPleft[1]
- #~ ppyoLeft = IOPleft[2]
- #~ k1Left = IOPleft[3]
- #~ k2Left = IOPleft[4]
- #~ k3Left = IOPleft[5]
- #~ p1Left = IOPleft[6]
- #~ p2Left = IOPleft[7]
- #~
- #~ fRight = IOPright[0]
- #~ ppxoRight = IOPright[1]
- #~ ppyoRight = IOPright[2]
- #~ k1Right = IOPright[3]
- #~ k2Right = IOPright[4]
- #~ k3Right = IOPright[5]
- #~ p1Right = IOPright[6]
- #~ p2Right = IOPright[7]
- #~
- #~ photoLeft = array([], double)
- #~ photoRight = array([], double)
- #~
- #~ length = len(gps)
- #~ photoLeft.resize(pixL.shape)
- #~ photoRight.resize(pixR.shape)
- #~
- #~ photoLeft[:,0:1] = (affParaLeft[1]*pixL[:,0:1])+(affParaLeft[2]*pixL[:,1:2]) + affParaLeft[0]
- #~ photoLeft[:,1:2] = (affParaLeft[4]*pixL[:,0:1])+(affParaLeft[5]*pixL[:,1:2]) + affParaLeft[3]
- #~
- #~ photoRight[:,0:1] = (affParaRight[1]*pixR[:,0:1])+(affParaRight[2]*pixR[:,1:2]) + affParaRight[0]
- #~ photoRight[:,1:2] = (affParaRight[4]*pixR[:,0:1])+(affParaRight[5]*pixR[:,1:2]) + affParaRight[3]
- #~
- #~ B1 = zeros((length,2, 3), double)
- #~ B2 = zeros((length,2, 3), double)
- #~ B = zeros((length, 4, 3), double)
- #~ epsilon1 = zeros((length, 2, 1))
- #~ epsilon2 = zeros((length, 2, 1))
- #~ epsilon = zeros((length, 4, 1))
- #~
- #~
- #~ i = 0
- #~ while i < 50:
- #~ Brow = 1
- #~ r1 = (M_left[0,0]*(gps[:,0:1] - X_left)) + (M_left[0,1]*(gps[:,1:2] - Y_left)) + (M_left[0,2]*(gps[:,2:3] - Z_left))
- #~ s1 = (M_left[1,0]*(gps[:,0:1] - X_left)) + (M_left[1,1]*(gps[:,1:2] - Y_left)) + (M_left[1,2]*(gps[:,2:3] - Z_left))
- #~ q1 = (M_left[2,0]*(gps[:,0:1] - X_left)) + (M_left[2,1]*(gps[:,1:2] - Y_left)) + (M_left[2,2]*(gps[:,2:3] - Z_left))
- #~
- #~ B1[:,2*Brow-1-1,0:1] = (fLeft/(q1**2))*((r1*M_left[2,0])-(q1*M_left[0,0]))
- #~ B1[:,2*Brow-1-1,1:2]= (fLeft/(q1**2))*((r1*M_left[2,1])-(q1*M_left[0,1]))
- #~ B1[:,2*Brow-1-1,2:3] = (fLeft/(q1**2))*((r1*M_left[2,2])-(q1*M_left[0,2]))
- #~
- #~ B1[:,2*Brow-1,0:1] = (fLeft/(q1**2))*((s1*M_left[2,0])-(q1*M_left[1,0]))
- #~ B1[:,2*Brow-1,1:2] = (fLeft/(q1**2))*((s1*M_left[2,1])-(q1*M_left[1,1]))
- #~ B1[:,2*Brow-1,2:3] = (fLeft/(q1**2))*((s1*M_left[2,2])-(q1*M_left[1,2]))
- #~
- #~
- #~ rDist2 = ((photoLeft[:,0:1]**2)+(photoLeft[:,1:2]**2))
- #~ deltaX = photoLeft[:,0:1]*rDist2*(k1Left+rDist2*(k2Left+rDist2*k3Left)) + p1Left*(rDist2+ (2*photoLeft[:,0:1]**2)) + 2*p2Left*photoLeft[:,0:1]*photoLeft[:,1:2]
- #~ deltaY = photoLeft[:,1:2]*rDist2*(k1Left+rDist2*(k2Left+rDist2*k3Left)) + p1Left*(rDist2+ (2*photoLeft[:,1:2]**2)) + 2*p2Left*photoLeft[:,0:1]*photoLeft[:,1:2]
- #~
- #~
- #~ epsilon1[:,2*Brow-1-1,0:1] = photoLeft[:,0:1] - ppxoLeft + (fLeft*(r1/q1)) + deltaX #pnt(Brow,1) - ppx01 + (fLeft*(r1/q1));
- #~ epsilon1[:,2*Brow-1,0:1] = photoLeft[:,1:2] - ppyoLeft + (fLeft*(s1/q1)) + deltaY #pnt(Brow,2) - ppy01 + (fLeft*(s1/q1));
- #~
- #~ r2 = (M_right[0,0]*(gps[:,0:1] - X_right)) + (M_right[0,1]*(gps[:,1:2] - Y_right)) + (M_right[0,2]*(gps[:,2:3] - Z_right))
- #~ s2 = (M_right[1,0]*(gps[:,0:1] - X_right)) + (M_right[1,1]*(gps[:,1:2] - Y_right)) + (M_right[1,2]*(gps[:,2:3] - Z_right))
- #~ q2 = (M_right[2,0]*(gps[:,0:1] - X_right)) + (M_right[2,1]*(gps[:,1:2] - Y_right)) + (M_right[2,2]*(gps[:,2:3] - Z_right))
- #~
- #~ B2[:,2*Brow-1-1,0:1] = (fRight/(q1**2))*((r2*M_right[2,0])-(q2*M_right[0,0]))
- #~ B2[:,2*Brow-1-1,1:2]= (fRight/(q1**2))*((r2*M_right[2,1])-(q2*M_right[0,1]))
- #~ B2[:,2*Brow-1-1,2:3] = (fRight/(q1**2))*((r2*M_right[2,2])-(q2*M_right[0,2]))
- #~
- #~ B2[:,2*Brow-1,0:1] = (fRight/(q2**2))*((s2*M_right[2,0])-(q2*M_right[1,0]))
- #~ B2[:,2*Brow-1,1:2] = (fRight/(q2**2))*((s2*M_right[2,1])-(q2*M_right[1,1]))
- #~ B2[:,2*Brow-1,2:3] = (fRight/(q2**2))*((s2*M_right[2,2])-(q2*M_right[1,2]))
- #~
- #~ rDist2 = ((photoRight[:,0:1]**2)+(photoRight[:,1:2]**2))
- #~ deltaX = photoRight[:,0:1]*rDist2*(k1Right+rDist2*(k2Right+rDist2*k3Right)) + p1Right*(rDist2+ (2*photoRight[:,0:1]**2)) + 2*p2Right*photoRight[:,0:1]*photoRight[:,1:2]
- #~ deltaY = photoRight[:,1:2]*rDist2*(k1Right+rDist2*(k2Right+rDist2*k3Right)) + p1Right*(rDist2+ (2*photoRight[:,1:2]**2)) + 2*p2Right*photoRight[:,0:1]*photoRight[:,1:2]
- #~
- #~ epsilon2[:,2*Brow-1-1,0:1] = photoRight[:,0:1] - ppyoRight + (fRight*(r2/q2)) + deltaX #pnt(Brow,1) - ppx01 + (fLeft*(r1/q1));
- #~ epsilon2[:,2*Brow-1,0:1] = photoRight[:,1:2] - ppyoRight + (fRight*(s2/q2)) + deltaY #pnt(Brow,2) - ppy01 + (fLeft*(s1/q1));
- #~
- #~
- #~ B[:,0:2,:] = B1
- #~ B[:,2:4,:] = B2
- #~
- #~ epsilon[:,0:2,:] = epsilon1
- #~ epsilon[:,2:4,:] = epsilon2
- #~ x = 0
- #~ while x < length:
- #~ b = B[x]
- #~ e = epsilon[x]
- #~ deltaX = dot(dot(linalg.inv(dot(b.T, b)), b.T), e)
- #~ gps[x] += deltaX
- #~
- #~ x +=1
- #~
- #~
- #~ print B.transpose()
- #~ deltaX = dot(dot(linalg.inv(dot(B.transpose(), B)), B.transpose()), epsilon)
- #~
- #~ i += 1
- surveyMath = SurveyMath()
Advertisement
Add Comment
Please, Sign In to add comment