我有一个返回 np.uin8 数组流的程序。我现在想将这些广播到由该计算机托管的网站。
我计划通过注入的代码来执行此此通过更换在线文档camera.start_recording(output, format='mjpeg')
用output.write(<numpy_array_but_jpeg>)
。文档start_recording
说明如果该write()
方法存在,它将以请求的格式将数据写入该缓冲区。我可以在网上找到很多关于如何将 a 保存np.uint8
为 jpeg 的内容,但在我的情况下,我想将该数据写入内存中的缓冲区,并且我不想将图像保存到文件然后将该文件读入缓冲区。
不幸的是,更改np.uint8
流中较早的输出格式不是一种选择。
感谢您的帮助。为简单起见,我复制了下面的重要代码位
class StreamingOutput(object):
def __init__(self):
self.frame = None
self.buffer = io.BytesIO()
self.condition = Condition()
def write(self, buf):
if buf.startswith(b'\xff\xd8'):
# New frame, copy the existing buffer's content and notify all
# clients it's available
self.buffer.truncate()
with self.condition:
self.frame = self.buffer.getvalue()
self.condition.notify_all()
self.buffer.seek(0)
return self.buffer.write(buf)
with picamera.PiCamera(resolution='640x480', framerate=24) as camera:
output = StreamingOutput()
camera.start_recording(output, format='mjpeg')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句