python - 树莓派相机透明图像叠加

标签 python image camera raspberry-pi

是否可以在 pi 相机预览上叠加透明(png 或 gif)图像?

我找到了一些代码,但它是白色背景

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)

最佳答案

'RGB' 更改为 'RGBA'

我没有条件来测试它,但我想这会解决你的问题。

关于python - 树莓派相机透明图像叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29087856/

相关文章:

python - Django 。导入应用模块

javascript - Prestashop 产品图像调整大小

python - PIL 从图像中删除背景图像

python - 如何获取用户加入Facebook的日期?

image - 更改单个像素的颜色 - Golang 图像

jquery - 使用 jQuery 在翻转时显示完整版本的缩略图?

macos - 苹果操作系统 : get full control of web-camera (USB connected)

android - 在不使用 action.Image_Capture 的情况下打开默认相机应用程序

android - 如何在不显示选择器的情况下打开 Android 设备的默认相机。

python - 将嵌套 JSON 转换为 CSV