CentralCamera.points2H#

static CentralCamera.points2H(p1: ndarray, p2: ndarray, method: str = 'leastsquares', seed: int | None = None, **kwargs) tuple[ndarray, float] | tuple[ndarray, float, ndarray][source]#

Estimate homography from corresponding points

Parameters:
  • p1 (ndarray(2,N)) – image plane points from first camera

  • p2 (ndarray(2,N)) – image plane points from second camera

  • method (str) – algorithm: ‘leastsquares’ [default], ‘ransac’, ‘lmeds’, ‘prosac’

  • kwargs – optional arguments as required for ransac’ and ‘lmeds’ methods

Returns:

homography, residual and optional inliers

Return type:

ndarray(3,3), float, ndarray(N,bool)

Compute a homography from two sets of corresponding image plane points whose world points lie on a plane.

Example:

>>> from machinevisiontoolbox import CentralCamera, mkgrid
>>> from spatialmath import SE3
>>> camera1 = CentralCamera(name="camera 1", f=0.002, imagesize=1000, rho=10e-6, pose=SE3.Tx(-0.1)*SE3.Ry(0.4))
>>> camera2 = CentralCamera(name="camera 2", f=0.002, imagesize=1000, rho=10e-6, pose=SE3.Tx(0.1)*SE3.Ry(-0.4))
>>> T_grid = SE3.Tz(1) * SE3.Rx(0.1) * SE3.Ry(0.2)
>>> P = mkgrid(3, 1.0, pose=T_grid)
>>> p1 = camera1.project_point(P)
>>> p2 = camera2.project_point(P);
>>> H, resid = CentralCamera.points2H(p1, p2)
>>> H
array([[ -0.4187,  -0.0004, 397.7657],
       [ -0.6981,   0.3738, 309.4588],
       [ -0.0014,  -0.    ,   1.    ]])
>>> resid
np.float64(4.838199100454595e-05)

Note

If the method is ‘ransac’ or ‘lmeds’ then a boolean array of inliers is also returned, True means the corresponding input point pair is an inlier.

References:
Seealso:

H decomposeH opencv.findHomography