| 462 | return renders, gts, image_names |
| 463 | |
| 464 | def align_pose(pose1, pose2): |
| 465 | mtx1 = np.array(pose1, dtype=np.double, copy=True) |
| 466 | mtx2 = np.array(pose2, dtype=np.double, copy=True) |
| 467 | |
| 468 | if mtx1.ndim != 2 or mtx2.ndim != 2: |
| 469 | raise ValueError("Input matrices must be two-dimensional") |
| 470 | if mtx1.shape != mtx2.shape: |
| 471 | raise ValueError("Input matrices must be of same shape") |
| 472 | if mtx1.size == 0: |
| 473 | raise ValueError("Input matrices must be >0 rows and >0 cols") |
| 474 | |
| 475 | # translate all the data to the origin |
| 476 | mtx1 -= np.mean(mtx1, 0) |
| 477 | mtx2 -= np.mean(mtx2, 0) |
| 478 | |
| 479 | norm1 = np.linalg.norm(mtx1) |
| 480 | norm2 = np.linalg.norm(mtx2) |
| 481 | |
| 482 | if norm1 == 0 or norm2 == 0: |
| 483 | raise ValueError("Input matrices must contain >1 unique points") |
| 484 | |
| 485 | # change scaling of data (in rows) such that trace(mtx*mtx') = 1 |
| 486 | mtx1 /= norm1 |
| 487 | mtx2 /= norm2 |
| 488 | |
| 489 | # transform mtx2 to minimize disparity |
| 490 | R, s = scipy.linalg.orthogonal_procrustes(mtx1, mtx2) |
| 491 | mtx2 = mtx2 * s |
| 492 | |
| 493 | return mtx1, mtx2, R |
| 494 | |
| 495 | def storePly(path, xyz, rgb): |
| 496 | # Define the dtype for the structured array |