Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
endeleze committed Sep 10, 2024
1 parent bfae7be commit d53b0f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
Binary file modified src/__pycache__/server_manager.cpython-38.pyc
Binary file not shown.
28 changes: 14 additions & 14 deletions src/server_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __init__(self, config, logger):

############################################# test data #################################################
# Load and process the specific image for debugging
# image_path = '/mnt/data/UNav-IO/logs/New_York_City/LightHouse/6_Good/2023-07-21_13-59-48.png'
# image = Image.open(image_path)
image_path = '/mnt/data/UNav-IO/logs/New_York_City/LightHouse/6_Good/2023-07-21_13-59-48.png'
image = Image.open(image_path)

# self.image_np = np.array(image)
self.image_np = np.array(image)
############################################# test data #################################################

def get_scale(self, place, building, floor, session_id):
Expand Down Expand Up @@ -95,20 +95,21 @@ def get_floorplan_and_destinations(self, session_id, place, building, floor):
location_config=self.config['location']
floorplan_url = os.path.join(self.new_root_dir, 'data', location_config['place'], building, floor, 'floorplan.png')
floorplan = Image.open(floorplan_url).convert("RGB")
destinations, anchor_dict = self.extract_data(self.config)

destinations = self.all_buildings_data.get(building,{}).get(floor,{}).get('destinations',{})

destinations_data = [
{'name': dest_info['name'], 'id': dest_id, 'location': dest_info['location']}
for dest_id, dest_info in destinations.items()
]

destinations_data = sorted(destinations_data, key=lambda x: x['name'])

# Convert floorplan image to base64
buffer = io.BytesIO()
floorplan.save(buffer, format="PNG")
floorplan_base64 = base64.b64encode(buffer.getvalue()).decode()

# Prepare destinations and anchors data
anchor_names = list(anchor_dict.keys())
anchor_locations = list(anchor_dict.values())

destinations_data = [{'name': list(dest.keys())[0], 'id': list(dest.values())[0], 'location': anchor_locations[anchor_names.index(list(dest.values())[0])]} for dest in destinations]
anchors_data = list(anchor_dict.values())

if session_id not in self.navigation_states:
self.navigation_states[session_id] = {
'Place': place,
Expand All @@ -122,7 +123,6 @@ def get_floorplan_and_destinations(self, session_id, place, building, floor):
return {
'floorplan': floorplan_base64,
'destinations': destinations_data,
'anchors': anchors_data
}

def select_destination(self, session_id, place, building, floor, destination_id):
Expand Down Expand Up @@ -157,7 +157,7 @@ def handle_localization(self, session_id, frame):
previous_segment_id = state['segment_id']

if state['failures'] >= COARSE_LOCALIZE_THRESHOLD or time_since_last_success > TIMEOUT_SECONDS or not state['segment_id']:
segment_id = self.coarse_localize(frame) #debug
segment_id = self.coarse_localize(self.image_np) #debug
if segment_id:
# Load the current segment and its neighbors
parts = segment_id.split('_')
Expand All @@ -170,7 +170,7 @@ def handle_localization(self, session_id, frame):

self.refine_locator.update_maps(map_data)

pose = self.refine_locator.get_location(frame) #debug
pose = self.refine_locator.get_location(self.image_np) #debug

if pose:
state['pose'] = pose
Expand Down
Binary file modified src/utils/__pycache__/data_handler.cpython-38.pyc
Binary file not shown.
15 changes: 0 additions & 15 deletions src/utils/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,6 @@ def load_map(self, segment_id):
print(f"Error loading map segment {segment_file}: {e}")
return None

def extract_data(self, config):
destination_path=join(config['IO_root'],'data','destination.json')
destinations=load_destination(destination_path)

location_config=config['location']
place = location_config['place']
building = location_config['building']
floor = location_config['floor']

boundary_path=join(config['IO_root'], 'data', place, building, str(floor), 'boundaries_interwaypoint.json')
anchor_names,anchor_locations,_=load_boundaires(boundary_path)

anchor_dict = dict(zip(anchor_names, anchor_locations))
return destinations[place][building]['6th_floor'], anchor_dict

class DemoData(DataHandler):
def __init__(self, new_root_dir):
super().__init__(new_root_dir)
Expand Down

0 comments on commit d53b0f7

Please sign in to comment.