Forum

Author Topic: align model to model.py without GUI  (Read 1199 times)

Tom2L

  • Newbie
  • *
  • Posts: 13
    • View Profile
align model to model.py without GUI
« on: May 17, 2022, 10:37:37 AM »
Hi all,
I'd like to use the align model to model. py script in a larger scale python project.
In odrer to do so, i've extracted the functions from align model to model. py to my script, but i get the error :

Code: [Select]
Traceback (most recent call last):
  File "C:/Users/Thomas/Desktop/pycharm/crash_code.py", line 532, in <module>
    align_two_point_clouds(chunk.models[-1],chunk.models[1], scale_ratio = 0.99358)
  File "C:/Users/Thomas/Desktop/pycharm/crash_code.py", line 27, in align_two_point_clouds
    assert(isinstance(points1_source, np.ndarray) and isinstance(points2_target, np.ndarray))
AssertionError


I'm fairly new to python so i don't have enough experience to see what went wrong, that's why i'm asking for help.
Could anyone help me with this ?
I've attached the whole code below
Thanks in advance !

PolarNick

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: align model to model.py without GUI
« Reply #1 on: May 17, 2022, 12:55:59 PM »
Hi, these asserts check that input point clouds (arguments for align_two_point_clouds function) are numpy arrays. You called that function with chunk.models[-1] - which is not a numpy array.

In original script conversion from Metashape's project model representation to numpy array type is implemented via export to ply file and reading it as numpy array.

Tom2L

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: align model to model.py without GUI
« Reply #2 on: May 17, 2022, 04:45:01 PM »
Thanks a lot for your answer. Unfortunately, i don't get it very well : should i export my models as .ply file and then read then as numpy array ?
similary to :
Code: [Select]
                    self.chunk.exportModel(path=filename, binary=True,
                                      save_texture=False, save_uv=False, save_normals=False, save_colors=False,
                                      save_cameras=False, save_markers=False, save_udim=False, save_alpha=False,
                                      save_comment=False,
                                      format=Metashape.ModelFormatPLY)
                else:
                    self.chunk.dense_cloud = None
                    for dense_cloud in self.chunk.dense_clouds:
                        if dense_cloud.key == key:
                            self.chunk.dense_cloud = dense_cloud
                    assert(self.chunk.dense_cloud is not None)
                    self.chunk.exportPoints(path=filename,
                                       source_data=Metashape.DenseCloudData, binary=True,
                                       save_normals=False, save_colors=False, save_classes=False, save_confidence=False,
                                       save_comment=False,
                                       format=Metashape.PointsFormatPLY)

            v1 = read_ply(tmp1.name)
            v2 = read_ply(tmp2.name)

PolarNick

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: align model to model.py without GUI
« Reply #3 on: May 17, 2022, 05:27:11 PM »
Yes, looks like the simplest way.