Esempio n. 1
0
def unproject_Rt_identity_2x2_2xdepth_test():
    width = 2
    height = 2
    f = 1

    K = np.array((
                 (f, 0, width / 2.0),
                 (0, f, height / 2.0),
                 (0, 0, 1)
                 ))

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = np.identity(3)

    depth = 2
    point = unproject_corners(K, width, height, depth, Rt)

    assert point.shape == (2, 2, 3)

    assert point[0, 0, 0] == -2
    assert point[0, 0, 1] == -2

    assert point[0, 1, 0] == 2
    assert point[0, 1, 1] == -2

    assert point[1, 0, 0] == -2
    assert point[1, 0, 1] == 2

    assert point[1, 1, 0] == 2
    assert point[1, 1, 1] == 2

    assert (point[:, :, 2] == 2).all()
Esempio n. 2
0
def project_unproject_Rt_identity_test():
    width = 20
    height = 10
    f = 1

    K = np.array((
                 (f, 0, width / 2.0),
                 (0, f, height / 2.0),
                 (0, 0, 1)
                 ))

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = np.identity(3)

    depth = 1
    point = unproject_corners(K, width, height, depth, Rt)

    projection = project(K, Rt, point)

    assert projection.shape == (2, 2, 2)

    assert np.abs(projection[0, 0, 0]) < 1e-5
    assert np.abs(projection[0, 0, 1]) < 1e-5

    assert np.abs(projection[0, 1, 0] - width) < 1e-5
    assert np.abs(projection[0, 1, 1]) < 1e-5

    assert np.abs(projection[1, 0, 0]) < 1e-5
    assert np.abs(projection[1, 0, 1] - height) < 1e-5

    assert np.abs(projection[1, 1, 0] - width) < 1e-5
    assert np.abs(projection[1, 1, 1] - height) < 1e-5
Esempio n. 3
0
File: tests.py Progetto: cw11794/pa4
def project_unproject_Rt_random_randdepth_test():
    width = 20
    height = 10
    f = 1

    K = np.array(((f, 0, width / 2.0), (0, f, height / 2.0), (0, 0, 1)))

    A = np.random.random((3, 3))
    U, S, Vt = np.linalg.svd(A)
    R = U.dot(Vt)

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = R
    Rt[:, 3] = np.random.random(3)

    depth = 2
    point = unproject_corners(K, width, height, depth, Rt)

    projection = project(K, Rt, point)

    assert projection.shape == (2, 2, 2)

    assertNear(projection[0, 0, 0], 0, 1e-5)
    assertNear(projection[0, 0, 1], 0, 1e-5)

    assertNear(projection[0, 1, 0], width, 1e-5)
    assertNear(projection[0, 1, 1], 0, 1e-5)

    assertNear(projection[1, 0, 0], 0, 1e-5)
    assertNear(projection[1, 0, 1], height, 1e-5)

    assertNear(projection[1, 1, 0], width, 1e-5)
    assertNear(projection[1, 1, 1], height, 1e-5)
Esempio n. 4
0
File: tests.py Progetto: cw11794/pa4
def unproject_Rt_identity_1x1_test():
    width = 1
    height = 1
    f = 1

    K = np.array(((f, 0, width / 2.0), (0, f, height / 2.0), (0, 0, 1)))

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = np.identity(3)

    depth = 1
    point = unproject_corners(K, width, height, depth, Rt)

    assert point.shape == (2, 2, 3)

    assertNear(point[0, 0, 0], -0.5, 1e-5)
    assertNear(point[0, 0, 1], -0.5, 1e-5)

    assertNear(point[0, 1, 0], 0.5, 1e-5)
    assertNear(point[0, 1, 1], -0.5, 1e-5)

    assertNear(point[1, 0, 0], -0.5, 1e-5)
    assertNear(point[1, 0, 1], 0.5, 1e-5)

    assertNear(point[1, 1, 0], 0.5, 1e-5)
    assertNear(point[1, 1, 1], 0.5, 1e-5)

    assertNear(point[:, :, 2], 1, 1e-5)
Esempio n. 5
0
File: tests.py Progetto: cs4670/pa4
def project_unproject_Rt_identity_randdepth_test():
    width = 20
    height = 10
    f = 1

    K = np.array((
                 (f, 0, width / 2.0),
                 (0, f, height / 2.0),
                 (0, 0, 1)
                 ))

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = np.identity(3)

    depth = 2
    point = unproject_corners(K, width, height, depth, Rt)

    projection = project(K, Rt, point)

    assert projection.shape == (2, 2, 2)

    assertNear(projection[0, 0, 0], 0, 1e-5)
    assertNear(projection[0, 0, 1], 0, 1e-5)

    assertNear(projection[0, 1, 0], width, 1e-5)
    assertNear(projection[0, 1, 1], 0, 1e-5)

    assertNear(projection[1, 0, 0], 0, 1e-5)
    assertNear(projection[1, 0, 1], height, 1e-5)

    assertNear(projection[1, 1, 0], width, 1e-5)
    assertNear(projection[1, 1, 1], height, 1e-5)
