티스토리 뷰
3.3.파이카메라 PIL 이미지 캡처
이는 스트림으로 캡처하는 변형입니다. 먼저 BytesIO 스트림 (Python의 메모리 내 스트림 클래스)에 이미지를 캡처 한 다음 스트림의 위치를 시작 부분으로 되감고 스트림을 PIL Image 객체로 읽습니다.
from io import BytesIO from time import sleep from picamera import PiCamera from PIL import Image # Create the in-memory stream 메모리 내 스트림 만들기 stream = BytesIO() camera = PiCamera() camera.start_preview() sleep(2) camera.capture(stream, format='jpeg') # "Rewind" the stream to the beginning so we can read its content 스트림을 처음으로 "되감기"하여 내용을 읽을 수 있습니다.
stream.seek(0) image = Image.open(stream)
댓글