Forum

Author Topic: Metashape model.pickPoint issue in version 2.1  (Read 5944 times)

JonathanMcGillivray

  • Newbie
  • *
  • Posts: 1
    • View Profile
Metashape model.pickPoint issue in version 2.1
« on: March 08, 2024, 03:01:12 PM »
When using chunk.model.pickPoint in python version 2.1 it seems to load the mesh for every separate function call. This loading of the mesh is extremely slow and causes multiple calls to the pickPoint function to be extremely inefficient / impossible to use. The pickPoint function also does not seem to allow for processing multiple points in a single call which would be fine when needing to process a batch of points. This issue did not occur before Metashape version 2.1

Here is the output for running it in the python console
for i in range(10):
    p = chunk.model.pickPoint(camera.center, camera.unproject([100,100]))
    print(p)
2024-03-08 11:40:54 loaded mesh in 0.667663 sec
2024-03-08 11:40:55 loaded mesh in 0.66498 sec
2024-03-08 11:40:56 loaded mesh in 0.664983 sec
2024-03-08 11:40:56 loaded mesh in 0.674484 sec
2024-03-08 11:40:57 loaded mesh in 0.671877 sec
2024-03-08 11:40:58 loaded mesh in 0.671404 sec
2024-03-08 11:40:58 loaded mesh in 0.672883 sec
2024-03-08 11:40:59 loaded mesh in 0.670517 sec
2024-03-08 11:41:00 loaded mesh in 0.673012 sec
2024-03-08 11:41:00 loaded mesh in 0.661756 sec
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])
2024-03-08 11:41:00 Vector([10.192707061767578, -145.27525329589844, -23.04425048828125])

When looking at the footprints_to_shapes.py script on Github which does something similar but uses multiple threads then it seems like the mesh is only loaded once. Not sure why but it would be nice to be able to still run the model.pickPoint function efficiently for a batch of points in a single thread.

This is the console output from running the footprints_to_shapes.py script on a project with a couple thousand images:
2024-03-08 11:44:04 To execute this script press Scripts/Create footprint shape layer
2024-03-08 11:44:12 Script started...
2024-03-08 11:44:13 loaded mesh in 0.654405 sec
2024-03-08 11:45:28 Script finished!

Paulo

  • Hero Member
  • *****
  • Posts: 1429
    • View Profile
Re: Metashape model.pickPoint issue in version 2.1
« Reply #1 on: March 08, 2024, 06:21:17 PM »
Hello,

I think that the view_mode must be set to Model Data outside loop so to load mesh only once (probably your default view_mode is set to Tie_points Data). See:
Code: [Select]
Metashape.app.model_view.view_mode = Metashape.DataSource.ModelData
2024-03-08 09:54:41 loaded mesh in 1.215 sec

for i in range(10):
    p = chunk.model.pickPoint(camera.center, camera.unproject([i*100,i*100]))
    print(p)
   
2024-03-08 09:55:36 Vector([-4.059615135192871, -2.7640161514282227, -9.319589614868164])
2024-03-08 09:55:36 Vector([-4.249917030334473, -2.972996950149536, -9.520050048828125])
2024-03-08 09:55:36 Vector([-4.044933319091797, -2.8117287158966064, -9.369665145874023])
2024-03-08 09:55:36 Vector([-3.8784561157226562, -2.687345504760742, -9.251367568969727])
2024-03-08 09:55:36 Vector([-3.7242331504821777, -2.5761122703552246, -9.141517639160156])
2024-03-08 09:55:36 Vector([-3.5773491859436035, -2.4710636138916016, -9.038172721862793])
2024-03-08 09:55:36 Vector([-3.4366350173950195, -2.3685312271118164, -8.9429931640625])
2024-03-08 09:55:36 Vector([-3.2960205078125, -2.271303653717041, -8.842096328735352])
2024-03-08 09:55:36 Vector([-3.0704894065856934, -2.2703800201416016, -8.480890274047852])
2024-03-08 09:55:36 Vector([-2.958159923553467, -2.164015054702759, -8.438690185546875])
« Last Edit: March 08, 2024, 07:02:24 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Fabio Cassinelli

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Metashape model.pickPoint issue in version 2.1
« Reply #2 on: March 15, 2024, 12:43:26 PM »
Hi
I also have the same problem, I tried your solution but it doesn't work, the problem remains.

Best regards

Fabio Cassinelli

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15320
    • View Profile
Re: Metashape model.pickPoint issue in version 2.1
« Reply #3 on: March 15, 2024, 04:32:10 PM »
Hello Jonathan, hello Fabio,

Do you run the related script from Metashape GUI?

If so, does it make any difference, if you switch to the mesh view  in the Model view?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Fabio Cassinelli

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Metashape model.pickPoint issue in version 2.1
« Reply #4 on: April 17, 2024, 11:38:12 AM »
Hello Alexey

Sorry, I missed your reply.

I run a separated Python script. This problem is present also in 2.1.1 version.

This is the function in a loop that is very slow:

Code: [Select]
chunk.model.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(Metashape.Vector(i))))

Also adding

Code: [Select]
Metashape.app.model_view.view_mode = Metashape.DataSource.ModelData

outside the loop does not solve the problem.

Fabio Cassinelli

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15320
    • View Profile
Re: Metashape model.pickPoint issue in version 2.1
« Reply #5 on: April 18, 2024, 06:38:16 PM »
Hello Fabio,

Can you please share the Console pane output related to the following code execution:

Code: [Select]
for i in range(10):
    p = chunk.model.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(Metashape.Vector([i*100,i*100]))))
    print(p)
providing that chunk, camera and sensor are properly defined.

Additionally please specify the number of faces in the model.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15320
    • View Profile
Re: Metashape model.pickPoint issue in version 2.1
« Reply #6 on: April 23, 2024, 02:18:48 PM »
In the next version update we will improve the performance of pickPoint operation, even if mesh display is not active in the Model view, the used mesh will be cached on the first call, providing that the following assignment is used:
Code: [Select]
model = chunk.model
for i in range(10):
    p = model.pickPoint(camera.center, camera.transform.mulp(sensor.calibration.unproject(Metashape.Vector([i*100,i*100]))))
    print(p)
Best regards,
Alexey Pasumansky,
Agisoft LLC