Forum

Author Topic: Select points according to masks  (Read 1784 times)

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Select points according to masks
« on: May 15, 2023, 10:51:48 AM »
Hey there!

I am looking for a way to automatically extract the reconstructed model from the artefacts. I was wondering if there's a way to select points from the point cloud according to the masks generated on the images? Like for each mask, ask Metashape to select the points situated in the white part of the image, according to the camera position.

Thank you!

Dr Popi

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Select points according to masks
« Reply #1 on: May 15, 2023, 12:31:16 PM »
Hello Dr Popi,

The following code shows how to select masked points according to the mask applied to the related camera:

Code: [Select]
chunk = Metashape.app.document.chunk
camera = chunk.cameras[0]
point_cloud = chunk.point_cloud
point_cloud.selectMaskedPoints([camera])
Best regards,
Alexey Pasumansky,
Agisoft LLC

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Select points according to masks
« Reply #2 on: May 15, 2023, 09:14:44 PM »
Hi Alexey!

Thank you very much, I'll give this a try this week and let you know  ;)

Kind regards,

Dr Popi

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Select points according to masks
« Reply #3 on: June 01, 2023, 11:52:26 AM »
Hello again!

I wanted to say that your solution works great, so thank you again! However I would add a small recommendation for any who would be interested in cleaning the dense cloud automatically this way. You need to actually make a loop where you first select the points, and then delete them, then go to the next iteration of the loop.

Here's my code:

Code: [Select]
point_cloud = doc.chunk.point_cloud

            for i in doc.chunk.cameras:
                log.info('Currently cleaning the point cloud, hang on')
                point_cloud.selectMaskedPoints([i])

                try:
                    point_cloud.removeSelectedPoints()

                except Exception:
                    log.error('There was no point selected, moving on')


The "try except" block is there to prevent the code from crashing when, for some reason, no point is selected. I tried in the API to find a way to get a list of the points that are currently selected, but I didn't find it (if anyone can enlighten me on that point, that would be great  :) ). I do think it would be more optimized to make a list of the selected points and add a condition that checks whether the list is empty or not.

Anyway, thanks again,

Dr Popi