def camera_position(self, ci, noise = 2): if len(self.campos[ci]) < 2: return None avg = Quaternion.average(self.campos[ci]) d = np.array([avg.distance_metric(q) for q in self.campos[ci]]) d2 = d**2 var = np.mean(d2) #print var * noise**2 #print d2 #print np.where(d2 < var * noise**2)[0] self.campos[ci] = [self.campos[ci][i] for i in np.where(d2 < var * noise**2)[0]] avg = Quaternion.average(self.campos[ci]) self.campos_avg[ci] = avg return avg
def solve(self, noise=2): if self.mode == 'adjust': return self.ra, self.dec if len(self.pos[0]) < 3: return None, None weights = np.matrix(np.zeros((2, 2))) wsum = np.zeros((2,1)) for ci in range(0, len(self.pos)): if len(self.pos[ci]) < 3: continue try: qlist = [ p for (p, t) in self.pos[ci]] avg = Quaternion.average(qlist).inv() alist = [] for q in qlist: q0 = q * avg if abs(q0.a[0]) < 0.7: ax, roll = q0.to_axis_roll() q0 = Quaternion.from_axis_roll(ax, roll - 180) a = q0.a[1:4] / q0.a[0] alist.append(a) aa = np.array(alist) d2 = np.sum(aa[:, 0:2] ** 2, axis = 1) var = np.mean(d2) aa = aa[np.where(d2 < var * 4)] line = cv2.fitLine(aa / aa[0,2] * 100, cv2.DIST_L2, 0.001, 0.000001, 0.000001)[0:3].reshape(3) line2d = line[0:2] / line[2] aa2d = aa[:, 0:2] - np.outer(aa[:, 2], line2d) cov =np.cov(aa2d.T) #print cov w = np.matrix(cov).I #print ci, "w", w weights += w wsum += w * line2d.reshape((2,1)) #print ci, "weights", weights #print ci, "wsum", wsum except: continue try: line2d = weights.I * wsum #print "res", line2d line = np.array([line2d[0,0], line2d[1,0], 1]) ra, dec = xyz_to_ra_dec(line) if dec < 0: dec = -dec ra -= 180 if ra < 0.0 : ra += 360 self.ra = ra self.dec = dec self.solved = True except: return None, None #print "rotation center", ra, dec #print "prec", self.prec_ra, self.prec_dec return ra, dec
poslist = [] for i in range(0, len(self.pos)): if self.campos_adjust[i] is None: continue prev_pos, prev_t = self.campos_adjust[i] if abs(t - prev_t) > 10: continue if i > 0 and self.campos_avg[i] is None: self.camera_position(i) if i > 0 and self.campos_avg[i] is not None: prev_pos = prev_pos * self.campos_avg[i] poslist.append(prev_pos) print [p.to_euler() for p in poslist] pos = Quaternion.average(poslist) if self.p2_from is None: self.mode_adjust_set_ref_pos() self.p2_from = pos self.save() t = pos / self.p2_from print t.to_euler() self.ra, self.dec = t.transform_ra_dec([self.ref_ra, self.ref_dec]) def plot2(self, size = 960, area = 0.1): ha = celestial_rot() + self.status['gps'][1] qha = Quaternion([90-ha, 0, 0])