Forum

Author Topic: Aligning chunk based on 4x4 matrix  (Read 6159 times)

Arie

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Aligning chunk based on 4x4 matrix
« on: January 27, 2016, 04:32:28 PM »
Hello,
is it possible to align a chunk (translation + rotation) based on a 4x4 matrix?

I have a couple of datasets, that have been referenced by overlapping areas using an ICP algorithm (done in a different software). I have the 4x4 matrix of the transformation and would like to use that for referencing the chunk within Photoscan for DEM creation etc.

Cheers!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15086
    • View Profile
Re: Aligning chunk based on 4x4 matrix
« Reply #1 on: January 27, 2016, 04:51:07 PM »
Hello Arie,

Maybe you can send the sample project (in PSZ format) with two chunks that you wish to align in that way and text file with transformation matrices?
Also specify how they work: do you have two matrices that transforms two chunk to the same space, or single matrix that describes the transformation from the second chunk to the first (reference) chunk space?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Arie

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: Aligning chunk based on 4x4 matrix
« Reply #2 on: January 27, 2016, 05:07:39 PM »
Hi Alexey,
thanks for the quick reply!

The datasets have been processed in two seperate project files. One of the projects has been referenced using markers while the other project hasn't been referenced. I've exported both dense pointclouds and aligned them using Cloudcompare, resulting in a 4x4 matrix (http://www.cloudcompare.org/doc/wiki/index.php?title=Apply_Transformation).

So I was wondering if this can be used to reference the previously unreferenced project file for exporting DEM etc.

I could upload both project files, but the internet connections I have here is terribly slow and unstable.
Thanks for your help.


MarineL

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Aligning chunk based on 4x4 matrix
« Reply #3 on: March 08, 2022, 01:32:46 PM »
Hi,

I was wondering if you made any progress on this matter? I am trying to achieve the exact same thing  :)
I used Cloudcompare to co-register (align) two point clouds from the same location but surveyed at different times. I would then like to import the matrix that describes the transformation from the second model (chunk) to the first (reference) into Metashape.

The reason I am not trying to co-register models in Metashape (yet) is because the point alignment won't work (the 2 clouds are not alike enough to do so) and I would like to avoid placing markers manually (we are planning to use the coded markers later but it is always tricky to place permanent markers underwater for yearly surveys!).

Unfortunately the script works but the model to be aligned isn't aligned with the reference model. I suspect it is due to the fact that cloudcompare gives the reference model the matrix [1,1,1,1] while this is not the case in Metashape?

Thank you for your help :)

jedfrechette

  • Full Member
  • ***
  • Posts: 132
  • Lidar Guys
    • View Profile
    • www.lidarguys.com
Re: Aligning chunk based on 4x4 matrix
« Reply #4 on: March 09, 2022, 07:36:01 AM »
Can you share the script you're using? The key bit of code should be something like:
Code: [Select]
​chunk​.​transform​.​matrix​ ​=​  align_matrix​ ​*​ ​chunk.transform.matrix`align_matrix` is the matrix you get from Cloudcompare. It's a relative transform, which is why you need to multiply it by the chunk's existing matrix rather than just replacing it.
Jed

MarineL

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Aligning chunk based on 4x4 matrix
« Reply #5 on: March 09, 2022, 08:15:24 AM »
Thanks @jedfrechette that is exactly what I suspected. I was first using this script from an older post: https://www.agisoft.com/forum/index.php?topic=12053.0

So reading your suggestion I changed it to this:

import Metashape
doc = Metashape.app.document
chunk = doc.chunk
T = Metashape.Matrix([[0.996788382530, 0.080044053495, 0.002253011800, -0.223356008530],
                      [-0.080041415989, 0.995143175125, 0.057292371988, 0.072804056108],
                      [0.002343843691, -0.057288724929, 0.998355031013, 0.125097066164],
                      [0.000000000000, 0.000000000000, 0.000000000000, 1.000000000000]])
chunk.transform.matrix = T * chunk.transform.matrix

And it worked, amazing thank you so much !!