Forum

Author Topic: py script - DJI camera relative altitude  (Read 4551 times)

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
py script - DJI camera relative altitude
« on: January 10, 2021, 09:58:24 PM »
I copied this script from the repository. 
It says " Script read RelativeAltitude information from DJI meta data for all the cameras in the active chunk # and loads it to the Reference pane instead of the existing data."

When I run it on a chunk with dji images, there is no difference in the altitude displayed in the reference pane.  Can someone explain what it is supposed to do.  It's purpose?

Thank you,
Dave

Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #1 on: January 11, 2021, 01:27:32 AM »
Dave,

did you check the Custom Menu on menu bar and click Read relative ...?

So what it does is read the relative DJI altitude from each photo metadata and writes it to your camera reference Z. So if you flew your mission at 50 m relative height from takeoff point, then all camera reference Z or altitude will be set to around 50...

So if you ran the script correctly and nothing changes then the DJI/Relative Altitude entry may not be present in your camera's metadata or maybe  DJI/Relative Altitude is equal to  DJI/Absolute Altitude ..To check this maybe you can attach an example image from your dataset?
« Last Edit: January 11, 2021, 02:05:07 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #2 on: January 11, 2021, 03:48:44 AM »
Hi Paul,

Indeed, I am running the script and the console says it finishes, but the altitude values for the cameras in the reference pane do not change if they are supposed to.  The z value in the reference pane matches the gps altitude in the exif data.

Attachments are:
1 Script runs and finishes.
2. Value in reference pane does not change.
3. exif gps altitude value as reported by exiftool.

I could provide an image if you think it would be helpful.  They are from a Phantom 4 Pro.

Thank you for your willingness to help!

Dave


Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #3 on: January 11, 2021, 05:50:26 AM »
Hi Dave,

could you enter the following lines in console pane pf your opened project:
Code: [Select]
chunk = Metashape.app.document.chunk

camera = chunk.cameras[0]

camera.photo.meta

and see the output you get. Should be something like:
Code: [Select]
{'DJI/AbsoluteAltitude': '+1864.63', 'DJI/FlightPitchDegree': '-6.80', 'DJI/FlightRollDegree': '+1.30', 'DJI/FlightYawDegree': '-88.80', 'DJI/GimbalPitchDegree': '-75.00', 'DJI/GimbalRollDegree': '+0.00', 'DJI/GimbalYawDegree': '-88.80', 'DJI/RelativeAltitude': '+45.80', 'DJI/RtkFlag': '0', 'Exif/ApertureValue': '4.97', 'Exif/DateTime': '2020:03:03 12:04:33', 'Exif/DateTimeOriginal': '2020:03:03 12:03:49', 'Exif/ExposureTime': '0.0025', 'Exif/FNumber': '5.6', 'Exif/FocalLength': '8.8', 'Exif/FocalLengthIn35mmFilm': '24', 'Exif/GPSAltitude': '1864.627', 'Exif/GPSLatitude': '39.6232487777778', 'Exif/GPSLongitude': '-104.876807305556', 'Exif/ISOSpeedRatings': '100', 'Exif/Make': 'DJI', 'Exif/Model': 'FC6310', 'Exif/Orientation': '1', 'Exif/ShutterSpeedValue': '8.643', 'Exif/Software': 'v01.07.1641', 'File/ImageHeight': '3648', 'File/ImageWidth': '5472', 'System/FileModifyDate': '2020:11:13 00:53:30', 'System/FileSize': '8101127'}
Check if you have DJI/RelativeAltitude and if is present whether it is different to Exif/GPSAltitude....


Best Regards,
Paul Pelletier,
Surveyor

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #4 on: January 11, 2021, 06:03:10 AM »
Hmmm...this is the console reply.

Code: [Select]
>>> chunk = Metashape.app.document.chunk

camera = chunk.cameras[0]

camera.photo.meta
2021-01-10 18:58:38   File "<console>", line 1
2021-01-10 18:58:38     chunk = Metashape.app.document.chunk

camera = chunk.cameras[0]

camera.photo.meta
2021-01-10 18:58:38                                         

     ^
2021-01-10 18:58:38 SyntaxError: invalid character in identifier
>>>

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #5 on: January 11, 2021, 06:09:50 AM »

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #6 on: January 11, 2021, 06:23:52 AM »
Paul,  I think I've discovered why there was no change.  I was using files that I edited.  I then use exiftool to clone the exif data from the originals onto the copies.  But apparently, there is still some difference. 

I started a new project with a sub-set of the originals.  Then, when I run the script the altitude changes, so it must be making some adjustment.  However, it only adjusts them about 9 meters.  What is that supposed to be?  The flight altitude was about 260' AGL (above take-off point).

