Gui*_*i13 6 python raspberry-pi picamera
我正在使用 python 的 picamera 模块捕获游戏中时光倒流:
from picamera import PiCamera, Color
class EggAlertCam:
def __init__(self):
self.camera = PiCamera()
self.camera.start_preview()
def capture_thread_task(self):
filename = os.path.join(self.SAVEPATH, self.safe_camname + '_{timestamp:%Y%m%d-%H%M%S}-{counter:03d}' + '.jpg' )
starttime = dt.datetime.now()
current_time = dt.datetime.now()
for filename in self.camera.capture_continuous(filename):
print('Captured {}'.format(filename))
self.wait(current_time)
current_time = dt.datetime.now()
def get_frame(self, size=None):
if size is None:
size = (640,480)
output = io.BytesIO()
self.camera.capture(output, format='jpeg', resize=size, use_video_port=True)
output.seek(0)
return output
Run Code Online (Sandbox Code Playgroud)
它capture_thread_task在线程中运行,我有一个 Flask 应用程序,允许通过调用get_frame.
我希望video_port=True即使在捕捉延时拍摄时也能获取(更高的噪音,但我不在乎)图像,但我得到了一个例外:
from picamera import PiCamera, Color
class EggAlertCam:
def __init__(self):
self.camera = PiCamera()
self.camera.start_preview()
def capture_thread_task(self):
filename = os.path.join(self.SAVEPATH, self.safe_camname + '_{timestamp:%Y%m%d-%H%M%S}-{counter:03d}' + '.jpg' )
starttime = dt.datetime.now()
current_time = dt.datetime.now()
for filename in self.camera.capture_continuous(filename):
print('Captured {}'.format(filename))
self.wait(current_time)
current_time = dt.datetime.now()
def get_frame(self, size=None):
if size is None:
size = (640,480)
output = io.BytesIO()
self.camera.capture(output, format='jpeg', resize=size, use_video_port=True)
output.seek(0)
return output
Run Code Online (Sandbox Code Playgroud)
我以为我会使用另一个端口进行捕获,但可惜它似乎不起作用。
从这里的文档: https: //picamera.readthedocs.io/en/release-1.10/fov.html ?highlight=splitter#under-the-hood 我认为 capture_continuous 函数使用端口 0,我应该能够使用端口 1,即告诉 时使用的端口 1 use_video_port=True。但异常消息告诉我它仍然想使用端口 0..
编辑:我尝试使用分离器端口 2,对于我的某些 Pi,它似乎可以工作,而对于其他树莓派,端口 2 似乎已被使用。几分钟后,端口开始可用,我可以从中获取帧。
这看起来像是一个花费太长时间的捕获,但我不知道如何正确地要求端口 2 释放自身以进行新的捕获。
我究竟做错了什么 ?
| 归档时间: |
|
| 查看次数: |
883 次 |
| 最近记录: |