Skip to content

Instantly share code, notes, and snippets.

@eddiewebb
Created January 18, 2023 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiewebb/ea2e3186ebb7ad4c578798cd1f21db3c to your computer and use it in GitHub Desktop.
Save eddiewebb/ea2e3186ebb7ad4c578798cd1f21db3c to your computer and use it in GitHub Desktop.
high resolution Picam v3 on Pi Zero as generic IP camera
'''
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)
# 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