sksurgerysurfacematch.algorithms.reconstructor_with_rectified_images module

Base class for surface reconstruction on already rectified images.

class sksurgerysurfacematch.algorithms.reconstructor_with_rectified_images.StereoReconstructorWithRectifiedImages(lower_disparity_multiplier: float = 2.0, upper_disparity_multiplier: float = 2.0, alpha: float = 0)[source]

Bases: sksurgerysurfacematch.interfaces.stereo_reconstructor.StereoReconstructor

Base class for those stereo reconstruction methods that work specifically from rectified images. This class handles rectification and the necessary coordinate transformations. Note: The client calls the reconstruct() method which requires undistorted images, which are NOT already rectified. It’s THIS class that does the rectification for you, and calls through to the _compute_disparity() method that derived classes must implement.

Constructor creates some member variables, so this class becomes statefull. You call reconstruct() once, and then you can call extract multiple times with different masks to pull out different subsets of data.

Parameters:
  • lower_disparity_multiplier – min=median - (this * std), default = 2.0.
  • upper_disparity_multiplier – max=median + (this * std), default = 2.0.
  • apha – OpenCV alpha parameter, default = 0.
extract(left_mask: numpy.ndarray)[source]

Extracts the actual point cloud. This is a separate method, so that you can reconstruct once using reconstruct(), and then call this extract method with multiple masks, without incurring the cost of multiple calls to the reconstruction algorithm, which may be expensive. :param left_mask: mask image, single channel, same size as left_image :return: [Nx6] point cloud where the 6 columns are x, y, z in left camera space, followed by r, g, b colours.

reconstruct(left_image: numpy.ndarray, left_camera_matrix: numpy.ndarray, right_image: numpy.ndarray, right_camera_matrix: numpy.ndarray, left_to_right_rmat: numpy.ndarray, left_to_right_tvec: numpy.ndarray, left_mask: numpy.ndarray = None)[source]

Implementation of stereo surface reconstruction that takes undistorted images, rectifies them, asks derived classes to compute a disparity map on the rectified images, and then sorts out extracting points and their colours.

Camera parameters are those obtained from OpenCV.

Parameters:
  • left_image – undistorted left image, BGR
  • left_camera_matrix – [3x3] camera matrix
  • right_image – undistorted right image, BGR
  • right_camera_matrix – [3x3] camera matrix
  • left_to_right_rmat – [3x3] rotation matrix
  • left_to_right_tvec – [3x1] translation vector
  • left_mask – mask image, single channel, same size as left_image
Returns:

[Nx6] point cloud where the 6 columns

are x, y, z in left camera space, followed by r, g, b colours.