def dino():
        img1 = cv2.imread(img1_path)
        img2 = cv2.imread(img2_path)
        pts1, pts2 = features.find_correspondence_points(
            img1, img2, feature, limit)
        points1 = processor.cart2hom(pts1)
        points2 = processor.cart2hom(pts2)

        fig, ax = plt.subplots(2, 1)
        ax[0].autoscale_view('tight')
        ax[0].imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB))
        ax[0].plot(points1[0],
                   points1[1],
                   'ro',
                   markerfacecolor='none',
                   markersize=2)
        ax[1].autoscale_view('tight')
        ax[1].imshow(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))
        ax[1].plot(points2[0],
                   points2[1],
                   'ro',
                   markerfacecolor='none',
                   markersize=2)
        fig.show()

        height, width, ch = img1.shape
        intrinsic = np.array([  # for dino
            [2360, 0, width / 2], [0, 2360, height / 2], [0, 0, 1]
        ])

        return points1, points2, intrinsic
示例#2
0
def house():
    input_path = 'imgs/house/'
    camera_filepath = 'imgs/house/3D/house.00{0}.P'

    cameras = [
        Camera(processor.read_matrix(camera_filepath.format(i)))
        for i in range(9)
    ]
    [c.factor() for c in cameras]

    points3d = processor.read_matrix(input_path + '3D/house.p3d').T  # 3 x n
    points4d = np.vstack((points3d, np.ones(points3d.shape[1])))  # 4 x n
    points2d = [
        processor.read_matrix(input_path + '2D/house.00' + str(i) + '.corners')
        for i in range(9)
    ]

    index1 = 2
    index2 = 4
    img1 = cv2.imread(input_path + 'house.00' + str(index1) +
                      '.pgm')  # left image
    img2 = cv2.imread(input_path + 'house.00' + str(index2) + '.pgm')

    # fig = plt.figure()
    # ax = fig.gca(projection='3d')
    # ax.plot(points3d[0], points3d[1], points3d[2], 'b.')
    # ax.set_xlabel('x axis')
    # ax.set_ylabel('y axis')
    # ax.set_zlabel('z axis')
    # ax.view_init(elev=135, azim=90)

    # x = cameras[index2].project(points4d)
    # plt.figure()
    # plt.plot(x[0], x[1], 'b.')
    # plt.show()

    corner_indexes = processor.read_matrix(
        input_path + '2D/house.nview-corners', np.int)
    corner_indexes1 = corner_indexes[:, index1]
    corner_indexes2 = corner_indexes[:, index2]
    intersect_indexes = np.intersect1d(np.nonzero([corner_indexes1 != -1]),
                                       np.nonzero([corner_indexes2 != -1]))
    corner_indexes1 = corner_indexes1[intersect_indexes]
    corner_indexes2 = corner_indexes2[intersect_indexes]
    points1 = processor.cart2hom(points2d[index1][corner_indexes1].T)
    points2 = processor.cart2hom(points2d[index2][corner_indexes2].T)

    height, width, ch = img1.shape
    intrinsic = np.array([  # for imgs/house
        [2362.12, 0, width / 2], [0, 2366.12, height / 2], [0, 0, 1]
    ])

    return points1, points2, intrinsic
示例#3
0
def dino(a, b):
    # Dino
    #img1 = cv2.imread('imgs/dinos/viff.003.ppm')
    #img2 = cv2.imread('imgs/dinos/viff.001.ppm')
    img1 = cv2.imread(a)
    img2 = cv2.imread(b)
    pts1, pts2 = features.find_correspondence_points(img1, img2)
    points1 = processor.cart2hom(pts1)
    points2 = processor.cart2hom(pts2)

    height, width, ch = img1.shape
    intrinsic = np.array([  # for dino
        [2360, 0, width / 2], [0, 2360, height / 2], [0, 0, 1]
    ])

    return points1, points2, intrinsic
