Pi 3b(2015)模型相机叠加png

时间:2019-02-09 02:26:02

标签: raspberry-pi3

导入picamera的轻微问题会给我一个版权错误,并且会涉及多个名称等问题,而./pngview会给我一个无效的代码

我是否需要从https://github.com/waveform80/picamera下载文件才能正常工作?

还有一点需要注意的是python 3是否可以对png覆盖进行编程?!

经过几次修改后,我的错误出现在这里:

Traceback (most recent call last): File "/home/pi/ScriptTest.py", line 24, in <module> o = camera.add_overlay(pad.tobytes(), size=img.size) File "/usr/lib/python3/dist-packages/picamera/camera.py", line 891, in add_overlay self._check_camera_open() File "/usr/lib/python3/dist-packages/picamera/camera.py", line 540, in _check_camera_open raise PiCameraClosed("Camera is closed") picamera.exc.PiCameraClosed: Camera is closed

这是我从github上的pi摄像机信息中键入的代码:



from PIL import Image
from time import sleep

with picamera.PiCamera() as camera:

    camera.start_preview()

# Load the arbitrarily sized image
img = Image.open('/home/pi/Pictures/Overlay.png')
# Create an image padded to the required size with
# mode 'RGBA'
pad = Image.new('RGBA', (
    ((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), img)

# Add the overlay with the padded image as the source,
# but the original image's dimensions
o = camera.add_overlay(pad.tobytes(), 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

self._check_camera_open()

# Wait indefinitely until the user terminates the script
while True:
    sleep(1)```

0 个答案:

没有答案