Raspberry Pi Kamera Transparentes Bild-Overlay
Ist es möglich, überlagern eine transparente png-oder gif -) Bild über die pi Kamera-Vorschau?
Fand ich einige code, aber es macht einen weißen hintergrund
import picamera
from PIL import Image
from time import sleep
with picamera.PiCamera() as camera:
camera.start_preview()
# Load the arbitrarily sized image
img = Image.open('lol.gif')
# Create an image padded to the required size with
# mode 'RGB'
pad = Image.new('RGB', (
((img.size[0] + 31) // 32) * 32,
((img.size[1] + 15) // 16) * 16,
))
# Paste the original image into the padded one
pad.paste(img, (0, 0))
# Add the overlay with the padded image as the source,
# but the original image's dimensions
o = camera.add_overlay(pad.tostring(), size=img.size)
# By default, the overlay is in layer 0, beneath the
# preview (which defaults to layer 2). Here we make
# the new overlay semi-transparent, then move it above
# the preview
o.alpha = 255
o.layer = 3
# Wait indefinitely until the user terminates the script
while True:
sleep(1)
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ändern
'RGB'
zu'RGBA'
Ich habe nicht die Bedingungen, um es zu testen, aber ich denke mal das wird dein problem lösen.
Der trick ist, in
Image.paste
Funktion. Der Dritte parameter ist eine Maske wird verwendet, um einfügen Bild, wie transparente Pixel werden maks das Ergebnis, geben Sie nur das gleiche Bild, das Sie einfügen als Maske und wird den trick tun:Wie die Dokumentation sagt:
Hoffe, es hilft!
Ich hatte ähnliches Problem, müssen Sie das Bild speichern/Bild als RGB, dann funktioniert das.