【问题标题】:PiCamera save stream data into image filesPiCamera 将流数据保存到图像文件中
【发布时间】:2018-06-28 23:23:09
【问题描述】:

以下示例代码将图像保存到流中。我想知道如何将此流中的图像保存到我的 Pi SD 卡上的图像文件(.jpg 等)中,最好是在捕获所有图像以保持高 FPS 之后。

import io
import time
import picamera

with picamera.PiCamera() as camera:
    # Set the camera's resolution to VGA @40fps and give it a couple
    # of seconds to measure exposure etc.
    camera.resolution = (640, 480)
    camera.framerate = 80
    time.sleep(2)
    # Set up 40 in-memory streams
    outputs = [io.BytesIO() for i in range(40)]
    start = time.time()
    camera.capture_sequence(outputs, 'jpeg', use_video_port=True)
    finish = time.time()
    # How fast were we?
    print('Captured 40 images at %.2ffps' % (40 / (finish - start)))

picamera 文档: http://picamera.readthedocs.io/en/release-1.10/api_camera.html

【问题讨论】:

    标签: python io stream raspberry-pi


    【解决方案1】:

    使用 PIL。 picam 文档中也有一个示例。

    import io
    import time
    import picamera
    
    from PIL import Image
    
    with picamera.PiCamera() as camera:
        # Set the camera's resolution to VGA @40fps and give it a couple
        # of seconds to measure exposure etc.
        camera.resolution = (1920, 1080)
        camera.framerate = 15
        camera.rotation = 180
        time.sleep(2)
        # Set up 40 in-memory streams
        outputs = [io.BytesIO() for i in range(40)]
        start = time.time()
        camera.capture_sequence(outputs, 'jpeg', use_video_port=True)
    
        finish = time.time()
        # How fast were we?
        print('Captured 40 images at %.2ffps' % (40 / (finish - start)))
    
        count = 0
        for frameData in outputs:
            rawIO = frameData
            rawIO.seek(0)
            byteImg = Image.open(rawIO)
    
            count += 1
            filename = "image" + str(count) + ".jpg"
            byteImg.save(filename, 'JPEG')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 2015-05-30
      • 1970-01-01
      • 2019-11-02
      • 2013-05-31
      相关资源
      最近更新 更多