Getting Camera position and rotation

I have a scene with a camera rotating around some objects. I am using the rendered animation for a computer vision project that is due in a couple of hours. How can I quickly get the camera global position and rotation for the 250 frames of my animation?

I am looking at a novel algorithm for detecting point correspondences between each frame of the animation. If I know the camera trajectory, I can reconstruct the 3D scene from the corresponding image point pairs.

I’m sure this has been asked before, but I’ve got a fast approaching deadline and I’m not familiar at all with the blender python interface.

Moved from “General Forums > Blender and CG Discussions” to “Coding > Python Support” (because I assume you want this data programmatically)

Assuming your camera’s name is “Camera”, you’ll probably want these (respectively):

cam_loc =["Camera"].location
cam_rot =["Camera"].rotation_euler

Both of these objects can be read like a list (0 = x, 1 = y, 2 = z)… so if you want the y location of your camera (and you used the above snippet), then you’d use:


Thanks a million, now how do I loop through frames?

so far I’ve got

c =[“Camera”]
s = bpy.types.Scene

for fr in range(1,250):
s.frame_current = fr
s.update() #This is giving me an error

The issue here is that you’ve got s assigned to a generic scene object; not the actual current scene that you’re working in. Try this:

cam =["Camera"]
s = bpy.context.scene # If your scene is named "Scene", you could also use["Scene"]

for fr in range(s.frame_start, s.frame_end):
    s.frame_current = fr
    s.update() # Not entirely sure this is fully necessary