Created
January 18, 2023 12:45
-
-
Save eddiewebb/ea2e3186ebb7ad4c578798cd1f21db3c to your computer and use it in GitHub Desktop.
high resolution Picam v3 on Pi Zero as generic IP camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Serve a single endpoint that provides imnage capture. | |
''' | |
from flask import Flask,make_response | |
from picamera2 import Picamera2, Preview | |
import io | |
app = Flask(__name__) | |
camera = Picamera2() | |
camera.start_preview(Preview.NULL) | |
config = camera.create_still_configuration() | |
camera.configure(config) | |
@app.route('/') | |
def index(): | |
camera.start() | |
data = io.BytesIO() | |
camera.switch_mode_and_capture_file(config, data, format='jpeg') | |
print(data.getbuffer().nbytes) | |
data.seek(0) #important.. | |
camera.stop() | |
response = make_response(data) | |
response.headers.set('Content-Type', 'image/jpeg') | |
response.headers.set( | |
'Content-Disposition', 'attachment', filename='snapshot.jpg') | |
return response | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', debug=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# modify existing /boot/config.txt | |
... | |
# adding cma-320 is specific parameter for the vc4 module to enable a larger CMA (continuous memory) block | |
# this addresses the "unable to allocate memory" | |
dtoverlay=vc4-kms-v3d,cma-320 | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment