Skip to content

Instantly share code, notes, and snippets.

@amb
Created June 17, 2022 20:18
Show Gist options
  • Save amb/5d411b2a0de118ee7eba02e87d6ccca2 to your computer and use it in GitHub Desktop.
Save amb/5d411b2a0de118ee7eba02e87d6ccca2 to your computer and use it in GitHub Desktop.
Meshroom cameras, with images, into Blender
import bpy
from pathlib import Path
#selo = bpy.context.selected_objects
#assert len(selo) > 0, "Need to select the camera root"
#mroot = selo[0]
#assert mroot.name == "mvgRoot"
mroot = bpy.data.objects['mvgRoot']
image_folder = Path("D:\\art\\photo\\2022.6\\16")
cams = mroot.children[0].children
print("Start...")
for c in cams:
cam = bpy.data.cameras["camera_" + c.name]
cam.show_background_images = True
cam.display_size = 0.3
if len(cam.background_images) == 0:
cam.background_images.new()
# Assume: second to last string is image name (without .jpg)
fname = image_folder / (c.name.split('_')[-2] + ".jpg")
print(fname)
assert fname.is_file(), "Could not find image to load"
rimg = bpy.data.images.load(str(fname.absolute()), check_existing=True)
cam.background_images[0].image = rimg
cam.background_images[0].alpha = 0.4
cam.background_images[0].frame_method = "CROP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment