I am trying to obtain the pixel coordinates (x, y) of the object that is rendered using pyrender. The aim is to get the bounding box coordinates of that object. I use OffScreenRenderer to render the scene.
r = pyrender.OffscreenRenderer(viewport_width=640,
viewport_height=480,
point_size=1.0)
color, depth = r.render(scene)
Available info: camera_to_world pose matrix
First I tried to plot the centroid of the object as below:
x, y = trimesh_mesh.centroid[:2]
height, width = image.shape[:2]
x = int(x * width)
y = int(y * height)
plt.imshow(image)
plt.scatter(x, y)
plt.show()
I get the following: image plot
Similary the bounding box plot for same object is here
Does anyone know how I can get the exact centroid and box coordinates of the rendered object? Thank you.
You are looking for
bpy_extras.object_utils.world_to_camera_view
.Use it like so:
See this answer on the Blender Stack Exchange