0

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?

p.Neu
  • 61
  • 8
  • 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? – p.Neu Jan 24 '17 at 16:24
  • Will find this useful too. http://blender.stackexchange.com/questions/1283/how-to-get-world-space-matrix-of-any-pose-bone. If you are getting good results suggest posting some code. Surely mapping bottom-left to top-left isn't too much of an issue? – batFINGER Jan 24 '17 at 16:38
  • 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. – p.Neu Jan 24 '17 at 16:49

1 Answers1

1

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]))   
p.Neu
  • 61
  • 8