(H: np.ndarray)
return focal
Solve for w = H w H^t, with w = diag(a, a, b)

    >>> K = np.diag([0.8, 0.8, 1])
    >>> R = cv2.Rodrigues(np.array([0.3, 0, 0]))[0]
    >>> H = K.dot(R).dot(np.linalg.inv(K))
    >>> f = focal_from_homography(3 * H)
    >>> np.allclose(f, 0.8)
    True
Solve for w = H w H^t, with w = diag(a, a, b)
Solve for w = H w H^t with w = diag ( a a b )
def focal_from_homography(H: np.ndarray) -> np.ndarray:
    """Solve for w = H w H^t, with w = diag(a, a, b)

    >>> K = np.diag([0.8, 0.8, 1])
    >>> R = cv2.Rodrigues(np.array([0.3, 0, 0]))[0]
    >>> H = K.dot(R).dot(np.linalg.inv(K))
    >>> f = focal_from_homography(3 * H)
    >>> np.allclose(f, 0.8)
    True
    """
    H = H / np.linalg.det(H) ** (1.0 / 3.0)
    A = np.array(
        [
            [H[0, 0] * H[0, 0] + H[0, 1] * H[0, 1] - 1, H[0, 2] * H[0, 2]],
            [H[0, 0] * H[1, 0] + H[0, 1] * H[1, 1], H[0, 2] * H[1, 2]],
            [H[0, 0] * H[2, 0] + H[0, 1] * H[2, 1], H[0, 2] * H[2, 2]],
            [H[1, 0] * H[1, 0] + H[1, 1] * H[1, 1] - 1, H[1, 2] * H[1, 2]],
            [H[1, 0] * H[2, 0] + H[1, 1] * H[2, 1], H[1, 2] * H[2, 2]],
            [H[2, 0] * H[2, 0] + H[2, 1] * H[2, 1], H[2, 2] * H[2, 2] - 1],
        ]
    )
    _, (a, b) = nullspace(A)
    focal = np.sqrt(a / b)
    return focal
def focal_from_homography ( H : np . ndarray ) -> np . ndarray : H = H / np . linalg . det ( H ) ** ( 1.0 / 3.0 ) A = np . array ( [ [ H [ 0 , 0 ] * H [ 0 , 0 ] + H [ 0 , 1 ] * H [ 0 , 1 ] - 1 , H [ 0 , 2 ] * H [ 0 , 2 ] ] , [ H [ 0 , 0 ] * H [ 1 , 0 ] + H [ 0 , 1 ] * H [ 1 , 1 ] , H [ 0 , 2 ] * H [ 1 , 2 ] ] , [ H [ 0 , 0 ] * H [ 2 , 0 ] + H [ 0 , 1 ] * H [ 2 , 1 ] , H [ 0 , 2 ] * H [ 2 , 2 ] ] , [ H [ 1 , 0 ] * H [ 1 , 0 ] + H [ 1 , 1 ] * H [ 1 , 1 ] - 1 , H [ 1 , 2 ] * H [ 1 , 2 ] ] , [ H [ 1 , 0 ] * H [ 2 , 0 ] + H [ 1 , 1 ] * H [ 2 , 1 ] , H [ 1 , 2 ] * H [ 2 , 2 ] ] , [ H [ 2 , 0 ] * H [ 2 , 0 ] + H [ 2 , 1 ] * H [ 2 , 1 ] , H [ 2 , 2 ] * H [ 2 , 2 ] - 1 ] , ] ) _ , ( a , b ) = nullspace ( A ) focal = np . sqrt ( a / b ) return focal