gpt4 book ai didi

python - PiCamera 将流数据保存到图像文件中

转载 作者:行者123 更新时间:2023-12-01 09:17:40 24 4
gpt4 key购买 nike

以下示例代码将图像保存到流中。我想知道如何将此流中的图像保存到我的 Pi SD 卡上的图像文件(.jpg 等)中,最好是在捕获所有图像后以保持高 FPS。

import io
import time
import picamera

with picamera.PiCamera() as camera:
# Set the camera's resolution to VGA @40fps and give it a couple
# of seconds to measure exposure etc.
camera.resolution = (640, 480)
camera.framerate = 80
time.sleep(2)
# Set up 40 in-memory streams
outputs = [io.BytesIO() for i in range(40)]
start = time.time()
camera.capture_sequence(outputs, 'jpeg', use_video_port=True)
finish = time.time()
# How fast were we?
print('Captured 40 images at %.2ffps' % (40 / (finish - start)))

picamera 文档: http://picamera.readthedocs.io/en/release-1.10/api_camera.html

最佳答案

使用 PIL。 picam 文档中还有一个示例。

import io
import time
import picamera

from PIL import Image

with picamera.PiCamera() as camera:
# Set the camera's resolution to VGA @40fps and give it a couple
# of seconds to measure exposure etc.
camera.resolution = (1920, 1080)
camera.framerate = 15
camera.rotation = 180
time.sleep(2)
# Set up 40 in-memory streams
outputs = [io.BytesIO() for i in range(40)]
start = time.time()
camera.capture_sequence(outputs, 'jpeg', use_video_port=True)

finish = time.time()
# How fast were we?
print('Captured 40 images at %.2ffps' % (40 / (finish - start)))

count = 0
for frameData in outputs:
rawIO = frameData
rawIO.seek(0)
byteImg = Image.open(rawIO)

count += 1
filename = "image" + str(count) + ".jpg"
byteImg.save(filename, 'JPEG')

关于python - PiCamera 将流数据保存到图像文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51092372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com