r/UAVmapping • • Oct 20 '24 • Take My Energy 1

WIP Python tool for mapping water surfaces with aerial images

172 Upvotes

44 comments sorted by

22

u/Straight-Spell-9930 Oct 20 '24

Hey everyone,

Here are some early wip image examples of a personal project i've been working on in python. While these examples have lots of matching features and could allow them to be processed in a photogrammetry software or photoshop, the goal is to build a tool for mapping over open water where these software typically don't work. Because of this, the ground is assumed to be a plane and I don't intend to add support for terrain elevation. (there are existing tools that can do this already)

The images are "orthorectified" from the imu and gps data and viewable in gis software. These examples are from a mavic 2 pro and therefore the results can be improved using an rtk or ppk gnss workflow and or even a more complex setup with a better imu. From the 4th image you can see that non-nadir images can be handled as well.

My do to do list for the project is as follows:

  • correct yaw for magnetic declination

  • feather/smooth overlapping image borders

  • remove lens distorition from input images

  • remove vignetting from input images

  • add support for Mavic 3 Multispectral images (rgb + ms bands)

  • add basic command line interface

12

u/hotairballonfreak Oct 20 '24

Throw it on GitHub and I’ll throw in my vignette removal code.

1

u/jackoftrashtrades Oct 21 '24

Just a thought. I see that you are avoiding elevation, but have you considered using elevation and photogrammetry and essentially some of the features that are meant for erosion and so on to track shore erosion and also if you are treating the water like a plane or like a surface then using it to track water levels? I also program a bit and also like things that fly. And also like data. And surfaces.

2

u/Straight-Spell-9930 Oct 21 '24

Shorelines have enough features to map with a typical photogrammetry workflow and software. Also see the links in my other comments about software that uses rubber sheeting and minimal tiepoints. It works really well for flying a single pass of photos over a shoreline or similar linear projects where you don't need as much 3d information

I'm pretty sure there's public data tracking most larger water bodies and sources. If needed, water level gauges can be installed on site and if I'm not mistaken are quite affordable.

One huge benefit of not using photogrammetry is that you greatly speed up data collection, allowing much larger areas to be mapped . Data processing can also be faster and performed with lower end computers.

1

u/jackoftrashtrades Oct 21 '24

Thanks. That is very helpful. I'm a very technical person both in brain and background, but I am a photogrammetry, mapping, 3D modeling, and surveying fetus.

You can only read so much and watch so many videos before you have to start playing around with stuff and asking questions.

48

u/rtsy312 Oct 20 '24

Underrated post, something that this sub needs is more of these kinds of projects

15

u/Straight-Spell-9930 Oct 20 '24

Thanks, your comment and the others on this post help keep me motivated :)

I'm working on a fixed wing ardupilot build with an IR camera alongside this. I'll try to keep posting updates at substantial milestones.

The drone build and testing is limited by money and weather especially with the canadian winter inbound. Fortunately learning and coding python is free so it should keep progressing.

2

u/scottthemedic Oct 20 '24

Whereabouts are you located? There might be a drone operator nearby that can help your project grow...?

4

u/Straight-Spell-9930 Oct 20 '24

Southern Ontario, Canada. I'm an experienced drone operator, and at this point would benfit the most by having access to rtk or ppk multispectral data from an M3M. Specifically flown with low overlap ~15%, over shorelines/small bodies of water. My end goal is to have my own consultancy or contribute to some ecological related projects.

4

u/bmwbiker1 Oct 20 '24

Lock your exposure! you will get a much more consistent final result!

5

u/Straight-Spell-9930 Oct 20 '24

Thanks for the suggestion. I've been flying with manual exposure and white balance which should "lock" the exposure and colour. In the first example I think there were a few small clouds present that caused some minor lighting differences.

The second image only being ~4 images was captured across a short window of time and therefore has very consistent lighting and colour.

My end goal is to use multispectral images which in my experience can be a lot less susceptable to colour/lighting changes.

3

u/sireetsalot Oct 20 '24 edited Oct 20 '24

This is great, love it specifically for open water. IIRC imu data isn’t always available depending on the drone. Which drones would this support off the shelf?

3

u/Straight-Spell-9930 Oct 20 '24

Currently my project is built around the mavic 2 pro but I can easily modify the code to include other drones. Im guessing most large brands such as autel, dji, skydio, parrot etc. include the imu metadata in the images. You can check an image using an online metadata reader, but be aware that most will only show very limited metadata and to view all of the metadata you need to use a tool such as exiftool (which this project uses)