Esempio n. 6
0
File: tests.py Progetto: cs4670/pa4
def unproject_Rt_identity_2x2_2xdepth_test():
    width = 2
    height = 2
    f = 1

    K = np.array((
                 (f, 0, width / 2.0),
                 (0, f, height / 2.0),
                 (0, 0, 1)
                 ))

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = np.identity(3)

    depth = 2
    point = unproject_corners(K, width, height, depth, Rt)

    assert point.shape == (2, 2, 3)

    assertNear(point[0, 0, 0], -2, 1e-6)
    assertNear(point[0, 0, 1], -2, 1e-6)

    assertNear(point[0, 1, 0], 2, 1e-6)
    assertNear(point[0, 1, 1], -2, 1e-6)

    assertNear(point[1, 0, 0], -2, 1e-6)
    assertNear(point[1, 0, 1], 2, 1e-6)

    assertNear(point[1, 1, 0], 2, 1e-6)
    assertNear(point[1, 1, 1], 2, 1e-6)

    assertNear(point[:, :, 2], 2, 1e-6)
Esempio n. 7
0
File: tests.py Progetto: cs4670/pa4
def project_unproject_Rt_random_randdepth_test():
    width = 20
    height = 10
    f = 1

    K = np.array((
                 (f, 0, width / 2.0),
                 (0, f, height / 2.0),
                 (0, 0, 1)
                 ))

    A = np.random.random((3, 3))
    U, S, Vt = np.linalg.svd(A)
    R = U.dot(Vt)

    Rt = np.zeros((3, 4), dtype=np.float32)
    Rt[:, :3] = R
    Rt[:, 3] = np.random.random(3)

    depth = 2
    point = unproject_corners(K, width, height, depth, Rt)

    projection = project(K, Rt, point)

    assert projection.shape == (2, 2, 2)

    assertNear(projection[0, 0, 0], 0, 1e-5)
    assertNear(projection[0, 0, 1], 0, 1e-5)

    assertNear(projection[0, 1, 0], width, 1e-5)
    assertNear(projection[0, 1, 1], 0, 1e-5)

    assertNear(projection[1, 0, 0], 0, 1e-5)
    assertNear(projection[1, 0, 1], height, 1e-5)

    assertNear(projection[1, 1, 0], width, 1e-5)
    assertNear(projection[1, 1, 1], height, 1e-5)
Esempio n. 8
0
reprojection needs to be done for this image.  Simply compute the normalized
patches across the entire image.
"""
right_normalized = preprocess_ncc(right[:, :, :3], ncc_size)
"""
We'll sweep a series of planes that are fronto-parallel to the right camera.
The image from the left camera is to be projected onto each of these planes,
normalized, and then compared to the normalized right image.
"""
volume = []
for pos, depth in enumerate(depths):
    """
    Unproject the pixel coordinates from the right camera onto the virtual
    plane.
    """
    points = unproject_corners(K_right, width, height, depth, Rt_right)
    """
    Project those points onto the two cameras to generate correspondences.
    """
    points_left = project(K_left, Rt_left, points)
    points_right = project(K_right, Rt_right, points)

    points_left = np.float32(points_left.reshape(-1, 2))
    points_right = np.float32(points_right.reshape(-1, 2))

    H, mask = cv2.findHomography(points_left, points_right)
    assert (mask == 1).all()

    projected_left = cv2.warpPerspective(left, H, (width, height))
    """
    Normalize this projected left image.
Esempio n. 9
0
patches across the entire image.
"""
right_normalized = preprocess_ncc(right[:, :, :3], ncc_size)

"""
We'll sweep a series of planes that are fronto-parallel to the right camera.
The image from the left camera is to be projected onto each of these planes,
normalized, and then compared to the normalized right image.
"""
volume = []
for pos, depth in enumerate(depths):
    """
    Unproject the pixel coordinates from the right camera onto the virtual
    plane.
    """
    points = unproject_corners(K_right, width, height, depth, Rt_right)

    """
    Project those points onto the two cameras to generate correspondences.
    """
    points_left = project(K_left, Rt_left, points)
    points_right = project(K_right, Rt_right, points)

    points_left = np.float32(points_left.reshape(-1, 2))
    points_right = np.float32(points_right.reshape(-1, 2))

    H, mask = cv2.findHomography(points_left, points_right)
    assert (mask == 1).all()

    projected_left = cv2.warpPerspective(left, H, (width, height))