コード例 #1
0
ファイル: tests.py プロジェクト: 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)
コード例 #2
0
ファイル: tests.py プロジェクト: 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)
コード例 #3
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
コード例 #4
0
	def predict(self, X):
		minDist = np.finfo('float').max
		minClass = -1
		Q = project(self.W, X.reshape(1,-1), self.mu)
		for i in range(len(self.projections)):
			dist = euclidianDist(self.projections[i], Q)
			if dist < minDist:
				minDist = dist
				minClass = self.y[i]
		# print("aaaaaaaaaaa")
		return minClass
コード例 #5
0
ファイル: test_minmax.py プロジェクト: yangly0815/scylla
def test_timeuuid(cql, test_keyspace):
    schema = "a int, b timeuuid, primary key (a,b)"
    with new_test_table(cql, test_keyspace, schema) as table:
        cql.execute(
            f'insert into {table} (a, b) values (0, 13814000-1dd2-11ff-8080-808080808080)'
        )
        cql.execute(
            f'insert into {table} (a, b) values (0, 6b1b3620-33fd-11eb-8080-808080808080)'
        )
        assert project(
            'system_todate_system_min_b',
            cql.execute(
                f'select todate(min(b)) from {table} where a = 0')) == [
                    Date('2020-12-01')
                ]
        assert project(
            'system_todate_system_max_b',
            cql.execute(
                f'select todate(max(b)) from {table} where a = 0')) == [
                    Date('2038-09-06')
                ]
コード例 #6
0
ファイル: tests.py プロジェクト: cw11794/pa4
def project_Rt_identity_upperleft_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)

    point = np.array(((-0.5, -0.5, 1), ), dtype=np.float32).reshape((1, 1, 3))

    projection = project(K, Rt, point)

    assert projection.shape == (1, 1, 2)
    assertNear(projection[0][0][0], 0, 1e-5)
    assertNear(projection[0][0][1], 0, 1e-5)
コード例 #7
0
def project_Rt_identity_centered_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)

    point = np.array(((0, 0, 1), ), dtype=np.float32).reshape((1, 1, 3))

    projection = project(K, Rt, point)

    assert projection.shape == (1, 1, 2)
    assert projection[0][0][0] == width / 2.0
    assert projection[0][0][1] == height / 2.0
コード例 #8
0
ファイル: tests.py プロジェクト: cw11794/pa4
def project_Rt_identity_20x10_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)

    point = np.array(height * width * [[0, 0, 1]], dtype=np.float32).reshape(
        (height, width, 3))

    projection = project(K, Rt, point)

    assert projection.shape == (height, width, 2)
    assertNear(projection[:, :, 0], width / 2.0, 1e-6)
    assertNear(projection[:, :, 1], height / 2.0, 1e-6)
コード例 #9
0
ファイル: tests.py プロジェクト: cw11794/pa4
def project_Rt_rot90_upperleft_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[0, 1] = 1
    Rt[1, 0] = -1
    Rt[2, 2] = 1

    point = np.array(((-0.5, -0.5, 1), ), dtype=np.float32).reshape((1, 1, 3))

    projection = project(K, Rt, point)
    assert projection.shape == (1, 1, 2)
    assertNear(projection[0][0][0], 0, 1e-5)
    assertNear(projection[0][0][1], height, 1e-5)
コード例 #10
0
ファイル: tests.py プロジェクト: cs4670/pa4
def project_Rt_identity_upperleft_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)

    point = np.array(((-0.5, -0.5, 1), ), dtype=np.float32).reshape((1, 1, 3))

    projection = project(K, Rt, point)

    assert projection.shape == (1, 1, 2)
    assertNear(projection[0][0][0], 0, 1e-5)
    assertNear(projection[0][0][1], 0, 1e-5)
コード例 #11
0
ファイル: tests.py プロジェクト: cs4670/pa4
def project_Rt_identity_20x10_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)

    point = np.array(height * width * [[0, 0, 1]], dtype=np.float32).reshape(
        (height, width, 3))

    projection = project(K, Rt, point)

    assert projection.shape == (height, width, 2)
    assertNear(projection[:, :, 0], width / 2.0, 1e-6)
    assertNear(projection[:, :, 1], height / 2.0, 1e-6)
コード例 #12
0
ファイル: tests.py プロジェクト: cs4670/pa4
def project_Rt_rot90_upperleft_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[0, 1] = 1
    Rt[1, 0] = -1
    Rt[2, 2] = 1

    point = np.array(((-0.5, -0.5, 1), ), dtype=np.float32).reshape((1, 1, 3))

    projection = project(K, Rt, point)
    assert projection.shape == (1, 1, 2)
    assertNear(projection[0][0][0], 0, 1e-5)
    assertNear(projection[0][0][1], height, 1e-5)
コード例 #13
0
ファイル: tests.py プロジェクト: 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)
コード例 #14
0
ファイル: plane_sweep_stereo.py プロジェクト: cs4670/pa4
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.
    """
    left_normalized = preprocess_ncc(projected_left, ncc_size)
コード例 #15
0
ファイル: plane_sweep_stereo.py プロジェクト: cw11794/pa4
"""
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.
    """
    left_normalized = preprocess_ncc(projected_left, ncc_size)
    """
    Compute the NCC score between the right and left images.
コード例 #16
0
	def train(self, X, y):
		[D, self.W, self.mu] = PCA(asRowMatrix(X),y)
		self.y = y
		for xi in self.X:
			self.projections.append(project(self.W, xi.reshape(1,-1), self.mu))
コード例 #17
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):
    # Task 5: complete the plane sweep stereo loop body by filling in
    # the following TODO lines

    # (TODO) Unproject the pixel coordinates from the right camera onto the virtual plane.
    points = unproject_corners(K_right, width, height, depth, Rt_right)

    # (TODO) Project the 3D corners into the two cameras to generate correspondences.
    points_left = project(K_left, Rt_left, points).reshape((4, 2))
    points_right = project(K_right, Rt_right, points).reshape((4, 2))

    # Solve for a homography to map the left image to the right:
    # Note: points_left and points_right should have shape 4x2
    # where each row contains (x,y)
    H, _ = cv2.findHomography(points_left, points_right)

    # Warp left image onto right image
    projected_left = cv2.warpPerspective(left, H, (width, height))

    # (TODO) Normalize the left image in preparation for NCC
    left_normalized = preprocess_ncc(projected_left, ncc_size)

    # (TODO) Compute the NCC score between the right and left images.
    ncc = compute_ncc(right_normalized, left_normalized)