diff --git a/rpi-cam-viewer.py b/rpi-cam-viewer.py new file mode 100644 index 0000000..f9ac703 --- /dev/null +++ b/rpi-cam-viewer.py @@ -0,0 +1,40 @@ +import io +from flask import Flask, Response +from picamera2 import Picamera2 +from PIL import Image + +WIDTH, HEIGHT = 640, 400 + +cam = Picamera2() +cam.configure(cam.create_video_configuration( + main={"size": (WIDTH, HEIGHT), "format": "YUV420"}, + controls={"FrameRate": 30})) +cam.start() + +app = Flask(__name__) + + +def frames(): + while True: + gray = cam.capture_array("main")[:HEIGHT, :WIDTH] # Y plane = greyscale image + buf = io.BytesIO() + Image.fromarray(gray).save(buf, format="JPEG", quality=70) + yield b"--frame\r\nContent-Type: image/jpeg\r\n\r\n" + buf.getvalue() + b"\r\n" + + +@app.route("/") +def index(): + return ('
' + '