【发布时间】:2015-09-18 00:54:50
【问题描述】:
我正在研究一个 Raspberry Pi 项目,我需要每秒拍摄大约 30 张图像(没有电影),并使用 numpy 数组将每个 2D 图像堆叠到 3D 数组中,而不将每个 2D 捕获保存为文件(因为很慢)。
我发现这个 Python 代码可以尽可能快地获取图像,但我不知道如何将所有图像快速堆叠到 3D 图像堆栈中。
import io
import time
import picamera
#from PIL import Image
def outputs():
stream = io.BytesIO()
for i in range(40):
# This returns the stream for the camera to capture to
yield stream
# Once the capture is complete, the loop continues here
# (read up on generator functions in Python to understand
# the yield statement). Here you could do some processing
# on the image...
#stream.seek(0)
#img = Image.open(stream)
# Finally, reset the stream for the next capture
stream.seek(0)
stream.truncate()
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.framerate = 80
time.sleep(2)
start = time.time()
camera.capture_sequence(outputs(), 'jpeg', use_video_port=True)
finish = time.time()
print('Captured 40 images at %.2ffps' % (40 / (finish - start)))
有没有人知道如何使用 Python 和 Raspberry Pi 相机模块将这段代码中拍摄的 2D 图像堆叠到 3D numpy 数组中?无需将每个 2D 捕获保存为文件
最好的问候,阿古斯丁
【问题讨论】:
-
您想要
numpy.dstackdocs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html 还是寻找更复杂的东西? -
嗨乔。我想要 dstack 之类的东西,但我不知道如何实现它。
-
@AgustinCruz 你事先知道要堆叠多少张图片吗?如果是,您可以预先分配您的数组并在捕获每个图像后填充它。
-
嗨,Saullo。是的,图像数量是预先固定的。我不知道如何在这段代码中实现预分配:(
标签: python image numpy raspberry-pi pillow