我正在尝试使用 Asyncio 事件循环来设置网络摄像机的帧速率和捕获时间。我正在尝试使用 PySpin 进行图像捕获。这是代码示例:
import PySpin
import asyncio
import time
Cap_time = 20
Frm_rate = 5
def stop():
task.cancel()
return
async def capture(cam):
await asyncio.sleep(1/Frm_rate)
image = cam.GetNextImage()
image.Save('images/cam1-%s.png' % round(time.time()*1000))
image.Release()
return
async def main():
serial_1 = '15327072'
system = PySpin.System.GetInstance()
cam_list = system.GetCameras()
cam_1 = cam_list.GetBySerial(serial_1)
cam_1.Init()
cam_1.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
cam_1.BeginAcquisition()
loop = asyncio.get_event_loop()
loop.call_later(Cap_time+(1/Frm_rate), stop)
global task
task = asyncio.create_task(capture(cam_1))
await task
cam_1.EndAcquisition()
cam_1.DeInit()
del cam_1
return
asyncio.run(main())
我遇到的问题是代码仅捕获单个图像而不是一系列图像。我会很感激任何帮助!
一切顺利,卡勒姆