And the code above still results in the same error in the console.

Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #7 on: January 11, 2021, 06:41:44 AM »
Yes that is the reason, David....

The RelativeAltitude tag is present in XMP DJI section as seen in following where i printed metadata for your submitted image and one from a regular P4Pro image:
 
DJI_0002.jpg {'Exif/ApertureValue': '2.97085', 'Exif/DateTime': '2020:12:31 11:09:08', 'Exif/DateTimeOriginal': '2020:12:31 11:09:07', 'Exif/ExposureTime': '0.003125', 'Exif/FNumber': '2.8', 'Exif/FocalLength': '8.8', 'Exif/FocalLengthIn35mmFilm': '24', 'Exif/GPSAltitude': '63.95', 'Exif/GPSLatitude': '46.8079801666298', 'Exif/GPSLongitude': '-123.030213166692', 'Exif/ISOSpeedRatings': '120', 'Exif/Make': 'DJI', 'Exif/Model': 'FC6310', 'Exif/Orientation': '1', 'Exif/ShutterSpeedValue': '8.31288', 'Exif/Software': 'v01.04.1546', 'File/ImageHeight': '3648', 'File/ImageWidth': '5472', 'System/FileModifyDate': '2021:01:10 21:14:35', 'System/FileSize': '9197148'}

DJI_0096.JPG {'DJI/AbsoluteAltitude': '+1864.63', 'DJI/FlightPitchDegree': '-6.80', 'DJI/FlightRollDegree': '+1.30', 'DJI/FlightYawDegree': '-88.80', 'DJI/GimbalPitchDegree': '-75.00', 'DJI/GimbalRollDegree': '+0.00', 'DJI/GimbalYawDegree': '-88.80', 'DJI/RelativeAltitude': '+45.80', 'DJI/RtkFlag': '0', 'Exif/ApertureValue': '4.97', 'Exif/DateTime': '2020:03:03 12:04:33', 'Exif/DateTimeOriginal': '2020:03:03 12:03:49', 'Exif/ExposureTime': '0.0025', 'Exif/FNumber': '5.6', 'Exif/FocalLength': '8.8', 'Exif/FocalLengthIn35mmFilm': '24', 'Exif/GPSAltitude': '1864.627', 'Exif/GPSLatitude': '39.6232487777778', 'Exif/GPSLongitude': '-104.876807305556', 'Exif/ISOSpeedRatings': '100', 'Exif/Make': 'DJI', 'Exif/Model': 'FC6310', 'Exif/Orientation': '1', 'Exif/ShutterSpeedValue': '8.643', 'Exif/Software': 'v01.07.1641', 'File/ImageHeight': '3648', 'File/ImageWidth': '5472', 'System/FileModifyDate': '2020:11:13 00:53:30', 'System/FileSize': '8101127'}

To come back to use of this script. This comes from the fact that for DJI drones, the altitude reported from the GPS is quite off so the idea is:
1. set reference Z for all cameras to relative altitude using the script (read_altitude_from_DJI_meta.py);
2. add the take off ground altitude to all reference Z using https://github.com/agisoft-llc/metashape-scripts/blob/master/src/add_altitude_to_reference.py.

This way your camera reference altitudes or Z will be much more realistic.

In your example image, reference altitude is set at 64 m flying at around 80 m AGL, then the real reference Z should be  something like 80 m + ground altitude (40 m maybe?) = 120 m
« Last Edit: January 11, 2021, 07:28:27 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #8 on: January 11, 2021, 06:57:33 AM »
Thanks, Paul.  That makes sense now.  It appears that the script is supposed to place the altitude of the cameras at or near the height above take-off.  Is that correct?  It is not supposed to return height above sea level (MSL) for the camera, correct?

Does running this script help improve the processing results in any way?

Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #9 on: January 11, 2021, 07:16:36 AM »
Please look at my previous post....
Best Regards,
Paul Pelletier,
Surveyor

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #10 on: January 11, 2021, 07:25:57 AM »
Got it, I apologize . I missed you comments after the exif as I was going back and forth.   Other than having the z values be much more realistic without the use of GCPs, have you found the reconstruction to otherwise be superior to not using this method?

Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #11 on: January 11, 2021, 07:32:46 AM »
Yes, if you use GCPs than your final estimated camera altitudes will be correct whether you use scripts or not . However if you do not use GCPs then using these scripts will give you results much closer to real ground elevation....
Best Regards,
Paul Pelletier,
Surveyor

dpitman

  • Full Member
  • ***
  • Posts: 236
    • View Profile
Re: py script - DJI camera relative altitude
« Reply #12 on: January 11, 2021, 08:55:05 AM »
Thank you, Paul !  You've been a great help.  :)