-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiCam.py
More file actions
38 lines (28 loc) · 894 Bytes
/
PiCam.py
File metadata and controls
38 lines (28 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from picamera import PiCamera
from time import sleep
import io
import time
import cv2
import numpy as np
import sys
# https://picamera.readthedocs.io/en/release-1.10/recipes1.html#capturing-to-a-pil-image
def take_pictures(n, delay):
try:
images = []
camera = PiCamera()
camera.start_preview()
for i in range(0, n):
# Create the in-memory stream
stream = io.BytesIO()
camera.capture(stream, format='jpeg')
# Construct a numpy array from the stream
data = np.fromstring(stream.getvalue(), dtype=np.uint8)
# "Decode" the image from the array, preserving colour
image = cv2.imdecode(data, 1)
images.append(image)
time.sleep(delay)
except Exception as e:
print(e)
finally:
camera.close()
return np.array(images)