#22 Use BytesIO for camera capture
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from picam import PiCam
|
||||
from src.picam import PiCam
|
||||
|
||||
from io import BytesIO
|
||||
from picamera import PiCamera
|
||||
|
||||
class PiCam1(PiCam):
|
||||
@@ -36,12 +37,17 @@ class PiCam1(PiCam):
|
||||
def capture(self, preview: bool = False) -> bytes:
|
||||
# Bytes to hold output buffer
|
||||
out = bytes()
|
||||
bytes_stream = BytesIO()
|
||||
|
||||
if not preview:
|
||||
# If preview we'll already have the right resolution
|
||||
self.set_camera_resolution(self.capture_resolution)
|
||||
|
||||
self.camera.capture(out, format='rgb', use_video_port=preview)
|
||||
self.camera.capture(bytes_stream, format='rgb', use_video_port=preview)
|
||||
|
||||
bytes_stream.seek(0)
|
||||
bytes_stream.readinto(out)
|
||||
bytes_stream.close()
|
||||
|
||||
if not preview:
|
||||
# If preview we'll already have the right resolution
|
||||
|
||||
Reference in New Issue
Block a user