def init_region(self, anchor=None):
        """
        Set the anchor and Initialize the local region.
        :param anchor:
        :return:
        """
        """
        # Set the anchor.
        """
        if anchor is None:
            print('Random anchor')
            for panoId in sorted(self.fileMeta['id2GPS']):
                print('anchor is:', panoId, self.fileMeta['id2GPS'][panoId])
                self.anchorId, self.anchorLat, self.anchorLon = \
                    panoId, float(self.fileMeta['id2GPS'][panoId][0]), float(self.fileMeta['id2GPS'][panoId][1])
                self.anchorECEF = base_process.geo_2_ecef(
                    self.anchorLat, self.anchorLon, 22)
                break
        else:
            print('use the anchor')
            print('anchor is:', anchor['anchorId'], anchor['anchorLat'],
                  anchor['anchorLon'])
            self.anchorId, self.anchorLat, self.anchorLon = \
                anchor['anchorId'], anchor['anchorLat'], anchor['anchorLon']
            self.anchorECEF = base_process.geo_2_ecef(self.anchorLat,
                                                      self.anchorLon, 22)
        """
        # Initialize the local region anchor_matrix and anchor_yaw
        """
        try:
            pano_id_dir = os.path.join(self.dataDir, self.anchorId)
            panorama = scipy.misc.imread(pano_id_dir + '.jpg').astype(np.float)
            with open(pano_id_dir + '.json') as data_file:
                pano_meta = json.load(data_file)
                sv3d = StreetView3D(pano_meta, panorama, self.d_height,
                                    self.d_width)
                sv3d.create_ptcloud_bilinear_depth(self.sphericalRay)
                sv3d.global_adjustment()
                sv3d.local_adjustment(self.anchorECEF)
                # TODO: reduce some redundant work
                # self.sv3D_Dict[self.anchorId] = sv3d
                self.anchorMatrix = np.dot(sv3d.matrix_local,
                                           sv3d.matrix_global)
                self.anchorYaw = sv3d.yaw
                data_file.close()

        except FileNotFoundError:
            print('no anchor file QQ')
    def init_region(self, anchor=None):
        """
        Initialize the local region
        Find the anchor
        :return:
        """
        if anchor is None:
            print('Random anchor')
            panoId = self.fileMeta['panoList'][0]
            print('anchor is:', panoId, self.fileMeta['id2GPS'][panoId])
            self.anchorId, self.anchorLat, self.anchorLon = \
                panoId, float(self.fileMeta['id2GPS'][panoId][0]), float(self.fileMeta['id2GPS'][panoId][1])
            self.anchorECEF = base_process.geo_2_ecef(self.anchorLat, self.anchorLon, 22)
        else:
            print('use the anchor')
            print('anchor is:', anchor['anchorId'], anchor['anchorLat'], anchor['anchorLon'])
            self.anchorId, self.anchorLat, self.anchorLon = \
                anchor['anchorId'], anchor['anchorLat'], anchor['anchorLon']
            self.anchorECEF = base_process.geo_2_ecef(self.anchorLat, self.anchorLon, 22)

        # The anchor
        try:
            pano_id_dir = os.path.join(self.dataDir, self.anchorId)
            panorama = scipy.misc.imread(pano_id_dir + '.jpg').astype(np.float)
            with open(pano_id_dir + '.json') as data_file:
                pano_meta = json.load(data_file)
                sv3d = StreetView3D(pano_meta, panorama)
                sv3d.create_ptcloud(self.sphericalRay)
                sv3d.global_adjustment()
                sv3d.local_adjustment(self.anchorECEF)
                # TODO: reduce some redundant work
                self.sv3D_Dict[self.anchorId] = sv3d
                self.anchorMatrix = np.dot(sv3d.matrix_local, sv3d.matrix_global)
                self.anchorYaw = sv3d.yaw
                data_file.close()

        except FileNotFoundError:
            print('no anchor file QQ')
            self.QQ = True
 def create_trajectory(self):
     keyframe_2_id = sorted(self.fileMeta['keyframe_2_id'])
     keyframe_num = len(keyframe_2_id)
     data = np.zeros(pano_num, dtype=[('a_position', np.float32, 3), ('a_color', np.float32, 3)])
     idx = 0
     for panoid in id_2_gps:
         gps = id_2_gps[panoid]
         ecef = base_process.geo_2_ecef(float(gps[0]), float(gps[1]), 22) - self.anchorECEF
         # TODO: ecef v.s. x-y plane
         data['a_position'][idx] = np.asarray(ecef, dtype=np.float32)
         idx += 1
     data['a_color'] = [0, 1, 0]
     self.trajectoryData = data
    def create_topology_bfs(self):
        id_2_gps = self.fileMeta['id2GPS']
        pano_list = self.fileMeta['panoList']
        pano_len = self.fileMeta['cur'] + 1
        topology = np.zeros((pano_len, 3), dtype=np.float32)
        for idx in range(0, pano_len):
            gps = id_2_gps[pano_list[idx]]
            lat, lon = float(gps[0]), float(gps[1])
            ecef = np.array(base_process.geo_2_ecef(lat, lon, 22))
            if idx == 0:
                self.anchorECEF = ecef

                matrix = np.eye(4, dtype=np.float32)
                # Change xy-plan to ecef coordinate
                glm.rotate(matrix, 90, 0, 1, 0)
                glm.rotate(matrix, 90, 1, 0, 0)
                glm.rotate(matrix, lat, 0, -1, 0)
                glm.rotate(matrix, lon, 0, 0, 1)

                self.anchorMatrix = matrix
            else:
                topology[idx, :] = ecef - self.anchorECEF
        topology = base_process.sv3d_apply_m4(topology, m4=np.linalg.inv(self.anchorMatrix))
        id_2_gps = self.fileMeta['id2GPS']
        pano_num = len(id_2_gps)
        data = np.zeros(pano_num, dtype=[('a_position', np.float32, 3), ('a_color', np.float32, 3)])
        idx = 0
        for panoid in id_2_gps:
            gps = id_2_gps[panoid]
            ecef = base_process.geo_2_ecef(float(gps[0]), float(gps[1]), 22) - self.anchorECEF
            # TODO: ecef v.s. x-y plane
            data['a_position'][idx] = np.asarray(ecef, dtype=np.float32)
            idx += 1
        data['a_color'] = [0, 1, 0]
        data['a_position'] = base_process.sv3d_apply_m4(data=data['a_position'],
                                   m4=np.linalg.inv(self.anchorMatrix))
        self.topologyData = data
 def create_topology(self):
     id_2_gps = self.fileMeta['id2GPS']
     pano_num = len(id_2_gps)
     data = np.zeros(pano_num, dtype=[('a_position', np.float32, 3), ('a_color', np.float32, 3)])
     idx = 0
     for panoid in id_2_gps:
         gps = id_2_gps[panoid]
         ecef = base_process.geo_2_ecef(float(gps[0]), float(gps[1]), 22) - self.anchorECEF
         # TODO: ecef v.s. x-y plane
         data['a_position'][idx] = np.asarray(ecef, dtype=np.float32)
         idx += 1
     data['a_color'] = [0, 1, 0]
     data['a_position'] = base_process.sv3d_apply_m4(data=data['a_position'],
                                m4=np.linalg.inv(self.anchorMatrix))
     self.topologyData = data
    def __init__(self, pano_meta, panorama):
        self.panoMeta, self.panorama = pano_meta, panorama
        self.depthHeader, self.depthMapIndices, self.depthMapPlanes = {}, [], []
        self.depthMap, self.ptCLoudData, self.ptCLoudDataGnd, self.ptCLoudDataGndGrid = None, None, None, None
        self.normal_map, self.gnd_indices = None, None
        self.lat, self.lon, self.yaw = float(pano_meta['Lat']), float(pano_meta['Lon']), float(pano_meta['ProjectionPanoYawDeg'])
        self.ecef = base_process.geo_2_ecef(self.lat, self.lon, 22)

        self.decode_depth_map(pano_meta['rawDepth'])
        if self.depthHeader['panoHeight'] != 256 or self.depthHeader['panoWidth'] != 512:
            print("The depthMap's size of id:%s is unusual: (%d, %d)"
                  % (self.panoMeta['panoId'], self.depthHeader['panoHeight'], self.depthHeader['panoWidth']))

        self.matrix_global = np.eye(4, dtype=np.float32)
        self.matrix_local = np.eye(4, dtype=np.float32)
        self.matrix_offs = np.eye(4, dtype=np.float32)

        self.indices_split, self.plane_split, self.gnd_con, self.non_con, self.all_con = None, None, None, None, None
        self.gnd_plane, self.all_plane = [], []
#!/usr/bin/python3
# ==============================================================
# demo for chane coordinate(lat, lon, h) <--> (x, y, z)
# ==============================================================
import google_parse
import base_process

fileID = 'NovelView_small'
"""
# 2. parse raw depth
"""
sv3DRegion = google_parse.StreetView3DRegion(fileID)
#sv3DRegion.init_region(anchor=None)
sv3DRegion.create_topoloy()
# All single location
topology_data = sv3DRegion.topologyData
sv3DRegion.create_region()
for key in sv3DRegion.sv3D_Dict:
    sv = sv3DRegion.sv3D_Dict[key]
    lat, lon = sv.lat, sv.lon
    lat, lon, h = base_process.ecef_2_geo(sv.ecef[0], sv.ecef[1], sv.ecef[2])
    x, y, z = base_process.geo_2_ecef(lat, lon, h)
    break