Skip to content

Commit

Permalink
mavpicviewer: support sorting by temp
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Oct 11, 2024
1 parent e4e68c1 commit ecf8ab1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
14 changes: 14 additions & 0 deletions MAVProxy/tools/mavpicviewer/mavpicviewer_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def handle_comm_object(self, obj):
self.set_yaw(obj.yaw)
elif isinstance(obj, mpv.ClearAllPOI):
self.poi_clear_all()
elif isinstance(obj, mpv.GetTempForAllImages):
self.send_all_temperatures()
elif isinstance(obj, mpv.Close):
self.close(False)

Expand Down Expand Up @@ -487,6 +489,18 @@ def get_exif_loc_and_temp(self, filename):

return lat, lon, alt, terr_alt, temp_max, temp_max_x, temp_max_y, temp_min, temp_min_x, temp_min_y

# collect and send all temperatures to mosaic
def send_all_temperatures(self):
for filenumber in range(len(self.filelist)):
filename = self.filelist[filenumber]
if filename is not None:
# load exif data
lat, lon, alt_amsl, terr_alt, \
temp_max, temp_max_pos_X, temp_max_pos_Y, \
temp_min, temp_min_pos_X, temp_min_pos_Y = self.get_exif_loc_and_temp(filename)
# send exif data to mosaic
self.send_comm_object(mpv.SetTempAndPos(filenumber, temp_max, temp_max_pos_X, temp_max_pos_Y))

def dms_to_decimal(self, degrees, minutes, seconds, sign=b' '):
"""Convert degrees, minutes, seconds into decimal degrees.
Expand Down
46 changes: 38 additions & 8 deletions MAVProxy/tools/mavpicviewer/mavpicviewer_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, folderpath, comm_pipe=None):

# init dictionary of image temperatures
self.image_temp_dict = {}
self.image_temp_dict_sorted = {}

# hardcoded thumbnail image size and number of columns
self.thumb_size = 100
Expand All @@ -69,12 +70,14 @@ def __init__(self, folderpath, comm_pipe=None):
self.frame.Bind(wx.EVT_MENU, self.menu_display_all_images, id=2)
self.menu.Append(3, "Show POI", "Show images with POI")
self.frame.Bind(wx.EVT_MENU, self.menu_display_poi_images, id=3)
self.menu.Append(4, "Settings", "Settings")
self.frame.Bind(wx.EVT_MENU, self.mavpicviewer_settings.show_settings_window, id=4)
self.menu.Append(5, "Clear All POI", "Clear POI from all images")
self.frame.Bind(wx.EVT_MENU, self.menu_clear_all_poi, id=5)
self.menu.Append(6, "Quit", "Quit")
self.frame.Bind(wx.EVT_MENU, self.menu_quit, id=6)
self.menu.Append(4, "Sort by Temp", "Sort images by Temp (max first)")
self.frame.Bind(wx.EVT_MENU, self.menu_sort_by_temp, id=4)
self.menu.Append(5, "Settings", "Settings")
self.frame.Bind(wx.EVT_MENU, self.mavpicviewer_settings.show_settings_window, id=5)
self.menu.Append(6, "Clear All POI", "Clear POI from all images")
self.frame.Bind(wx.EVT_MENU, self.menu_clear_all_poi, id=6)
self.menu.Append(7, "Quit", "Quit")
self.frame.Bind(wx.EVT_MENU, self.menu_quit, id=7)
self.menu_bar = wx.MenuBar()
self.menu_bar.Append(self.menu, "Menu")
self.frame.SetMenuBar(self.menu_bar)
Expand Down Expand Up @@ -177,6 +180,11 @@ def menu_display_poi_images(self, event):
"""display POI images only"""
wx.CallAfter(self.display_all_images, poi_only=True)

# sort images by temperature
def menu_sort_by_temp(self, event):
"""sort images by temperature"""
wx.CallAfter(self.sort_images_by_temperature)

# clear all POI
def menu_clear_all_poi(self, event):
"""clear all POI"""
Expand Down Expand Up @@ -391,16 +399,22 @@ def scroll_to_be_visible(self, filenumber):
self.scrolled_panel.ScrollChildIntoView(panel)

# display all images
def display_all_images(self, poi_only=False):
def display_all_images(self, poi_only=False, sort_by_temp=False):
"""display all images"""
# detach and hide all panels
for p in self.scrolled_panel_sizer.GetChildren():
panel = p.GetWindow()
self.scrolled_panel_sizer.Detach(panel)
panel.Hide()

# create list of filenumbers (either the full list or the sorted by temperature list)
if sort_by_temp:
filenumber_list = list(self.image_temp_dict_sorted.keys())
else:
filenumber_list = list(range(len(self.filelist)))

# add panels to scrolled panel sizer
for i in range(len(self.filelist)):
for i in filenumber_list:
# check if we should only display POI images
if poi_only is True and i not in self.poi_dict:
continue
Expand Down Expand Up @@ -434,6 +448,22 @@ def settings_changed_cb(self, name, value):
if name == "YAW":
self.send_comm_object(mpv.SetYaw(float(value)))

# sort images by temperature
def sort_images_by_temperature(self):
"""sort images by temperature (max temp first)"""
# print warning if not all images have temperature data
if len(self.image_temp_dict) != len(self.filelist):
print(prefix_str + "only %d (of %d) images have temp" % (len(self.image_temp_dict), len(self.filelist)))
# request temperatures from image viewer
self.send_comm_object(mpv.GetTempForAllImages())

# update dictionary of images sorted by temperature
self.image_temp_dict_sorted = dict(sorted(self.image_temp_dict.items(),
key=lambda item: item[1].temp_max, reverse=True))

# display all images sorted by temperature
self.display_all_images(sort_by_temp=True)


# main function
if __name__ == "__main__":
Expand Down
6 changes: 6 additions & 0 deletions MAVProxy/tools/mavpicviewer/mavpicviewer_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def __init__(self):
pass


# request temperatures from all images
class GetTempForAllImages:
def __init__(self):
pass


# set Temp data for the given filenumber
class SetTempAndPos:
def __init__(self, filenumber, temp_max, temp_pos_x, temp_pos_y):
Expand Down

0 comments on commit ecf8ab1

Please sign in to comment.