with Django
Building stuff that interacts with the real world.
Internet of Things (IoT)
Sensors + Smarts + Connectivity
"Something, Something, Something, Dark side"
# -*- coding: utf-8 -*-
import io
import time
import picamera
def capture_image():
data = io.BytesIO()
with picamera.PiCamera(resolution=(800, 600), framerate=10) as camera:
time.sleep(1) # Camera warm-up time
camera.rotation = 270
camera.capture(data, 'jpeg')
data.seek(0)
return data
# -*- coding: utf-8 -*-
import base64
from rest_framework import views
from rest_framework.response import Response
from .. import camera
class ImageAPIView(views.APIView):
http_method_names = ['get']
def get(self, request, *args, **kwargs):
data = camera.capture_image()
return Response({
'img': "data:image/png;base64,{}".format(
base64.b64encode(data.getvalue())
)
})
* sort of