Forum

Author Topic: Apply patch on multiple shapes  (Read 20856 times)

mcstieg

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Apply patch on multiple shapes
« Reply #15 on: May 01, 2020, 06:12:14 PM »
Hello benj_G,

In your code you are always assigning the first camera in the chunk to all the patches.

I'm attaching the script that performs automatic patching for all the polygonal shapes in the active chunk. Please check, if it works as expected. Note that the rank selection by the script is little bit different from the GUI version that is more complex.

This seems to work great, but only for georeferenced chunk - right?
What do I need to change to make it work for local ortho and local shapes?

Thank you!

mcstieg

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Apply patch on multiple shapes
« Reply #16 on: May 07, 2020, 07:11:51 AM »
Hello mcstieg,

It is not possible to fully replicate via Python the list of the images with the ranks, but as a workaround you can use the following metric:
estimate the XY of the image center projected on the surface and calculate the distance from it to the shape centroid.

Hello Alexey!

I have implemented this - thanks for that! For my code I also need to add a max search radius around the shape centroid. Only cameras inside this radius should be taken into account.
So I want to calculate the distance from the shape centroid vector (x,y) to the camera positions in the orthomosaic (must be x, y too)

Can you please tell me how to calculate the projected position of the cameras on the orthomosaic (like they are shown in ortho view)?

Thank you!!!!!!  :) 

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Apply patch on multiple shapes
« Reply #17 on: May 07, 2020, 03:05:01 PM »
Hello mcsteig,

If you need to get the geographic/projected coordinates of the camera center, then you need to take X and Y of the following vector:
Code: [Select]
chunk.crs.project(chunk.transform.matrix.mulp(camera.center))
Best regards,
Alexey Pasumansky,
Agisoft LLC

mcstieg

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Apply patch on multiple shapes
« Reply #18 on: May 09, 2020, 02:54:41 PM »
Thank you for that.

It is still not working as expected.

Just to make some things sure:
- I'm working in orthomosaic (not model).
- Local reference system normally (georef. possible)
- scaled via 12 bit markers
- The goal is to find the nearest camera to a shape...like shown via ruler function in my attachment.
- Therefore I calculate the shape centroid first.
- But the camera.center seems to be far away from the expected position, even if I look at X and Y in:
Code: [Select]
chunk.crs.project(chunk.transform.matrix.mulp(camera.center))
Thanks again!  :D
« Last Edit: May 09, 2020, 02:56:31 PM by mcstieg »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Apply patch on multiple shapes
« Reply #19 on: May 09, 2020, 05:47:29 PM »
Hello mcstieg,

If the chunk is referenced in the local coordinates, you should use the following transformation to get the coordinates of the camera centers in the reference coordinate system:
Code: [Select]
chunk.transform.matrix.mulp(camera.center)
But, of course, the XYZ coordinates of the resulting vector can be only used, if the orthomosaic projection plane is normal to one of the reference system axis, otherwise, you should consider the projection plane rotation matrix.
« Last Edit: May 09, 2020, 05:49:29 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

mcstieg

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Apply patch on multiple shapes
« Reply #20 on: May 11, 2020, 08:00:27 AM »
Before the calculation of orthomosaic I:
- rotate the model by 3 markers
- scale it 3 markers

Then I calculate the orthomosaic via GUI (Workflow, Build Orthomosaic, Local Coordinates).
So the rotation matrix should be the same, right?

But anyway, is there a way to get the rotation matrix from the model with python?
And how do I consider this matrix properly?

Thank you!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Apply patch on multiple shapes
« Reply #21 on: May 11, 2020, 04:38:41 PM »
Hello mcstieg,

Which projection plane have you selected when building orthomosaic? Was it Geographic -> Local Coordinates, or Planar?
Best regards,
Alexey Pasumansky,
Agisoft LLC

mcstieg

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Apply patch on multiple shapes
« Reply #22 on: May 11, 2020, 06:27:19 PM »
Hello Alexey!

