original_docstring: Crops camera image to the specified bounding box and shifts keypoints.
  
    Args:
      image: input image to crop, an array with shape [height, width, 3].
      keypoints: a collection of camera keypoints.
      box: a 2D bounding box to extract from the input image.
      margin: a ratio of the extra margin to add to the image relative to the
        input image size.
  
    Returns:
      a tuple (new image, shifted keypoints).
    
docstring: Crops camera image to the specified bounding box and shifts keypoints.
docstring_tokens: Crops camera image to the specified bounding box and shifts keypoints .
code: def crop_camera_keypoints(
      image: np.ndarray,
      keypoints: Collection[keypoint_pb2.CameraKeypoint],
      box: label_pb2.Label.Box,
      margin: float = 0
  ) -> Tuple[np.ndarray, Collection[keypoint_pb2.CameraKeypoint]]:
    """Crops camera image to the specified bounding box and shifts keypoints.
  
    Args:
      image: input image to crop, an array with shape [height, width, 3].
      keypoints: a collection of camera keypoints.
      box: a 2D bounding box to extract from the input image.
      margin: a ratio of the extra margin to add to the image relative to the
        input image size.
  
    Returns:
      a tuple (new image, shifted keypoints).
    """
    new_camera_keypoints = []
    crop_width = (1 + margin) * box.length
    crop_height = (1 + margin) * box.width
    min_x = max(0, int(box.center_x - crop_width / 2))
    min_y = max(0, int(box.center_y - crop_height / 2))
    for old_kp in keypoints:
      new_kp = keypoint_pb2.CameraKeypoint()
      new_kp.CopyFrom(old_kp)
      new_p = new_kp.keypoint_2d.location_px
      new_p.x -= min_x
      new_p.y -= min_y
      new_camera_keypoints.append(new_kp)
    max_x = min(image.shape[1] - 1, int(box.center_x + crop_width / 2))
    max_y = min(image.shape[0] - 1, int(box.center_y + crop_height / 2))
    new_image = image[min_y:max_y, min_x:max_x, :]
    return new_image, new_camera_keypoints
code_tokens: def crop_camera_keypoints ( image : np . ndarray , keypoints : Collection [ keypoint_pb2 . CameraKeypoint ] , box : label_pb2 . Label . Box , margin : float = 0 ) -> Tuple [ np . ndarray , Collection [ keypoint_pb2 . CameraKeypoint ] ] : new_camera_keypoints = [ ] crop_width = ( 1 + margin ) * box . length crop_height = ( 1 + margin ) * box . width min_x = max ( 0 , int ( box . center_x - crop_width / 2 ) ) min_y = max ( 0 , int ( box . center_y - crop_height / 2 ) ) for old_kp in keypoints : new_kp = keypoint_pb2 . CameraKeypoint ( ) new_kp . CopyFrom ( old_kp ) new_p = new_kp . keypoint_2d . location_px new_p . x -= min_x new_p . y -= min_y new_camera_keypoints . append ( new_kp ) max_x = min ( image . shape [ 1 ] - 1 , int ( box . center_x + crop_width / 2 ) ) max_y = min ( image . shape [ 0 ] - 1 , int ( box . center_y + crop_height / 2 ) ) new_image = image [ min_y : max_y , min_x : max_x , : ] return new_image , new_camera_keypoints
short_docstring: Crops camera image to the specified bounding box and shifts keypoints.
short_docstring_tokens: Crops camera image to the specified bounding box and shifts keypoints .
comment: """Crops camera image to the specified bounding box and shifts keypoints.
  
    Args:
      image: input image to crop, an array with shape [height, width, 3].
      keypoints: a collection of camera keypoints.
      box: a 2D bounding box to extract from the input image.
      margin: a ratio of the extra margin to add to the image relative to the
        input image size.
  
    Returns:
      a tuple (new image, shifted keypoints).
    """