我正在进行一个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相机模块将代码中的2D图像叠加到一个3D的numpy数组中吗?而不将每个2D捕获保存为文件
致以最良好的问候,奥古斯丁
发布于 2015-10-01 05:31:39
这可能不直接作为复制-n粘贴,但应该演示如何预先分配内存和写入那里的结果。我不熟悉pycamera
,但是这里示例显示了内存流的不同用法。
import numpy as np
def outputs(resolution, n_pics, clr_channels=3):
# Note that the first dimension is height and second is width
images = np.zeros((resolution[1], resolution[0], clr_channels, n_pics), dtype=np.uint8)
stream = io.BytesIO()
for i in range(n_pics):
yield stream
images[:,:,:,i] = Image.open(stream)
stream.seek(0)
stream.truncate()
https://stackoverflow.com/questions/31151624
复制相似问题