I am trying to get the pixel coordinates of the object in the rendered image in blender using the How to find image coordinates of the rendered vertex? But I get the error AttributeError: 'Mesh' object has no attribute 'view_frame'
# Test the function using the active object (which must be a camera)
# and the 3D cursor as the location to find.
import bpy
import bpy_extras
scene = bpy.context.scene
obj = bpy.context.object
co = bpy.context.scene.cursor_location
co_2d = bpy_extras.object_utils.world_to_camera_view(scene, obj, co)
print("2D Coords:", co_2d)