def GetDepthMap(panoid=None, lat=None, lon=None, radius=10): if panoid is None: panoid = GSV.GetIDByLoc(lat=lat, lon=lon, radius=radius) if panoid is None: return None metadata = GSV.GetPanoramaMetadata(panoid=panoid) return CreateDepthMap(metadata)
def Merge(ID): print ID info = Info.GetVideoInfo(ID) f_name = info['match_path'] + '/' + name f = open(f_name, 'r') data = json.load(f) f.close() key_lst = sorted(data.keys()) pano_lst = [] for key in key_lst: loc = data[key] print key try: panoid = GSV.getIDbyloc(lat=loc[0], lon=loc[1]) except: data.pop(key) continue #print panoid if panoid is None: data.pop(key) continue elif not panoid in pano_lst: pano_lst.append(panoid) try: loc = GSV.getLocationbyID(panoid) data[key] = [float(loc[0]), float(loc[1])] except: data.pop(key) continue else: data.pop(key) f = open(info['match_path'] + '/google_info.json', 'w') f.write(json.dumps(data, indent=4)) f.close()
def GetResultLst(ID): print ID info = Info.GetVideoInfo(ID) frame_sift_lst = [x for x in sorted(os.listdir(info['frame_sift_path'])) if x.endswith('.sift')] pano_sift_lst = [x for x in sorted(os.listdir(info['pano_sift_path'])) if x.endswith('.sift')] fisher_result = np.load(Info.GetFisherResultFileName(info)) match_score = np.load(Info.GetMatchFunMFileName(info)) #print match_score f = open(Info.GetMatchLstFileName(info), 'w') for frame_index, frame_sift_name in enumerate(frame_sift_lst): arg_sort_index = np.argsort(match_score[frame_index, :]) highest_index = arg_sort_index[-1] highest_score = match_score[frame_index, highest_index] second_index = arg_sort_index[-2] second_score = match_score[frame_index, second_index] ratio = float(highest_score) / float(second_score) if highest_score >= THRESHOLD: frame_name = frame_sift_name.split('.')[0] + '.jpg' pano_sift_name = pano_sift_lst[fisher_result[frame_index, highest_index]] pano_name = pano_sift_name.split('.')[0] + '.jpg' pano_id = pano_name[5:27] print pano_id loc = GoogleSV.getLocationbyID(pano_id) if loc is None: continue s = '%s\t%s\t%s\t%s\t%d\n'%(frame_name, pano_name, loc[0], loc[1], highest_score) f.write(s) f.close()
def GetIDByLoc(latlon): # # latlon is ['24', '121'] formt # lat = str(latlon[0]) lon = str(latlon[1]) try: panoid = GSV.GetIDByLoc(lat=lat, lon=lon) except: panoid = None return panoid
def Label(ID): info = Info.GetVideoInfo(ID) frame_lst = [x for x in sorted(os.listdir(info['frame_path'])) if x.endswith] i = 0 f = open(Info.GetMatchLstFileName(info), 'w') while True: f_name = info['frame_path'] + '/' + frame_lst[i] command = 'eog %s'%f_name subprocess.call(command, shell=True) panoid = raw_input('Pano ID : ') loc = GSV.getLocationbyID(panoid) print loc s = '%s\t%s\t%s\t%s\n'%(frame_lst[i], panoid, loc[0], loc[1]) f.write(s) i += 10 if i >= 125: f.close() return f.close()
def Label(ID): info = Info.GetVideoInfo(ID) frame_lst = [ x for x in sorted(os.listdir(info['frame_path'])) if x.endswith ] i = 0 f = open(Info.GetMatchLstFileName(info), 'w') while True: f_name = info['frame_path'] + '/' + frame_lst[i] command = 'eog %s' % f_name subprocess.call(command, shell=True) panoid = raw_input('Pano ID : ') loc = GSV.getLocationbyID(panoid) print loc s = '%s\t%s\t%s\t%s\n' % (frame_lst[i], panoid, loc[0], loc[1]) f.write(s) i += 10 if i >= 125: f.close() return f.close()
def GetPanoByID_full(ID, DIR): if not os.path.isdir(DIR): return False subprocess.call('mkdir -p buffer_%s' % (ID), shell=True) row_range = range(7) col_range = range(13) for row in row_range: for col in col_range: data = GSV.GetPanoramaTile(ID, zoom_lv, col, row) f = open('buffer_%s/image_%d_%d.jpg' % (ID, row, col), 'wb') f.write(data) f.close() img = np.zeros([512 * 7, 512 * 13, 3], dtype=np.uint8) for row in row_range: for col in col_range: patch = cv2.imread('buffer_%s/image_%d_%d.jpg' % (ID, row, col)) img[row * 512:(row + 1) * 512, col * 512:(col + 1) * 512, :] = patch cv2.imwrite('%s/pano_%s.jpg' % (DIR, ID), img[:-256, :]) subprocess.call('rm -r buffer_%s' % (ID), shell=True)
def GetResultLst(ID): print ID info = Info.GetVideoInfo(ID) frame_sift_lst = [ x for x in sorted(os.listdir(info['frame_sift_path'])) if x.endswith('.sift') ] pano_sift_lst = [ x for x in sorted(os.listdir(info['pano_sift_path'])) if x.endswith('.sift') ] fisher_result = np.load(Info.GetFisherResultFileName(info)) match_score = np.load(Info.GetMatchFunMFileName(info)) #print match_score f = open(Info.GetMatchLstFileName(info), 'w') for frame_index, frame_sift_name in enumerate(frame_sift_lst): arg_sort_index = np.argsort(match_score[frame_index, :]) highest_index = arg_sort_index[-1] highest_score = match_score[frame_index, highest_index] second_index = arg_sort_index[-2] second_score = match_score[frame_index, second_index] ratio = float(highest_score) / float(second_score) if highest_score >= THRESHOLD: frame_name = frame_sift_name.split('.')[0] + '.jpg' pano_sift_name = pano_sift_lst[fisher_result[frame_index, highest_index]] pano_name = pano_sift_name.split('.')[0] + '.jpg' pano_id = pano_name[5:27] print pano_id loc = GoogleSV.getLocationbyID(pano_id) if loc is None: continue s = '%s\t%s\t%s\t%s\t%d\n' % (frame_name, pano_name, loc[0], loc[1], highest_score) f.write(s) f.close()
def GetPanoByID_0_180(ID, DIR): if not os.path.isdir(DIR): return False try: if not os.path.isdir('./buffer_%s' % ID): subprocess.call('mkdir -p buffer_%s/tmp' % ID, shell=True) else: subprocess.call('rm -r buffer_%s' % ID, shell=True) subprocess.call('mkdir -p buffer_%s/tmp' % ID, shell=True) row_range = [2, 3, 4] col_range = [5, 6, 7] index = 0 for row in row_range: for col in col_range: data = GSV.GetPanoramaTile(ID, zoom_lv, col, row) #subprocess.call("wget '%s' -O buffer_%s/tmp/image_%.2d%s"%(url, ID, index, ext), shell=True) f = open('buffer_%s/tmp/image_%.2d%s' % (ID, index, ext), 'wb') f.write(data) f.close() index += 1 lst = os.listdir('buffer_%s/tmp/' % ID) lst.sort() output = np.zeros([1536, 1536, 3], dtype=np.uint8) begin_row = 0 begin_col = 0 index = 0 for row in range(0, 3): begin_col = 0 for col in range(0, 3): img = cv2.imread('buffer_%s/tmp/' % ID + lst[index]) output[begin_row:begin_row + 512, begin_col:begin_col + 512] = img begin_col += 512 index += 1 begin_row += 512 cv2.imwrite('buffer_%s/pano_%s_0.jpg' % (ID, ID), output[208:928, 128:1408]) subprocess.call('rm buffer_%s/tmp/*' % ID, shell=True) row_range = [2, 3, 4] col_range = [11, 12, 0, 1] #col_range = [1, 0 , 12, 11] index = 0 for row in row_range: for col in col_range: data = GSV.GetPanoramaTile(ID, zoom_lv, col, row) #subprocess.call("wget '%s' -O buffer_%s/tmp/image_%.2d%s"%(url, ID, index, ext), shell=True) f = open('buffer_%s/tmp/image_%.2d%s' % (ID, index, ext), 'wb') f.write(data) f.close() index += 1 lst = os.listdir('buffer_%s/tmp/' % ID) lst.sort() output = np.zeros([2048, 2048, 3], dtype=np.uint8) begin_row = 0 begin_col = 0 index = 0 for row in range(0, 3): begin_col = 0 for col in range(0, 4): img = cv2.imread('buffer_%s/tmp/' % ID + lst[index]) output[begin_row:begin_row + 512, begin_col:begin_col + 512] = img begin_col += 512 index += 1 begin_row += 512 cv2.imwrite('buffer_%s/pano_%s_180.jpg' % (ID, ID), output[208:928, 384:1664]) subprocess.call('mv buffer_%s/*.jpg %s' % (ID, DIR), shell=True) subprocess.call('rm -r buffer_%s/' % ID, shell=True) return True except: subprocess.call('rm -r buffer_%s/' % ID, shell=True) return False
def GetLocByID(ID): return GSV.GetLocByID(panoid=ID)
''' depth_map = depth * 255 / 50 depth_map[np.nonzero(np.isnan(depth_map))] = 255 depth_map[np.nonzero(depth_map > 255)] = 255 depth_map /= 255 ''' #depth_map = depth #''' depth[np.isinf(depth)] = 3000 depth_map = np.abs(depth) + 1 #print np.max(np.log(depth_map)) sc = 1 / np.max(np.log(depth_map)) depth_map = sc * np.log(depth_map) #depth_map = depth / np.amax(depth) * 255 #''' scipy.misc.imsave('depth.png', depth_map) def DepthToNpy(depth, store_name): np.save(store_name, depth) if __name__ == '__main__': #CreateSphericalBuf(256, 512) #exit() #test_id = 'Bu_I2xKvp4GVH97EB4obLQ' test_id = 'pRANHWx41ZnTz5PsZs6JpA' data = GSV.GetPanoramaMetadata(panoid=test_id) a = CreateDepthMap(data) DepthToNpy(a, './G.npy')
def GetPanoID(latlon): return GoogleSV.getIDbyloc(lat=latlon[0], lon=latlon[1])
def GetPanoByID(ID, save_dir): if not (os.path.isdir(save_dir)): subprocess.call("mkdir -p %s" % save_dir, shell=True) GoogleSV.getpanobyID(ID, DIR=save_dir)