You need to find the bpy.data.images
entry for the image. If you know the name of the image but not the path you can use bpy.data.images[NAME]
Once you know the entry, the full file path is in the filepath
member, so something like bpy.data.images['foo.png'].filepath
will return the full path to the image.
If you don't know the name, but you know you have only a single camera background image, you can use bpy.data.cameras['Camera'].background_images.items()
to fetch a list of all of the background images associated with the camera. Here's what the list looks like when there is only one image:
[(0, bpy.data.cameras['Camera']...CameraBackgroundImage)]
You can find the bpy.data.Images
entry from the second member of the tuple, so
items = bpy.data.cameras['Camera'].background_images.items()
camera_image = items[0][1]
filepath = camera_image.image.filepath
Will give you the full path to the first camera background image. For an non-camera background image you need to find the empty associated with the background image. Here's how to get the filepath for a background that's associated with an empty with the default name
filepath = bpy.data.objects['Empty'].data.filepath
UPDATE: about relative paths
If you have blender set up to use relative paths, filepath
will be a path that starts '//' indicating that it is relative to the directory where your blend file is stored. To pass this as an absolute path to functions that require such things, instead of filepath
, use bpy.path.abspath(filepath)
.