xrfeitoria.utils.projector

Project 3D points to 2D points, and draw 3D points on image, using XRPrimer camera.

xrfeitoria.utils.projector.draw_points3d(points3d: ndarray, camera_param: CameraParameter, image: ndarray | None = None, color: Tuple[int, int, int] = (255, 0, 0)) ndarray[source]

Draw 3d points on canvas. The 3d points will be projected to 2d points first. Then draw the 2d points on a canvas of the same size as the image. If image is not None, the canvas will be drawn on the image. Otherwise, the canvas will be returned which is a binary image, where 1 means the points are drawn.

Parameters:
  • point3d (np.ndarray) – [N, 3] points to project, where N is the number of points, and 3 is the location of each point. In convention of opencv.

  • camera_param (PinholeCameraParameter) – camera parameter

  • image (Optional[np.ndarray], optional) – [height, width, channel]. Defaults to None. If not None, the canvas will be drawn on the image with the given color.

  • color (Tuple[int, int, int], optional) – color of the points. Defaults to (255, 0, 0).

Returns:

np.ndarray – If image is None, return a binary image [H, W], where 1 means the points are drawn, dtype=np.bool. Otherwise, return a image [H, W, C] with the points drawn on it, dtype=np.uint8.

xrfeitoria.utils.projector.points2d_to_canvas(points2d: ndarray, resolution: Tuple[int, int]) ndarray[source]

Draw 2d points on canvas. The canvas is a binary image, where 1 means the points are drawn.

Parameters:
  • points2d (np.ndarray) – [N, 2] points to draw

  • resolution (Tuple[int, int]) – [height, width] of the canvas

Returns:

np.ndarray – [height, width] binary image, where 1 means the points are drawn, dtype=np.bool

xrfeitoria.utils.projector.project_points3d(points3d: ndarray, camera_param: CameraParameter) ndarray[source]

Project 3D point to 2D point.

Parameters:
  • point3d (np.ndarray) – [N, 3] points to project, where N is the number of points, and 3 is the location of each point. In convention of ‘opencv’.

  • camera_param (PinholeCameraParameter) – camera parameter in convention of xrprimer

Returns:

np.ndarray – [N, 2] projected 2d points, dtype=np.float32