Forum

Author Topic: List of assigned photos?  (Read 2892 times)

mwillis

  • Full Member
  • ***
  • Posts: 140
    • View Profile
List of assigned photos?
« on: July 06, 2022, 07:32:22 PM »
Hi, after assigning several images to an ortho, is it possible to auto generate a list of all the names of all the photos that where assigned?

Thanks!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: List of assigned photos?
« Reply #1 on: July 06, 2022, 08:14:01 PM »
Hello mwillis,

The example below prints out such list for the last shape drawn:

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

shape = chunk.shapes[-1]

patch = chunk.orthomosaic.patches[shape]

assigned_cameras = list()
for camera in chunk.cameras:
    if camera.key in patch.image_keys:
        assigned_cameras.append(camera)
print(assigned_cameras)
Best regards,
Alexey Pasumansky,
Agisoft LLC

mwillis

  • Full Member
  • ***
  • Posts: 140
    • View Profile
Re: List of assigned photos?
« Reply #2 on: July 06, 2022, 08:19:54 PM »
Alexey, you continue to be the greatest. Thank you.

mwillis

  • Full Member
  • ***
  • Posts: 140
    • View Profile
Re: List of assigned photos?
« Reply #3 on: July 09, 2022, 06:51:54 PM »
Hi Alexey, the script you wrote works fine with Patches but I actually used polygon when assigning the images.  I'm getting this error:

2022-07-09 10:47:26   File "C:/Users/Downloads/select_test.py", line 6, in <module>
2022-07-09 10:47:26     patch = chunk.orthomosaic.patches [shape]
2022-07-09 10:47:26 KeyError: <Shape '50'>
2022-07-09 10:47:26 Error: <Shape '50'>

What can I change to get it to work with polygons?  Sorry, not much programming skill on my end.

Thanks!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: List of assigned photos?
« Reply #4 on: July 12, 2022, 04:34:27 PM »
Hello Mark,

When you apply Assign Image command to a polygon, the orthomosaic.patches dictionary is automatically updated with the new element.

Note that using Update Orthomosaic command discards any assigned images (as they are already applied).

You can implement additional checks to skip elements that are not patches, now the code would output assigned images, if any, to all the shapes, skipping not polygonal shapes and shapes that do not have any images assigned:


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

for shape in [s for s in chunk.shapes is s.geometry.type == Metashape.Geometry.Type.PolygonType]:

    if shape not in chunk.orthomosaic.patches.keys():
        print(shape.label + " shape does not have assigned images, skipping.")
        continue
    patch = chunk.orthomosaic.patches[shape]

    assigned_cameras = list()
    for camera in chunk.cameras:
        if camera.key in patch.image_keys:
            assigned_cameras.append(camera)
    print(shape.key, shape.label, assigned_cameras)
print("Script finished.")
Best regards,
Alexey Pasumansky,
Agisoft LLC

flyzk

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: List of assigned photos?
« Reply #5 on: September 10, 2022, 12:29:37 AM »
Hello Alexey,

I have a similar need, but some of my shapes are not assigned to photo.
Instead of skipping them, I would like to have the list of photos used (assigned by agisoft during orthophoto building) by the orthomosaic into the area of my shapes.

Is it possible?

When I click right on the orthomosaic, there is a feature "open image" : it seems to be the photo assigned by agisoft for this point ? If so, there should be a solution for my need?
« Last Edit: September 10, 2022, 02:34:25 AM by flyzk »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: List of assigned photos?
« Reply #6 on: September 12, 2022, 11:42:14 AM »
Hello flyzk,

Do you need the rank 1 image from the Assign Image dialog for the shapes that do not have any images assigned manually? It is not the same, as image used for orthomosaic generation, as there could be multiple different "patches" inside the drawn shape.
Best regards,
Alexey Pasumansky,
Agisoft LLC

flyzk

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: List of assigned photos?
« Reply #7 on: September 12, 2022, 11:48:39 AM »
Hi and thanks for answer.

What I need is to be able to know which picture is used in orthomosaic at a given position (area of my shapes). Knowing that some parts of the orthomosaic are not assigned manually, and some parts are assigned manually.

What I would like would be : for every shape selected, having a list of the pictures assigned during the orthomosaic generation or pictures assigned manually (by patch or shape) : I'm only interested by the "last" photo assigned (manually or during orthomosaic generation) : the one really used by the orthomosaic when I use the script.
Knowing that the shapes for which I need the list of picture, are not the one used for assigning pictures.


There could be several images assigned by shape. What I'm expected is a list :
shape 1, image 1
shape 1, image 6
shape 1, image 9
shape 2, image 2
shape 2, image 5
etc..
« Last Edit: September 12, 2022, 12:02:11 PM by flyzk »

flyzk

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: List of assigned photos?
« Reply #8 on: September 12, 2022, 05:03:35 PM »
is it possible to get using python the list of pictures used for the orthomosaic generation?