1
$\begingroup$

I'm trying to set a background image to a camera using python, but no luck so far. The background image checkbox on the camera item is checked, but no file is loaded.

Also, I'm actually trying to load an image-sequence, not a still image.

filepath = "D:/path/to/image_seq.jpg"
img = bpy.data.images.load(filepath)
# cam is a camera object.
cam.data.show_background_images = True
bg = cam.data.background_images.new()
bg = img
$\endgroup$

1 Answer 1

5
$\begingroup$

You have to assign your image to bg.image. The last line should therefore be:

bg.image = img

Below you find a modified version of your code that runs properly.

import bpy

cam = bpy.context.scene.camera
filepath = "D:/path/to/image_seq.jpg"

img = bpy.data.images.load(filepath)
cam.data.show_background_images = True
bg = cam.data.background_images.new()
bg.image = img

If you want to use an image sequence you will have to set the img.source:

img.source = 'SEQUENCE'

Make sure that your filenames of the sequence are numbered, so that Blender can automatically identify the consecutive frames.

$\endgroup$

You must log in to answer this question.

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