import firebase_admin from firebase_admin import credentials from firebase_admin import firestore from PIL import Image import camera import image_tools # Use a service account cred = credentials.Certificate('./hackku-272b6e79b2a9.json') firebase_admin.initialize_app(cred) db = firestore.client() doc_ref_lot1 = db.collection(u'Lot1') # Take the picture # img = Image.open(camera.capture()).load() img = Image.open('./lib/test-images/lot-3-cars.jpg').load() reference = Image.open('./lib/test-images/lot-empty.jpg').load() stalls = doc_ref_lot1.get() for stall in stalls: #print(u'{} => {}'.format(stall.id, stall.to_dict())) stall_obj = stall.to_dict() color_reference = image_tools.average_color(stall_obj['locationX'], stall_obj['locationY'], stall_obj['sideN'], reference) color_compare = image_tools.average_color(stall_obj['locationX'], stall_obj['locationY'], stall_obj['sideN'], img) stall_occupied = image_tools.threshold(image_tools.differences(color_reference, color_compare)) stall_obj['open'] = not stall_occupied db.collection(u'Lot1').document(stall.id).set( stall_obj )