code: def corners_to_cxcywha(
      corners: jnp.ndarray, np_backbone: PyModule = jnp
  ) -> jnp.ndarray:
      """Convert four corners of [x, y] to [cx, cy, w, h, a].
  
      Although the conversion is only guaranteed to produce an exact rbox when given
      vertices that form an rbox, there is some graceful handling of nearly rbox
      vertices by choosing the rbox with corners minimizing the square distance to
      the rbox vertices. This solution is equivalent to taking the average of the
      top and bottom edges (wcorners*) as well as the left and right edges
      (hcornersy).
  
      Args:
        corners: [..., 4, 2]-ndarray of four corners of the rotated box as [x, y]
          points.
        np_backbone: Numpy module: Either the regular numpy package or jax.numpy.
  
      Returns:
        [..., 5]-ndarray of [center-x, center-y, width, height, angle]
        representation of rotated boxes. Angle is in radians and center of rotation
        is defined by [center-x, center-y] point.
      """
      assert (
          corners.shape[-2] == 4 and corners.shape[-1] == 2
      ), "Expected four corners [..., 4, 2] input."
  
      cornersx, cornersy = corners[..., 0], corners[..., 1]
      cx = np_backbone.mean(cornersx, axis=-1)
      cy = np_backbone.mean(cornersy, axis=-1)
      wcornersx = (
          cornersx[..., 0]
          + cornersx[..., 1]
          - cornersx[..., 2]
          - cornersx[..., 3]
      )
      wcornersy = (
          cornersy[..., 0]
          + cornersy[..., 1]
          - cornersy[..., 2]
          - cornersy[..., 3]
      )
      hcornersy = (
          -cornersy[
              ...,
              0,
          ]
          + cornersy[..., 1]
          + cornersy[..., 2]
          - cornersy[..., 3]
      )
      a = -np_backbone.arctan2(wcornersy, wcornersx)
      cos = np_backbone.cos(a)
      w = wcornersx / (2 * cos)
      h = hcornersy / (2 * cos)
      cxcywha = np_backbone.stack([cx, cy, w, h, a], axis=-1)
  
      return cxcywha
  
file_path: scenic/scenic/model_lib/base_models/box_utils.py
imports: from typing import Any, Union
  import jax.numpy
  import numpy
label_desc: Use image node_id 8 for calling a global function with example usage: corners_to_cxcywha(corners, np_backbone) and returns: cxcywha