1

u/jackoftrashtrades Oct 21 '24

Why does Phil Harvey's site look like it is from 1997? :) I joke but you seem like you have played around with us a lot so I'm curious which other tools you like as well. I'd like to try out some of them for metadata

2

u/Straight-Spell-9930 Oct 21 '24

It's worth figuring out how to use exiftool. I think there is a GUI version as well. All of the top metadata readers on Google search only show the basic image metadata. Which is sometimes only 20% of the stored information

1

u/jackoftrashtrades Oct 21 '24

Thanks. I will play with it.

3

u/ElevatedInGamma Oct 20 '24

What background do you have to be able to do this? How did you learn to do this?

11

u/Straight-Spell-9930 Oct 20 '24

I did a Civil engineering technology 3-year diploma in college (not the most applicable but the surveying and geomatics helps). I worked for a drone research group at a college after graduating where I worked a lot with lidar and photogrammetry data. I've been teaching myself python for a few months now + many hours of researching google and referencing similar projects.

2

u/armour666 Oct 20 '24

Nice, I’m in my first year of that program

2

u/LumpyLongJohns Oct 20 '24

Looks cool, what altitude is the drone flying at?

4

u/Straight-Spell-9930 Oct 20 '24

Some of the above examples are at 400ft agl flown with the mavic 2 pro, and a few with a dji mini3 @ 1000ft agl

2

u/scottthemedic Oct 20 '24

I like the cut of your jib, sir.

If you'd like more testing or source images, let me know. I fly a fleet of M3T's at work, own a Mini 3 Pro, and have a gaggle of other drones in the "old fleet".

2

u/Straight-Spell-9930 Oct 20 '24

Much appreciated. Ideally I'm looking for M3M data. That being said, thermal data would be a great addition to my testing (and would eventually allow me to add support for M3T imagery). If you'd like to provide some example data for me to use it would be greatly appreciated. Some specifics for the data:

  • image grid flown with low overlap (around 10% side and front overlap)

  • flown at maximum legal height (usually 400ft agl if your area permits or higher)

  • flown over relatively flat terrain with minimal ground objects

  • Takeoff location @ similar elevation to the terrain your are mapping

  • maximum of 36 images (i like the small filesize dataset for testing)

  • minimum of 9 images (a minimum 3x3 grid allows me to test how the images overlap)

Some other bonuses if possible:

  • flown with rtk positioning

  • calibrate the drone imu on the day of the flight

  • calibrate compass onsite ensuring minimal nearby magnetic interference

  • flown on a day with relatively low windpseeds

  • google drive or similar download tool

Thanks!

2

u/scottthemedic Oct 20 '24

Let me talk to the guy I get drones from to know if he has any M3M's around...

2

u/RiceBucket973 Oct 20 '24

I'm often mapping rivers with riparian forest on both sides - any idea whether there could be workflow where I'm using Metashape to process the land portions and something like this for the open water? This is awesome by the way. Could it work with thermal images if there's good IMU metadata?

4

u/Straight-Spell-9930 Oct 20 '24

For combining with a finished photogrammetry ortho .tif file, one workflow could be to capture your standard photogrammetry grid w/high overlap. then refly a dedicated mission over the centre line of the river with lower overlap.

To combine them, import both final georeferenced .tif files into a gis program and mask the river .tif to only include the river. You can feather the image edges and tweak the colour/exposure if necesarry.

The final results will depend on how flat the river is. Currently the images assume a flat water body such as a pond, lake or ocean. If the river has a lot of elevation change then it won't work.

That being said your use case makes me think I should add something to account for changing ground elevation for long rivers

edit: yes, thermal images would work as well

1

u/RiceBucket973 Oct 20 '24

Just to wrap my head around how this works:

So the ground is assumed to be a plane, but is the height AGL determined by the GPS metadata? Or is that not even necessary to orthorectify images (pardon my ignorance). And if it is set by the GPS metadata, does it vary from image to image, or does the whole imageset get assigned one value for the drone AGL? I think this could also be useful for areas of dense tree canopy, or homogenous areas of reeds/grasses/early grain crops where it's also hard to find tie points.

4

u/Straight-Spell-9930 Oct 20 '24 edited Oct 20 '24

Yes, the height AGL is determined by the GPS metadata which is based on the takeoff altitude. In simple terms that is: GPS altitude - takeoff altitude = altitude AGL (dji actually uses barometric information in addition to gps altitude to calculate drone altitude for non-enterprise drones which results in poorer accuracy, rtk would produce much better results)

