所以我的这段代码几乎可以工作,但是当我只希望它出现在相机预览窗口上时,覆盖层会接管整个 HDMI 输出(全屏)。
import picamera
import time
image_folder="../images/"
with picamera.PiCamera() as camera:
camera.start_preview()
camera.preview.window=(0,0, 750, 400)
camera.preview.fullscreen=False
# Overlay
img = Image.open(image_folder+'cam_overlay.png')
pad = Image.new('RGBA', (
((img.size[0] + 31) // 32) * 32,
((img.size[1] + 15) // 16) * 16,
))
pad.paste(img, (0, 0))
o = camera.add_overlay(pad.tobytes(), size=img.size)
o.alpha = 32
o.layer = 3
time.sleep(10)
camera.stop_preview()