触发Pi摄影机时图像的多个实例

2024-07-04 15:33:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些代码,当PIR传感器被触发时,相机拍摄一张图像并将其上传到Azure blob存储,拍摄一张照片是不够的,但我无法让程序在相机被触发时拍摄多张图像

from gpiozero import MotionSensor
from picamera import PiCamera
from datetime import datetime
from azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettings

camera = PiCamera()
pir = MotionSensor()
block_blob_service = BlockBlobService(account_name='YOURACCOUNT', account_key='YOURKEY')

while True:
  pir.wait_for_motion()
  filename = "pircam-" +  datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
  camera.capture(filename)
  pir.wait_for_no_motion()
  block_blob_service.create_blob_from_path(
  'YOURCONTAINER',
  filename,
  filename,
  content_settings=ContentSettings(content_type='image/jpeg'))

预期结果应该是相机拍摄多幅静止图像,而不是一幅静止图像


Tags: from图像importdatetimeservicestoragefilenameazure
2条回答

我无法测试它,但pir.wait_for_no_motion()会在第一个图像之后停止循环,因此无法获得更多图像。如果必须拍照,则必须使用pir.motion_detected进行测试

while True:
  if pir.motion_detected:
      filename = "pircam-" +  datetime.now().strftime("%Y-%m-%d_%H.%M.%S.%s.jpg")
      camera.capture(filename)
      block_blob_service.create_blob_from_path(...)

我是根据GPIO_Zero_Cheatsheet.pdf写的

图像将保存到名为的文件中,时间戳精确到秒。如果在同一秒钟内拍摄图像,则文件名将相同,并且只有一个结果文件。您需要使文件名不同-例如,使用最接近的毫秒

相关问题 更多 >

    热门问题