-
Notifications
You must be signed in to change notification settings - Fork 0
/
rejection.py
164 lines (143 loc) · 5.06 KB
/
rejection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import numpy as np
from ransac import estimate_foe
def inlier(q2,d,S,n):
foe, inlie = estimate_foe(d)
inlie = np.array(inlie)
q2 = q2[inlie]
d = d[inlie]
a = np.sqrt(d[:,0]**2 + d[:,1]**2)
dm = np.median(a, axis=0)
#print(dm)
dm = np.linalg.norm(dm)
drr = np.where(a < 1.8*dm) #and (a > 0.2*dm))
dr = d[drr]
qr = q2[drr]
'''alp = np.arctan2(dr[:,1],dr[:,0])*180/np.pi
alp_me = np.median(alp, axis=0)
# print(alp_me)
drr_alp = np.where((alp > alp_me+7.5) | (alp < alp_me-7.5) )
# print(np.shape(d))
dr_alp = dr[drr_alp]
qr_alp = qr[drr_alp]'''
# return qr, dr, foe, n
return qr, dr, foe, n
def brut_force(q2,d,S,n):
S = np.array(S)
s = S.copy()
u = np.zeros((S[0],S[1],2))
# v = np.flip(q2,1)
q = q2.copy()
d2 = d.copy()
u[np.reshape(q2[:,1],-1),np.reshape(q2[:,0],-1)] = d
S = np.intp(S/n)
foes = np.zeros((n*n,2))
i3 = 0
#all_inliners = []
ddr = np.empty((1,2),dtype=np.float32)
kd = ddr.copy()
for j in range(0,n):
for i in range(0,n):
i3 += 1
k = q2[np.where(np.all(np.array([i*S[1],j*S[0]]) <= q2,axis=1) & np.all(np.array([(i+1)*S[1],(j+1)*S[0]])>q2,axis=1)),:]
k = k[0,:,:]
d_rob = u[np.reshape(k[:,1],-1),np.reshape(k[:,0],-1)]
if d_rob.size <= 2:
# print("break")
continue
foe, inliers = estimate_foe(d_rob)
foes[i3-1,:] = np.array(foe) + np.array([(i+0.5)*S[1],(j+0.5)*S[0]])
inliers = np.array(inliers) #+ np.array([(j+1)*S[0],(i+1)*S[1]])
#print(i+j)
if i+j == 0:
#all_inliers = inliers
ddr = d_rob[inliers]
kd = k[inliers]
else:
#all_inliers = all_inliers + inliers
ddr = np.concatenate((ddr,d_rob[inliers]),axis=0)
kd = np.concatenate((kd,k[inliers]),axis=0)
#print(type(all_inliers))
#print(foes)
kd_, ddr_, foes_, n_ = brut_force2(kd, ddr, s, n)
return kd_, ddr_, foes_, n_
#return kd, ddr , foes, n
def brut_force2(q2,d,S,n):
S = np.array(S)
s = S.copy()
u = np.zeros((S[0],S[1],2))
# v = np.flip(q2,1)
q = q2.copy()
d2 = d.copy()
#print(np.reshape(q2[:,1],-1))
u[np.reshape(q2[:,1],-1),np.reshape(q2[:,0],-1)] = d
S = np.intp(S/n)
foes = np.zeros((n*n,2))
i3 = 0
#all_inliners = []
ddr = np.empty((1,2),dtype=np.float32)
kd = ddr.copy()
for j in range(0,n):
for i in range(0,n):
i3 += 1
k = q2[np.where(np.all(np.array([i*S[1],j*S[0]]) <= q2,axis=1) & np.all(np.array([(i+1)*S[1],(j+1)*S[0]])>q2,axis=1)),:]
k = k[0,:,:]
d_rob = u[np.reshape(k[:,1],-1),np.reshape(k[:,0],-1)]
if d_rob.size < 2:
# print("break")
continue
foe, inliers = estimate_foe(d_rob)
foes[i3-1,:] = np.array(foe) + np.array([(i+0.5)*S[1],(j+0.5)*S[0]])
inliers = np.array(inliers) #+ np.array([(j+1)*S[0],(i+1)*S[1]])
#print(i+j)
if i+j == 0:
#all_inliers = inliers
ddr = d_rob[inliers]
kd = k[inliers]
else:
#all_inliers = all_inliers + inliers
ddr = np.concatenate((ddr,d_rob[inliers]),axis=0)
kd = np.concatenate((kd,k[inliers]),axis=0)
#print(type(all_inliers))
a = np.sqrt(d_rob[:,0]**2 + d_rob[:,1]**2)
dm = np.median(a, axis=0)
#print(dm)
drr = np.where((a > 1.5*dm) | (a < 0.2*dm))
dr = d_rob[drr]
qr = k[drr]
dr = dr.tolist()
qr = qr.tolist()
d = d.tolist()
q2 = q2.tolist()
for i2,j2 in zip(dr,qr):
d.remove(i2)
q2.remove(j2)
d = np.array(d)
q2 = np.array(q2)
for j in range(n):
for i in range(n):
k = q2[np.where(np.all(np.array([i*S[1],j*S[0]]) <= q2,axis=1) & np.all(np.array([(i+1)*S[1],(j+1)*S[0]])>q2,axis=1)),:]
k = k[0,:,:]
#print(k)
d_rob = u[np.reshape(k[:,1],-1),np.reshape(k[:,0],-1)]
if d_rob.size < 2:
continue
alp = np.arctan2(d_rob[:,1],d_rob[:,0])*180/np.pi
alp_me = np.median(alp, axis=0)
# print(alp_me)
drr_alp = np.where((alp > alp_me+7.5) | (alp < alp_me-7.5) )
# print(np.shape(d))
dr_alp = d_rob[drr_alp]
qr_alp = k[drr_alp]
dr_alp = dr_alp.tolist()
qr_alp = qr_alp.tolist()
d = d.tolist()
q2 = q2.tolist()
for i2,j2 in zip(dr_alp,qr_alp):
d.remove(i2)
q2.remove(j2)
d = np.array(d)
q2 = np.array(q2)
#kd_, ddr_, foes_, n_ = brut_force(q2, d, s, n)
#print(foes)
#return kd_, ddr_, foes_, n_
return q2, d , foes, n