3D point cloud visualization

The last step is visualizing the triangulated 3D real-world points. An easy way of creating 3D scatterplots is by using matplotlib. However, if you are looking for more professional visualization tools, you may be interested in Mayavi (http://docs.enthought.com/mayavi/mayavi), VisPy (http://vispy.org), or the Point Cloud Library (http://pointclouds.org). Although the latter does not have Python support for point cloud visualization yet, it is an excellent tool for point cloud segmentation, filtering, and sample consensus model fitting. For more information, head over to strawlab's GitHub repository at https://github.com/strawlab/python-pcl.

Before we can plot our 3D point cloud, we obviously have to extract the [R | t] matrix and perform the triangulation as explained earlier:

def plot_point_cloud(self, feat_mode="SURF"):
    self._extract_keypoints(feat_mode)
    self._find_fundamental_matrix()
    self._find_essential_matrix()
    self._find_camera_matrices_rt()

    # triangulate points
    first_inliers = np.array(self.match_inliers1).reshape(-1, 3)[:, :2]
    second_inliers = np.array(self.match_inliers2).reshape(-1, 3)[:, :2]
    pts4D = cv2.triangulatePoints(self.Rt1, self.Rt2,first_inliers.T, second_inliers.T).T

    # convert from homogeneous coordinates to 3D
    pts3D = pts4D[:, :3]/np.repeat(pts4D[:, 3], 3).reshape(-1, 3)

Then, all we need to do is open a matplotlib figure and draw each entry of pts3D in a 3D scatterplot:

    Ys = pts3D[:,0]
    Zs = pts3D[:,1]
    Xs = pts3D[:,2]
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(Xs, Ys, Zs, c='r', marker='o')
    ax.set_xlabel('Y')
    ax.set_ylabel('Z')
    ax.set_zlabel('X')
    plt.show()

The result is most compelling when studied using pyplot's Pan axes button, which lets you rotate and scale the point cloud in all three dimensions. This will make it immediately clear that most of the points that you see lie on the same plane, namely the wall behind the fountain, and that the fountain itself extends from that wall in negative z coordinates. It is a little harder to draw this convincingly, but here we go:

3D point cloud visualization

Each subplot shows the recovered 3D coordinates of the fountain as seen from a different angle. In the top row, we are looking at the fountain from a similar angle as the second camera in the previous images, that is, by standing to the right and slightly in front of the fountain. You can see how most of the points are mapped to a similar x coordinate, which corresponds to the wall behind the fountain. For a subset of points concentrated between z coordinates -0.5 and -1.0, the x coordinate is significantly different, which shows different keypoints that belong to the surface of the fountain. The first two panels in the lower row look at the fountain from the other side. The last panel shows a birds-eye view of the fountain, highlighting the fountain's silhouette as a half-circle in the lower half of the image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.156.93