Agisoft Metashape

Agisoft Metashape => Feature Requests => Topic started by: jtheule on September 27, 2019, 03:02:17 PM

Title: Iterative Closest Point Algorithm
Post by: jtheule on September 27, 2019, 03:02:17 PM
Hello,
In my work I often have to export the dense point cloud from Agisoft into CloudCompare to align it with previous lidar datasets using ICP.

I do this because there are no ground control points, only the refence point cloud (Lidar) on the mountain sides.

It is very time consuming.
In CloudCompare, I cut out chunks of permanent features, run alignment. Then I match identifiable points and their coordinates and then make GCP point in Agisoft for better optimization.

It would be nice to have Agisoft to be able to import other point clouds and align selected features for optimization.

I am pretty sure this is not so easy to do, but I thought to had it to a wish list
Title: Re: Iterative Closest Point Algorithm
Post by: stephan on October 03, 2019, 03:31:13 PM
Hi there!

You can import Open3D to the photoscan python envirnomlent and use the ICP algorithm in there to compute the transformations that you need, then apply them directly in photoscan to your chunks.

Cheers,
Stephan
Title: Re: Iterative Closest Point Algorithm
Post by: piste on April 16, 2020, 10:05:39 AM
Hi Stephan,

have you ever tried that? And does it work?

I am willing to try it myself but I would like to have some feedback from the members of this community.
Even better if someone could share the script but I guess that might be confidential...

Regards,
Title: Re: Iterative Closest Point Algorithm
Post by: PolarNick on April 29, 2020, 02:22:24 PM
Hi, you can try this script - https://github.com/agisoft-llc/metashape-scripts/blob/master/src/align_model_to_model.py
Title: Re: Iterative Closest Point Algorithm
Post by: Paulo on April 30, 2020, 06:16:05 AM
Hi PolarNick,

i downloaded the script and tried to install the modules open3d and pyhull using:

Code: [Select]
"%programfiles%\Agisoft\Metashape Pro\python\python.exe" -m pip install open3d pyhull
open3d is installed but pyhull installation fails with following error:

Code: [Select]
Building wheels for collected packages: pyhull
  Running setup.py bdist_wheel for pyhull: started
  Running setup.py bdist_wheel for pyhull: finished with status 'error'
  Complete output from command "C:\Program Files\Agisoft\Metashape Pro\python\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\PAUL~1.PEL\\AppData\\Local\\Temp\\pip-build-1_g15vzt\\pyhull\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d C:\Users\PAUL~1.PEL\AppData\Local\Temp\tmpg_10nry1pip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.5
  creating build\lib.win-amd64-3.5\pyhull
  copying pyhull\convex_hull.py -> build\lib.win-amd64-3.5\pyhull
  copying pyhull\delaunay.py -> build\lib.win-amd64-3.5\pyhull
  copying pyhull\halfspace.py -> build\lib.win-amd64-3.5\pyhull
  copying pyhull\simplex.py -> build\lib.win-amd64-3.5\pyhull
  copying pyhull\voronoi.py -> build\lib.win-amd64-3.5\pyhull
  copying pyhull\__init__.py -> build\lib.win-amd64-3.5\pyhull
  running build_ext
  building 'pyhull._pyhull' extension
  error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
 
  ----------------------------------------
  Running setup.py clean for pyhull
Failed to build pyhull
Installing collected packages: pyhull, jupyter-core, tornado, pyzmq, jupyter-client
  Running setup.py install for pyhull: started
    Running setup.py install for pyhull: finished with status 'error'
    Complete output from command "C:\Program Files\Agisoft\Metashape Pro\python\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\PAUL~1.PEL\\AppData\\Local\\Temp\\pip-build-1_g15vzt\\pyhull\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\PAUL~1.PEL\AppData\Local\Temp\pip-epjll0cq-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.5
    creating build\lib.win-amd64-3.5\pyhull
    copying pyhull\convex_hull.py -> build\lib.win-amd64-3.5\pyhull
    copying pyhull\delaunay.py -> build\lib.win-amd64-3.5\pyhull
    copying pyhull\halfspace.py -> build\lib.win-amd64-3.5\pyhull
    copying pyhull\simplex.py -> build\lib.win-amd64-3.5\pyhull
    copying pyhull\voronoi.py -> build\lib.win-amd64-3.5\pyhull
    copying pyhull\__init__.py -> build\lib.win-amd64-3.5\pyhull
    running build_ext
    building 'pyhull._pyhull' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
   
    ----------------------------------------

But I do have Visual Studio Build Tools installed as shown in following screen capture...

What am I missing here?

Help would be welcome!
Title: Re: Iterative Closest Point Algorithm
Post by: PolarNick on May 01, 2020, 01:56:30 PM
Hi Paulo,

1) It seems that "MSVC v140 - VS 2015 C++ Build Tools (v14.00)" should be installed - see attached screenshot (I also downloaded https://visualstudio.microsoft.com/visual-cpp-build-tools/ -> Download Build Tools).

2) Note that after that I encountered another error:

LINK : fatal error LNK1158: cannot run 'rc.exe'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe' failed with exit status 1158

This problem seems to be due to multiple installed versions of Visual Studio :( and w.r.t. https://stackoverflow.com/a/14373113 you should:

2.1) Open C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64
2.2) Copy rc.exe and rcdll.dll to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
2.3) Try pip install pyhull again (worked for me)

3) Note that installation of the open3d led to upgrading some of python packages used in Metashape (jupyter notebook package used for rich python console), and so you will see 'Please wait while Windows configures Agisoft Metashape Professional' (see second screenshot) - after that Metashape will launch and everything will work.
Title: Re: Iterative Closest Point Algorithm
Post by: Paulo on May 01, 2020, 05:57:38 PM
Hey PolarNick,

