Created
November 22, 2014 17:37
-
-
Save richrd/2ac9e743857f54a304a1 to your computer and use it in GitHub Desktop.
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
# | |
# HTTP Server that returns an image from the RaspberryPi camera | |
# | |
import io | |
import time | |
import picamera | |
import pyco_http | |
def get_image(): | |
# Create the in-memory stream | |
stream = io.BytesIO() | |
camera = picamera.PiCamera() | |
camera.resolution = (360, 240) | |
camera.capture(stream, format='jpeg') | |
camera.close() | |
stream.seek(0) | |
return stream | |
def handle_request(request): | |
stream = get_image() | |
response = { | |
"status": 200, | |
"headers": {"Content-Type": "image/jpeg"}, | |
"data": stream.read() | |
} | |
return response | |
if __name__ == "__main__": | |
srv = pyco_http.PycoHTTP() | |
srv.set_handler(handle_request) | |
srv.start(True) # True for blocking server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment