Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: CamMakoJ on March 08, 2017, 03:15:45 AM

Title: Exporting the extent of each camera's coverage of the Orthophoto
Post by: CamMakoJ on March 08, 2017, 03:15:45 AM
Just wondering if anyone has worked on or made a script that would export the extent of each cameras coverage on the orthophoto.
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Alexey Pasumansky on March 09, 2017, 10:38:57 AM
Hello CamMakoJ,

Do you mean something like footprints for each camera or the seamlines of the orthomosaic?
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: CamMakoJ on March 30, 2017, 07:23:07 PM
Yes exactly, the 'footprint' of each photo would be awesome
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Alexey Pasumansky on March 31, 2017, 04:05:37 PM
Hello CamMakoJ,

With the version 1.3.1 release I'll publish the script that will be creating footprint shape layer. We've extended API to make the script in more convenient way.
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Seboon on April 06, 2017, 05:51:01 PM
Hello Alexey,

Could you please tell us when you'll provide this script?

Thanks and regards!
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Alexey Pasumansky on April 06, 2017, 06:11:39 PM
Hello Seboon,

The following script should be creating the shape layer with the footprints related to the aligned cameras.

Each footprint would have four vertices.

Code: [Select]
#compatibility PhotoScan Pro 1.3.1
#creates footprint shape layer in the active chunk

import PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunk

if not chunk.shapes:
chunk.shapes = PhotoScan.Shapes()
chunk.shapes.crs = chunk.crs
T = chunk.transform.matrix
footprints = chunk.shapes.addGroup()
footprints.label = "Footprints"
footprints.color = (30, 239, 30)

if chunk.dense_cloud:
surface = chunk.dense_cloud
elif chunk.model:
surface = chunk.model
else:
surface = chunk.point_cloud

for camera in chunk.cameras:
if not camera.transform:
continue #skipping NA cameras

sensor = camera.sensor
corners = list()
for i in [[0, 0], [sensor.width - 1, 0], [sensor.width - 1, sensor.height - 1], [0, sensor.height - 1]]:
corners.append(surface.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(PhotoScan.Vector(i)))))
if not corners[-1]:
corners[-1] = chunk.point_cloud.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(PhotoScan.Vector(i))))
if not corners[-1]:
break
corners[-1] = chunk.crs.project(T.mulp(corners[-1]))

if not all(corners):
print("Skipping camera " + camera.label)
continue

if len(corners) == 4:
shape = chunk.shapes.addShape()
shape.label = camera.label
shape.attributes["Photo"] = camera.label
shape.type = PhotoScan.Shape.Type.Polygon
shape.group = footprints
shape.vertices = corners
shape.has_z = True

PhotoScan.app.update()
print("Script finished")
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Seboon on April 06, 2017, 06:17:04 PM
Alexey,

Your reactivity is impressive, as always!

Thanks a lot!
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: william on April 08, 2017, 01:32:20 AM
Thank you. I also happen to be very interested in this functionality, and I am very pleased to see the above script!
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: tkwasnitschka on May 03, 2017, 01:20:36 PM
While it may not be as straightforward as this example, a real help would be the incorporation of masks. It is pretty hard to adjusts masks procedurally without feedback on the resulting coverage.

In other words, I would like to have a preview wether my masks leave holes in the model or the texture, or not.
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: animesh_PRSD on June 01, 2017, 05:46:34 PM
Hello Alexey,

I tried a backdoor modification for Ver. 1.2.6. The console to problem is attached. can you help me identify the problem and mail me same on animesh.ce07@gmail.com

Thanks
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Alexey Pasumansky on June 01, 2017, 05:53:31 PM
Hello animesh_PRSD,

The script cannot be ported to the version 1.2.6 due to the lack of the required functions in the old Python API.

The error in the Console, however, states that proper indentation is not used inside "if" clause.
Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: jkova96 on February 29, 2024, 10:24:03 AM
Hi Alexey,

My company just buy software Agisoft Metashape, version 2.1 (newer version).
I have similar request, let's say that's similar.
So, state geodetic department of Croatia ask us to send them coordinates of 4 corners of each image footprint - to be visible in images EXIF. They also specified image format in which photos should be exported - .tif format.

Is there a way how to perform that if possible, it not can I somehow
get .txt file where 4 corners of image footprint are stored.

Thank you forwards!

Bye :)

J.K.

Title: Re: Exporting the extent of each camera's coverage of the Orthophoto
Post by: Alexey Pasumansky on February 29, 2024, 05:50:29 PM
Hello jkova96,

Do you have an example of the text file that you would like to save?  Or it is just camera name and additional eight columns (XY coordinates for 4 corners of image footprint)?

As for the EXIF - what tags should be used to include additional meta data to the images?