Each image is scaled/warped based on it's own metadata so the flight altitude can vary throughout the flight and produce good results. The ground altitude should not vary by large amounts (>10m)

For mapping using minimal tiepoints, chechout the below tool which is much more advanced than what I've created. This tool and the drone mapping tool in ArcGIS both rely on much fewer tie-points compared to standard photogrammetry and are better suited to the applications you mentioned.

https://github.com/NorthStarUAS/ImageAnalysis

The purpose behind my project is for mapping areas with 0 valid tie-points such as open water. The image examples I posted allow me to QC the image placing.

1

u/GIS_Sean Oct 21 '24

We've got a Mavic M3M. Do you want to send me some flight parameters and I'll ask one of the team to grab you some data? I can see you're looking for minimal overlap, anything else?

It's a shame you didn't post last week, we've just captured 1.2km of coastline along the Isle of Man, unfortunately only in RGB, not multispectral. If that is useful, I can always ask the client if they will allow me to share the raw data for you.

Let me know and I'll try to grab something for you this week and make it available on one of our FTP servers.

1

u/Straight-Spell-9930 Oct 21 '24

That would be amazing. I'll follow up with you in a private message. Thanks man

1

u/grogology Oct 24 '24

I just coded up a workflow to this end for open ocean (i.e. no tie points), projecting imagery based only on camera orientation (from photo metadata) and altitude (from the flight log). It's not perfect, but pretty darn good spatial localization for zero tie points. The key, for me, was using the python package 'CameraTransform' to project the image to earth coordinates based on camera orientation, then using GDAL/OGR to turn those coordinates to GCPs at the photo's edges and then warp the image with a 2nd degree polynomial. I think that, alternatively, you can achieve that with Rasterio too.

Sorry for not posting my code here - it's not exactly public-ready, but the logic and packages should get you there if you know some python!

2

u/Straight-Spell-9930 Oct 24 '24

Oh neat, it's good to see others working on the same problem. Similarly, my code is barely pieced together and using shortcuts so I can see what solutions works first before I make it public. I'm planning to rewrite everything soon using proper OOP because it's getting too complicated to manage the basic arrays and loops. Each image will be an object, so that I can store and modify its attributes like bounding corners, location, metadata, overlap regions, etc.

Currently I'm using opencv findHomography and warp perspective. Basically a pinhole camera model is represented by vectors and rotated to calculate the UTM ground points of the image corners which are then warped to the final pixel coordinates of the full orthomosaic. While it took more time to write it grants me greater control.

I'm going to read up on open ocean too. thanks for mentioning it.

1

u/grogology Oct 24 '24

Interesting thanks for sharing! findHomography sounds useful for scenarios where there's land/fixed features. I bet it could tighten up some of the distortion and misalignment that occurs when you're projecting/warping based only on camera location+orientation. I'm working with things like wildlife and sea ice that are drifting around from pic to pic (not to mention wave crests that appear and disappear), so that's my 'open ocean' scenario that confuses most cv-based alignment. I have some friends doing "ocean color" work (e.g. mapping phytoplankton blooms in open water) who have done a lot of work on camera-based georeferencing, I'll try to remember to post their git once it goes public.

1

u/Straight-Spell-9930 Oct 24 '24

Mapping algae blooms was actually my intended use case when making this. I'm getting some m3m data soon so I can make sure the program can handle it.

Theres a lot of distortion and misalignment in my examples because I'm just using standard drone GPS and IMU from a mavic 2 pro. Rtk and ppk positioning help a lot and a custom setup using a high end IMU, ppk and a dual GNSS for heading could deliver near perfect results on open water

1

u/grogology Oct 25 '24

Oo yeah, PPK would be a big help, and tighter IMU data. Will be curious what you settle on for those solutions! I was on a project last year that was exploring similar goals with a DJI M300, which had a built-in PPK system, but that was frustrating in a lot of ways mostly because DJI locks you into their particular proprietary workflows. And now DJI is simply off-limits for most of my work because of recent US legislation. 

3

u/evrano Oct 20 '24

Looks sick

2

u/thewrynoise Oct 21 '24

Gorgeous. Gonna save to follow up on.

1

u/Mountainman1913 Oct 20 '24

This is fantastic! Thank you.

1

u/CyberEd-ca Oct 28 '24

That's a lot of work to plan out your duck decoy set.