0
$\begingroup$

I need the bone-head coordinates to be mapped on to the camera view. Actual scenario is to obtain the 3D coordinates of bone/joint. This is how I do it now.

  scene = bpy.context.scene
  obj = bpy.context.object
  render_scale = scene.render.resolution_percentage / 100
      render_size = (
    int(scene.render.resolution_x * render_scale),
    int(scene.render.resolution_y * render_scale),
    )
  Bones16_WCO=[obj.pose.bones["Head"].head,obj.pose.bones["Neck"].head]
  for wco in Bones16_WCO:
      cco = bpy_extras.object_utils.world_to_camera_view(scene, cam, wco)
      print("2D Coords:", cco )     
      print("Pixel Coords:", (
       round(cco.x * render_size[0]),
      round(cco.y * render_size[1]),
  ))

This is with the help of link- How to find image coordinates of the rendered vertex?

However, I need this to be done for different animated model. So at each frame of animation, the above code to get the bone locations has to be executed. How do I iterate this for entire animation using python scripting?

$\endgroup$
3
  • $\begingroup$ thank you, I am trying to get each bones, convert to camera coordinates system and then to 2D: So far I am getting good results. Is there a way to change the 2d coordinate system? In blender it starts from bottom-left corner, but for image processing we need it from top-left corner. How can I change that? $\endgroup$
    – p.Neu
    Jan 24, 2017 at 16:24
  • $\begingroup$ Will find this useful too. blender.stackexchange.com/questions/1283/…. If you are getting good results suggest posting some code. Surely mapping bottom-left to top-left isn't too much of an issue? $\endgroup$
    – batFINGER
    Jan 24, 2017 at 16:38
  • $\begingroup$ no. not really. Thank you very much. I would update , once I fix this. For noe´w I am using the code from the linked answer. $\endgroup$
    – p.Neu
    Jan 24, 2017 at 16:49

1 Answer 1

1
$\begingroup$

So, here it is, was very close to the solution after the last update to the question

for f in frame_numbers:
            scene.frame_set( f )   
            for wco in Bones16_WCO:
                print("world Coords:", wco)
                cco = bpy_extras.object_utils.world_to_camera_view(scene, cam, wco)       
                x=(round(cco.x * render_size[0]))
                y=(render_size[1]-round(cco.y * render_size[1]))   
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .