Get 2D bounding box of object in camera frame

Isaac Sim Version

4.2.0
4.1.0
4.0.0
2023.1.1
2023.1.0-hotfix.1
Other (please specify):

Operating System

Ubuntu 22.04
Ubuntu 20.04
Windows 11
Windows 10
Other (please specify):

Topic Description

Detailed Description

I am trying to get the 2D bounding box of an object in a specific camera frame using Python. I read Compute the Bounding Box for a Prim — Omniverse Developer Guide but don’t know how to go from the 3D range provided to the pixel coordinates. So far what I have is:

  imageable = UsdGeom.Imageable(pallet_prim)
  bound = imageable.ComputeWorldBound(Usd.TimeCode.Default(), UsdGeom.Tokens.default_)
  bound_range = bound.ComputeAlignedBox()

  world_T_camera = UsdGeom.Xformable(camera_prim).ComputeLocalToWorldTransform(Usd.TimeCode.Default()).GetInverse()
  min_point = bound_range.GetMin()
  max_point = bound_range.GetMax()

  # Calculate the vertices of the bounding box
  vertices = [
      min_point,
      Gf.Vec3d(min_point[0], min_point[1], max_point[2]),
      Gf.Vec3d(min_point[0], max_point[1], min_point[2]),
      Gf.Vec3d(min_point[0], max_point[1], max_point[2]),
      Gf.Vec3d(max_point[0], min_point[1], min_point[2]),
      Gf.Vec3d(max_point[0], min_point[1], max_point[2]),
      Gf.Vec3d(max_point[0], max_point[1], min_point[2]),
      max_point
  ]

What I am missing is getting the camera intrinsics and projecting into 2D pixel coordinates. For the intrinsics, I’ve had the most difficulty trying to get the resolution.