Most models I use are in local coordinates system.
Where is the difference between local and local (m)?

As you see the shapes are in local (m), the model in local.
The ortho was built in geographic - local system as you can see.

I'd like to build ortho with the same markers I use for rotation of my model (planar - markers), but I don't know how to calculate the projection plane for that.
Also the python function for max dimension is unknown at the moment.

As I rotate models by markers, planar xy would also work for me.

Thank you again!



« Last Edit: May 11, 2020, 06:29:43 PM by mcstieg »

mcstieg

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Re: Apply patch on multiple shapes
« Reply #23 on: May 15, 2020, 02:21:34 PM »
Please give me a hint  ;)
Thank you!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Apply patch on multiple shapes
« Reply #24 on: May 15, 2020, 02:58:05 PM »
Hello mcstieg,

How you are creating shapes?

If you are generating them after the orthomosaic generation, does it help, if you set chunk.shapes.crs = chunk.orthomosaic.crs before adding any shapes to the chunk?
Best regards,
Alexey Pasumansky,
Agisoft LLC

fjgarciam

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Apply patch on multiple shapes
« Reply #25 on: August 24, 2020, 04:00:40 PM »
Hello, I am very interested in this thread, this is just what I am looking for. is there no way to assign the image with Rank 1 to a shape?

Lorenzoo

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Apply patch on multiple shapes
« Reply #26 on: March 30, 2024, 11:11:50 AM »
Hello all,

I have been trying to run this script on Version 2.1.1 build and keep getting the following error:

Error: 'Metashape.Shape' object has no attribute 'type'

Are there parts of the scripts I need to updated for it be compatible with V 2.1.1 ?

Thanks in advance for any assistance !  :)

Hello benj_G,

In your code you are always assigning the first camera in the chunk to all the patches.

I'm attaching the script that performs automatic patching for all the polygonal shapes in the active chunk. Please check, if it works as expected. Note that the rank selection by the script is little bit different from the GUI version that is more complex.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Re: Apply patch on multiple shapes
« Reply #27 on: April 01, 2024, 01:03:51 PM »
Hello Lorenzoo,

In 2.1 version to check that shape has polygon type you need to use the following:
Code: [Select]
shape.geometry.type == Metashape.Geometry.Type.PolygonType
Best regards,
Alexey Pasumansky,
Agisoft LLC

Lorenzoo

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Apply patch on multiple shapes
« Reply #28 on: April 09, 2024, 12:15:15 PM »
Hello Lorenzoo,

In 2.1 version to check that shape has polygon type you need to use the following:
Code: [Select]
shape.geometry.type == Metashape.Geometry.Type.PolygonType

Hi Alexey,

Thank you very much for that, that part works  :)

When i get to the section of code below, I now get the message:   Error: 'Metashape.Shape' object has no attribute 'vertices'

Is there different code that I should be using for V2.1  ?  Any help would be greatly appreciated.


def findCentroid(shape):
   area_sum = 0
   C = Metashape.Vector([0, 0])
   print("next bit7...")
   for i in range(1, len(shape.vertices) - 1):
      cent = shape.vertices[0] + shape.vertices + shape.vertices[i + 1]
      area = area2(shape.vertices[0], shape.vertices, shape.vertices[i + 1])
      C += Metashape.Vector([area * cent.x, area * cent.y])
      area_sum += area

   C /= (3 * area_sum)
   return C




I will attach the full code i'm trying to run...
« Last Edit: April 09, 2024, 12:24:13 PM by Lorenzoo »

Paulo

  • Hero Member
  • *****
  • Posts: 1362
    • View Profile
Re: Apply patch on multiple shapes
« Reply #29 on: April 09, 2024, 02:57:27 PM »
Hi,

Yes the coordinates of shape are now defined by shape.geometry.coordinates[0]... See attachment...
Best Regards,
Paul Pelletier,
Surveyor