# Absolute Orientation of Two 3D Point Sets

## Goal

Given two 3D point sets $P$ and $Q$ as $3{\times}N$ matrices, the absolute orientation is a problem that finds rotation $R$, translation $t$, and scale $s$ satisfying
\begin{equation}
Q = s R P + t .
\end{equation}

Here, each corresponding columns of $P$ and $Q$ are assumed to be a corresponding point pair in 3D.

* Input
  * $P$, $Q$
* Output
  * $R, t, s$


## References
* Horn. Closed-form solution of absolute orientation using unit quaternions, JOSA 1987


## Libraries


```python
%matplotlib notebook
import numpy as np
import os
import sys
import cv2
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
    sys.path.append(module_path)

from pycalib.calib import absolute_orientation

```

## Synthetic data


```python
N = 10
P = np.random.random((3, N))
R, _ = cv2.Rodrigues(np.random.random(3))
t = np.random.random(3)
s = np.random.random(1)
Q = s * (R @ P) + t[:, None]

fig = plt.figure()
ax = Axes3D(fig)
ax.plot(P[0,:], P[1,:], P[2,:], 'o')
ax.plot(Q[0,:], Q[1,:], Q[2,:], 'x')
fig.show()
```


    <IPython.core.display.Javascript object>






## Absolute Orientation


```python
R2, t2, s2 = absolute_orientation(P, Q)

P2 = s2 * (R2 @ P) + t2[:, None]

fig = plt.figure()
ax = Axes3D(fig)
ax.plot(P2[0,:], P2[1,:], P2[2,:], 'o')
ax.plot(Q[0,:], Q[1,:], Q[2,:], 'x')
fig.show()

assert np.allclose(R, R2)
assert np.allclose(t, t2)
assert np.allclose(s, s2)

```


    <IPython.core.display.Javascript object>






6a11c5e7d6878056b6c52192e46bd50f78588c37
ipynb
Jupyter Notebook
ipynb/absolute_orientation.ipynb
woodyZootopia/pycalib
5beb3d950c9ec830d7a031755bd269756bb62b9b
Apache-2.0
2019-06-14T01:25:20.000Z
2022-02-18T08:03:10.000Z
ipynb/absolute_orientation.ipynb
woodyZootopia/pycalib
5beb3d950c9ec830d7a031755bd269756bb62b9b
Apache-2.0
2019-09-30T08:31:14.000Z
2019-09-30T08:36:17.000Z
ipynb/absolute_orientation.ipynb
woodyZootopia/pycalib
5beb3d950c9ec830d7a031755bd269756bb62b9b
Apache-2.0
2019-09-30T07:37:47.000Z
2022-01-11T09:56:09.000Z
Qwen/Qwen-72B
1. YES
2. YES