thanks for the recipe. It worked!

And in the VS Build Tools 2019 installation options, I only ticked Windows 10 SDK and MSVC v140....
Title: Re: Iterative Closest Point Algorithm
Post by: cagritaskin on July 05, 2020, 11:19:06 PM
Hello,

I am trying to use align_model_to_model.py. I managed to install open3d and pyhull. When i run the script i get error: "Importing zmq.backend.cython dailed with zmq.backend.cython.socket.Socket has the wrong size, try recompiling. Expected 72, got 64"

Thanks for any help
Title: Re: Iterative Closest Point Algorithm
Post by: cagritaskin on July 05, 2020, 11:47:44 PM
Hi. I installed open3d 0.9.0.0 instead of 0.8.0.0 and problem solved
Title: Re: Iterative Closest Point Algorithm
Post by: jnb on February 19, 2021, 01:47:57 AM
Hello,

I'm trying to use this script on v1.7.1. Thanks to the indications given by PolarNick the installation went fine but when running it I have the following error : AttributeError: module 'open3d' has no attribute 'registration'.

Some research seems to indicate that 'registration' has now moved to 'open3d.pipelines' but my skills in python are to limited to understand more...

Thanks for any help

EDIT : Thank you PolarNick for the updated script, works perfectly now !
Title: Re: Iterative Closest Point Algorithm
Post by: antoine billault on February 16, 2022, 07:07:26 AM
Dear all,
I was wondering if the alignement of the photo was automaticcally update when using that ICP script ?
I mean : if I am aligning a 3D model on a pointcloud, I guess the images (in the chunk containing that 3D model) are directly rotated and translated ?
by an additionnal command in the script ?
should we update the pose of each image ?

thanks for your comments.
antoine
Title: Re: Iterative Closest Point Algorithm
Post by: PolarNick on February 16, 2022, 01:32:29 PM
Script changes only position of model/point cloud.

Maybe switching From and To objects will work for you? (i.e. aligning point cloud on a 3D model instead of aligning 3D model on a point cloud)
Title: Re: Iterative Closest Point Algorithm
Post by: Andreas1206 on April 18, 2022, 01:37:48 PM
Hello,

When I run through this script to align an imported scanned mesh to a photogrammetric mesh, everything seems to work fine in the intermediate alignment stages. They show good results (see attached print screen). However, after the final step when the script is finished, the "aligned" mesh is placed somewhere way off in the coordinate system. What could be the reason for this?

I am using the "Coordinate system to bounding box" script before importing the scanned mesh, in order to align the photogrammetric mesh in my local coordinate system - does this transformation maybe somehow interfere with the ICP alignment matrix?

thanks for any advice,
Andreas
Title: Re: Iterative Closest Point Algorithm
Post by: Alexey Pasumansky on April 18, 2022, 05:45:14 PM
Hello Andreas,

To analyze the problem we need to reproduce it on our side. Would it be possible to share the following data to support@agisoft.com:
- project file (could be re-saved in PSZ format),
- file to be imported,
- description of the steps that you follow.
Title: Re: Iterative Closest Point Algorithm
Post by: Guarouba on April 20, 2022, 03:22:59 PM
Hello,

I have the same problem as Andreas1206 when trying to align two point clouds. When visualizing the intermediate steps, everything looks fine. However, after the process, the point cloud disappears in Metashape.  I have sent you the data to reproduce the issue to the email address mentioned above.

Regards,
Title: Re: Iterative Closest Point Algorithm
Post by: mattabao on July 05, 2023, 12:51:35 PM
Hi PolarNick,

thank you for your script. But after it was installed and run it, an error occured which says

Traceback (most recent call last):
File "C:/Users/kouzoulab/Downloads/align_model_to_model.py", line 497, in align
self.chunk.exportPoints(path=filename,
AttributeError: 'Metashape.Chunk' object has no attribute 'exportPoints'

can you help me with this please?

please see attachment
Title: Re: Iterative Closest Point Algorithm
Post by: PolarNick on July 05, 2023, 07:01:52 PM
Hi mattabao,

please try updated version (https://github.com/agisoft-llc/metashape-scripts/blob/master/src/align_model_to_model.py), now it should work.
Title: Re: Iterative Closest Point Algorithm
Post by: mattabao on July 06, 2023, 05:02:24 AM
Thank you, PolarNick! your code is now working.
But, the result of combining my model is not good. Should I move the two models close to each other or should I make an initial alaignment before running your script?
Title: Re: Iterative Closest Point Algorithm
Post by: mattabao on July 06, 2023, 05:10:01 AM
PolarNick,

in addition, I did not input value in scale ration and target resolution. is this necessary to input value? what value shoul I input then?
What does target resolution mean?
Title: Re: Iterative Closest Point Algorithm
Post by: PolarNick on July 06, 2023, 12:22:27 PM
You can read about these optional parameters here (https://github.com/agisoft-llc/metashape-scripts/blob/20f6058608049ab57eb6fd9c9d365d1d1598345e/src/align_model_to_model.py#L8-L11) and here (https://github.com/agisoft-llc/metashape-scripts/blob/20f6058608049ab57eb6fd9c9d365d1d1598345e/src/align_model_to_model.py#L48-L56)
Title: Re: Iterative Closest Point Algorithm
Post by: PolarNick on July 06, 2023, 02:21:24 PM
Also note that there are tooltips - just hover mouse above parameter fields, or you can read them here (https://github.com/agisoft-llc/metashape-scripts/blob/20f6058608049ab57eb6fd9c9d365d1d1598345e/src/align_model_to_model.py#L384-L403)