Fundamental matrix from camera matrices while preserving transpose

23 views Asked by At

Given a pair of camera matrices, P0 and P1, I want to determine their fundamental matrix using the function F. I know the fundamental matrix is only unique up to scale. However, it should obey the transpose property that the F(P0, P1) = F(P1, P0).T. My implementation does not obey this. What do I need to change for the transpose property to hold?

import torch


def skew(x):
    return torch.tensor(
        [
            [0, -x[2], x[1]],
            [x[2], 0, -x[0]],
            [-x[1], x[0], 0],
        ]
    )


def compute_camera_center(P):
    """Hartley and Zisserman, pg 158"""
    return -P[:3, :3].inverse() @ P[:, 3]


def F(P0, P1):
    """Hartley and Zisserman, pg 246"""
    c0 = compute_camera_center(P0)
    e1 = P1 @ torch.concat([c0, torch.ones(1)])
    e1 = e1 / e1[-1]
    return skew(e1) @ P1 @ P0.pinverse()

For the example camera matrices below, this implementation doesn't produce transpose equivalent fundamental matrices (although the fundamental matrices themselves are correct):

P0 = torch.tensor(
    [
        [-7.05e03, 3.45e03, 9.85e00, -4.90e05],
        [3.11e02, 9.13e02, 7.77e03, -1.57e06],
        [3.12e-01, 9.50e-01, -1.29e-03, -8.96e02],
    ]
)
P1 = torch.tensor(
    [
        [-1.33e03, -8.09e03, 2.89e01, 1.54e05],
        [-9.49e02, 4.71e01, 8.11e03, -1.38e06],
        [-1.00e00, 1.93e-02, 6.25e-05, -6.66e02],
    ]
)

print(F(P0, P1))
# tensor([[-4.0561e-03, -1.0436e+00,  9.8712e+02],
#         [-1.0368e+00,  4.1507e-03, -4.8989e+03],
#         [ 1.0004e+03,  7.4186e+03, -2.4306e+06]])

print(F(P1, P0))
# tensor([[-3.7487e-03, -9.5822e-01,  9.2449e+02],
#         [-9.6446e-01,  3.8492e-03,  6.8561e+03],
#         [ 9.1226e+02, -4.5275e+03, -2.2463e+06]])
0

There are 0 answers