示例#4
0
def test():
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import cv2

    # load points
    points = processor.read_matrix('testsets/house.p3d').T  # 3 x n
    points = processor.cart2hom(points)  # 4 x n

    img = cv2.imread('testsets/house1.jpg')
    height, width, ch = img.shape

    K = np.array([[width * 30, 0, width / 2], [0, height * 30, height / 2],
                  [0, 0, 1]])
    R = np.array([  # No rotation
        [1, 0, 0], [0, 1, 0], [0, 0, 1]
    ])
    t = np.array([[0], [0], [100]])  # t != 0 to be away from image plane

    # Setup cameras
    cam = Camera(K=K, R=R, t=t)
    x = cam.project(points)

    rotation_angle = 20
    rotation_mat = transformers.rotation_3d_from_angles(rotation_angle)
    cam = Camera(K=K, R=rotation_mat, t=t)
    x2 = cam.project(points)

    # Plot actual 3d points
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.set_aspect('equal')
    ax.plot(points[0], points[1], points[2], 'b.')
    ax.set_xlabel('x axis')
    ax.set_ylabel('y axis')
    ax.set_zlabel('z axis')
    ax.view_init(elev=140, azim=0)

    # Plot 3d to 2d projection
    f, ax = plt.subplots(2, sharex=True, sharey=True)
    plt.subplots_adjust(left=0.08,
                        bottom=0.08,
                        right=0.99,
                        top=0.95,
                        wspace=0,
                        hspace=0.01)
    ax[0].set_aspect('equal')
    ax[0].set_title(
        '3D to 2D projection. Bottom x-axis rotated by {0}°'.format(
            rotation_angle))
    ax[0].plot(x[0], x[1], 'k.')
    ax[1].plot(x2[0], x2[1], 'k.')
    plt.show()
示例#5
0
        def dino():
            img1 = cv2.imread(directory_name + "/" + filename)
            img2 = cv2.imread(directory_name1 + "/" + filename)
            pts1, pts2 = features.find_correspondence_points(img1, img2)
            points1 = processor.cart2hom(pts1)
            points2 = processor.cart2hom(pts2)

            fig, ax = plt.subplots(1, 2)
            ax[0].autoscale_view('tight')
            ax[0].imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB))
            ax[0].plot(points1[0], points1[1], 'r.')
            ax[1].autoscale_view('tight')
            ax[1].imshow(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))
            ax[1].plot(points2[0], points2[1], 'r.')
            fig.show()

            height, width, ch = img1.shape
            intrinsic = np.array([  # for dino
                [2360, 0, width / 2], [0, 2360, height / 2], [0, 0, 1]
            ])

            return points1, points2, intrinsic
示例#6
0
def dino():
    # Dino
    img1 = cv2.imread('../../../Desktop/imgs/dinos/viff.003.ppm')
    img2 = cv2.imread('../../../Desktop/imgs/dinos/viff.001.ppm')
    pts1, pts2 = features.find_correspondence_points(img1, img2)
    points1 = processor.cart2hom(pts1)
    points2 = processor.cart2hom(pts2)

    fig, ax = plt.subplots(1, 2)
    ax[0].autoscale_view('tight')
    ax[0].imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB))
    ax[0].plot(points1[0], points1[1], 'r.')
    ax[1].autoscale_view('tight')
    ax[1].imshow(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))
    ax[1].plot(points2[0], points2[1], 'r.')
    fig.show()

    height, width, ch = img1.shape
    intrinsic = np.array([  # for dino
        [2360, 0, width / 2], [0, 2360, height / 2], [0, 0, 1]
    ])

    return points1, points2, intrinsic
示例#7
0
intrinsic = np.array([[size, 0, center], [0, size, center], [0, 0, 1]])

# Points of on the surface of the cube
points3d = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2],
                     [2, 1, 0, 2, 1, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0],
                     [0, 0, 0, -1, -1, -1, -2, -2, -2, 0, 0, -1, -1, -2, -2],
                     [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])

# Define pose of cube with respect to camera1 in world view
rotation_mat = transformers.rotation_3d_from_angles(120, 0, 60)
translation_mat = np.matrix([0, 0, 5]).T
c = camera.Camera(K=intrinsic, R=rotation_mat, t=translation_mat)

# Project 3d points to camera1 on the left
points1 = c.project(points3d)
points1 = processor.cart2hom(points1)

# Get 4x4 homogenous extrinsic parameters of camera 1
H_c1 = np.vstack([c.extrinsic, [0, 0, 0, 1]])

# Define rotation of camera1 wrt camera2 and
# translation of camera2 wrt camera1
rotation_mat_wrt_c1 = transformers.rotation_3d_from_angles(0, -25, 0)
translation_mat_wrt_c1 = np.matrix([3, 0, 1]).T
H_c2_c1 = np.hstack([rotation_mat_wrt_c1, translation_mat_wrt_c1])
H_c1_c2 = extrinsic_from_camera_pose(H_c2_c1)

# Calculate pose of model wrt to camera2 in world view
H_c2 = np.dot(H_c1_c2, H_c1)

# Project 3d points to camera 2 on the right