Forum

Author Topic: Removing photos based on GPS elevation  (Read 1463 times)

AKGIS

  • Newbie
  • *
  • Posts: 1
    • View Profile
Removing photos based on GPS elevation
« on: May 01, 2020, 11:55:28 PM »
I could use some help developing a better approach to removing cameras based on GPS elevation.

Our drone camera collects images while descending from and ascending to preprogrammed mission height.  We would like to automatically detect and remove these photos (see attached Capture 1.  We would like to remove the cameras within the red box).

I developed the attached script (also pasted below).  It simply calculates a global median elevation from all the camera's GPS metadata, calculates a range of acceptable elevation values, and then removes any camera whose elevation value does not fall within the range.

Code: [Select]
import Metashape as ms, statistics as stats
doc = ms.app.document
doc.chunk=doc.chunks[0]
'''
 STEP 3: Remove Out of Plane photos'''
for c in doc.chunks:
    print('WORKING ON CHUNK:',c.label.upper())
    camera_heights = []
    height_median = 0.0
    if (c.cameras[0].photo.meta["Exif/Make"]=="DJI"):
        camera_heights=[(float(cam.photo.meta["DJI/AbsoluteAltitude"])) for cam in c.cameras]
        height_median = stats.median(camera_heights)
        height_upper=height_median*1.01
        height_lower=height_median*0.99
        for cam in c.cameras:
            if not height_lower <= (float(cam.photo.meta["DJI/AbsoluteAltitude"])) < height_upper:
                c.remove(cam)
    elif (c.cameras[0].photo.meta["Exif/Make"]=="MicaSense"):
        camera_heights=[(float(cam.photo.meta["Exif/GPSAltitude"])) for cam in c.cameras]
        height_median = stats.median(camera_heights)
        height_upper=height_median*1.01
        height_lower=height_median*0.99
        for cam in c.cameras:
            if not height_lower <= (float(cam.photo.meta["Exif/GPSAltitude"])) < height_upper:
                c.remove(cam)
    print ('MOVING ON TO THE NEXT CHUNK. \n')

This script works fine on small areas with small changes in topography.  But for those areas with large changes in topography, the script removes cameras from high and low elevation areas that should remain in the project.  Our drone and flight software allow terrain following so the drone does not fly at a fixed elevation but rather follows the contours of the ground.

I need a script that can take this into account.  My first thought was to 'divide' the entire chunk space into smaller pieces and then run the script in each smaller piece- essentially calculating a local elevation median for each piece and evaluating all photos within each piece against the local median.

1.  Is there a better approach?
2.  If creating smaller pieces is the way to go, I'm not sure how to implement. I'd like to avoid creating multiple chunks to do this, but if that's the best option then ok.  I could always merge them back together afterwards.

Any thoughts or advice would be appreciated.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Removing photos based on GPS elevation
« Reply #1 on: May 02, 2020, 12:11:13 PM »
Hello AKGIS,

It is not a good practice to remove the elements of the list you are iterating on, so I can suggest the following modification:
Code: [Select]
        for cam in list(c.cameras):
            if not height_lower <= (float(cam.photo.meta["DJI/AbsoluteAltitude"])) < height_upper:
                c.remove(cam)
and

Code: [Select]
        for cam in list(c.cameras):
            if not height_lower <= (float(cam.photo.meta["Exif/GPSAltitude"])) < height_upper:
                c.remove(cam)

Can you please check if it solves the problem, or still not all the outliers are removed?
Best regards,
Alexey Pasumansky,
Agisoft LLC