.env stuff
This commit is contained in:
parent
9d1b159e83
commit
31c6293576
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
### FIREBASE STUFF ###
|
### FIREBASE STUFF ###
|
||||||
hackku-*.json
|
hackku-*.json
|
||||||
|
|
||||||
|
.env
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/git,python,opencv,pycharm,visualstudio,visualstudiocode
|
# Created by https://www.gitignore.io/api/git,python,opencv,pycharm,visualstudio,visualstudiocode
|
||||||
# Edit at https://www.gitignore.io/?templates=git,python,opencv,pycharm,visualstudio,visualstudiocode
|
# Edit at https://www.gitignore.io/?templates=git,python,opencv,pycharm,visualstudio,visualstudiocode
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="f410c5c2-3ffe-4260-93eb-e3d83256d263" name="Default Changelist" comment="">
|
<list default="true" id="f410c5c2-3ffe-4260-93eb-e3d83256d263" name="Default Changelist" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/image_diff_color.py" beforeDir="false" afterPath="$PROJECT_DIR$/image_tools.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/camera.py" beforeDir="false" afterPath="$PROJECT_DIR$/camera.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/image_tools.py" beforeDir="false" afterPath="$PROJECT_DIR$/image_tools.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/index.py" beforeDir="false" afterPath="$PROJECT_DIR$/index.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/index.py" beforeDir="false" afterPath="$PROJECT_DIR$/index.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -16,8 +18,8 @@
|
|||||||
<file pinned="false" current-in-tab="true">
|
<file pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/index.py">
|
<entry file="file://$PROJECT_DIR$/index.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="270">
|
<state relative-caret-position="225">
|
||||||
<caret line="18" column="46" selection-start-line="18" selection-start-column="46" selection-end-line="18" selection-end-column="46" />
|
<caret line="24" column="5" selection-start-line="24" selection-start-column="5" selection-end-line="24" selection-end-column="5" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#0#21#0" expanded="true" />
|
<element signature="e#0#21#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
@ -25,6 +27,11 @@
|
|||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-3-cars.jpg">
|
||||||
|
<provider selected="true" editor-type-id="images" />
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
<file pinned="false" current-in-tab="false">
|
<file pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-5-cars-B.jpg">
|
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-5-cars-B.jpg">
|
||||||
<provider selected="true" editor-type-id="images" />
|
<provider selected="true" editor-type-id="images" />
|
||||||
@ -33,8 +40,8 @@
|
|||||||
<file pinned="false" current-in-tab="false">
|
<file pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/camera.py">
|
<entry file="file://$PROJECT_DIR$/camera.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="165">
|
<state relative-caret-position="105">
|
||||||
<caret line="11" column="14" selection-start-line="11" selection-start-column="14" selection-end-line="11" selection-end-column="14" />
|
<caret line="7" column="44" selection-start-line="7" selection-start-column="44" selection-end-line="7" selection-end-column="44" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#0#13#0" expanded="true" />
|
<element signature="e#0#13#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
@ -45,8 +52,8 @@
|
|||||||
<file pinned="false" current-in-tab="false">
|
<file pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/.gitignore">
|
<entry file="file://$PROJECT_DIR$/.gitignore">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="15">
|
<state relative-caret-position="45">
|
||||||
<caret line="1" column="13" selection-start-line="1" selection-start-column="13" selection-end-line="1" selection-end-column="13" />
|
<caret line="3" column="4" selection-start-line="3" selection-start-column="4" selection-end-line="3" selection-end-column="4" />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
@ -54,8 +61,35 @@
|
|||||||
<file pinned="false" current-in-tab="false">
|
<file pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/image_tools.py">
|
<entry file="file://$PROJECT_DIR$/image_tools.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="-379">
|
<state relative-caret-position="270">
|
||||||
<caret line="27" column="1" selection-start-line="27" selection-start-column="1" selection-end-line="27" selection-end-column="1" />
|
<caret line="18" column="35" lean-forward="true" selection-start-line="18" selection-start-column="35" selection-end-line="18" selection-end-column="35" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/example.env">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="30">
|
||||||
|
<caret line="2" column="13" selection-start-line="2" selection-end-line="2" selection-end-column="13" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/.env">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state>
|
||||||
|
<caret column="16" selection-start-column="16" selection-end-column="16" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/config.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="75">
|
||||||
|
<caret line="5" lean-forward="true" selection-start-line="5" selection-end-line="5" />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
@ -75,8 +109,12 @@
|
|||||||
<component name="IdeDocumentHistory">
|
<component name="IdeDocumentHistory">
|
||||||
<option name="CHANGED_PATHS">
|
<option name="CHANGED_PATHS">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/.gitignore" />
|
|
||||||
<option value="$PROJECT_DIR$/image_diff_color.py" />
|
<option value="$PROJECT_DIR$/image_diff_color.py" />
|
||||||
|
<option value="$PROJECT_DIR$/image_tools.py" />
|
||||||
|
<option value="$PROJECT_DIR$/.gitignore" />
|
||||||
|
<option value="$PROJECT_DIR$/config.py" />
|
||||||
|
<option value="$PROJECT_DIR$/example.env" />
|
||||||
|
<option value="$PROJECT_DIR$/.env" />
|
||||||
<option value="$PROJECT_DIR$/camera.py" />
|
<option value="$PROJECT_DIR$/camera.py" />
|
||||||
<option value="$PROJECT_DIR$/index.py" />
|
<option value="$PROJECT_DIR$/index.py" />
|
||||||
</list>
|
</list>
|
||||||
@ -176,49 +214,70 @@
|
|||||||
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-empty.jpg">
|
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-empty.jpg">
|
||||||
<provider selected="true" editor-type-id="images" />
|
<provider selected="true" editor-type-id="images" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-3-cars.jpg">
|
|
||||||
<provider selected="true" editor-type-id="images" />
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/test.jpg">
|
<entry file="file://$PROJECT_DIR$/test.jpg">
|
||||||
<provider selected="true" editor-type-id="images" />
|
<provider selected="true" editor-type-id="images" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/capture.jpg">
|
<entry file="file://$PROJECT_DIR$/capture.jpg">
|
||||||
<provider selected="true" editor-type-id="images" />
|
<provider selected="true" editor-type-id="images" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/.gitignore">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="15">
|
|
||||||
<caret line="1" column="13" selection-start-line="1" selection-start-column="13" selection-end-line="1" selection-end-column="13" />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/camera.py">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="165">
|
|
||||||
<caret line="11" column="14" selection-start-line="11" selection-start-column="14" selection-end-line="11" selection-end-column="14" />
|
|
||||||
<folding>
|
|
||||||
<element signature="e#0#13#0" expanded="true" />
|
|
||||||
</folding>
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/image_tools.py">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state relative-caret-position="-379">
|
|
||||||
<caret line="27" column="1" selection-start-line="27" selection-start-column="1" selection-end-line="27" selection-end-column="1" />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-1-car.jpg">
|
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-1-car.jpg">
|
||||||
<provider selected="true" editor-type-id="images" />
|
<provider selected="true" editor-type-id="images" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-5-cars-B.jpg">
|
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-5-cars-B.jpg">
|
||||||
<provider selected="true" editor-type-id="images" />
|
<provider selected="true" editor-type-id="images" />
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/index.py">
|
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-3-cars.jpg">
|
||||||
|
<provider selected="true" editor-type-id="images" />
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/.gitignore">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="45">
|
||||||
|
<caret line="3" column="4" selection-start-line="3" selection-start-column="4" selection-end-line="3" selection-end-column="4" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/config.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="75">
|
||||||
|
<caret line="5" lean-forward="true" selection-start-line="5" selection-end-line="5" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/.env">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state>
|
||||||
|
<caret column="16" selection-start-column="16" selection-end-column="16" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/image_tools.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="270">
|
<state relative-caret-position="270">
|
||||||
<caret line="18" column="46" selection-start-line="18" selection-start-column="46" selection-end-line="18" selection-end-column="46" />
|
<caret line="18" column="35" lean-forward="true" selection-start-line="18" selection-start-column="35" selection-end-line="18" selection-end-column="35" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/camera.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="105">
|
||||||
|
<caret line="7" column="44" selection-start-line="7" selection-start-column="44" selection-end-line="7" selection-end-column="44" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#0#13#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/example.env">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="30">
|
||||||
|
<caret line="2" column="13" selection-start-line="2" selection-end-line="2" selection-end-column="13" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/index.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="225">
|
||||||
|
<caret line="24" column="5" selection-start-line="24" selection-start-column="5" selection-end-line="24" selection-end-column="5" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#0#21#0" expanded="true" />
|
<element signature="e#0#21#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -2,10 +2,10 @@ import pygame
|
|||||||
import pygame.camera
|
import pygame.camera
|
||||||
|
|
||||||
|
|
||||||
def capture():
|
def capture(camera_stream = "/dev/video4"):
|
||||||
pygame.camera.init()
|
pygame.camera.init()
|
||||||
pygame.camera.list_cameras()
|
pygame.camera.list_cameras()
|
||||||
cam = pygame.camera.Camera('/dev/video4', (640, 480))
|
cam = pygame.camera.Camera(camera_stream, (640, 480))
|
||||||
cam.start()
|
cam.start()
|
||||||
img = cam.get_image()
|
img = cam.get_image()
|
||||||
pygame.image.save(img, './capture.jpg')
|
pygame.image.save(img, './capture.jpg')
|
||||||
|
5
config.py
Normal file
5
config.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
|
||||||
|
def bootstrap(envfile='./.env'):
|
||||||
|
load_dotenv(dotenv_path=envfile)
|
6
example.env
Normal file
6
example.env
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
POLL_FREQUENCY=15
|
||||||
|
FIREBASE_CERT_FILE="hackku-ffffffffffff.json"
|
||||||
|
CAMERA_DEVICE="/dev/video4"
|
||||||
|
LOT_NAME="Lot1"
|
||||||
|
REFERENCE_IMAGE="./lib/test-images/lot-empty.jpg"
|
||||||
|
E_HAT_TRIGGER_LEVEL=4
|
@ -1,5 +1,3 @@
|
|||||||
from PIL import Image
|
|
||||||
|
|
||||||
def average_color(x, y, n, image):
|
def average_color(x, y, n, image):
|
||||||
r, g, b = 0, 0, 0
|
r, g, b = 0, 0, 0
|
||||||
count = 0
|
count = 0
|
||||||
@ -21,64 +19,3 @@ def differences(rgb_tuple1, rgb_tuple2):
|
|||||||
def threshold(diff_tuple, trigger=4):
|
def threshold(diff_tuple, trigger=4):
|
||||||
dr, dg, db = diff_tuple
|
dr, dg, db = diff_tuple
|
||||||
return (((( dr**4 + dg**4 + db**4 ) / 3)**0.25) > trigger) # Thanks to Thomas Atkins, math whiz
|
return (((( dr**4 + dg**4 + db**4 ) / 3)**0.25) > trigger) # Thanks to Thomas Atkins, math whiz
|
||||||
|
|
||||||
#
|
|
||||||
# reference_image = Image.open('./lib/test-images/lot-empty.jpg').load()
|
|
||||||
# compare_image = Image.open('./lib/test-images/lot-1-car.jpg').load()
|
|
||||||
#
|
|
||||||
# stall_1 = {
|
|
||||||
# 'location': (54, 79, 109),
|
|
||||||
# 'reference': average_color(54, 79, 109, reference_image),
|
|
||||||
# 'compare': average_color(54, 79, 109, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_2 = {
|
|
||||||
# 'location': (186, 81, 116),
|
|
||||||
# 'reference': average_color(186, 81, 116, reference_image),
|
|
||||||
# 'compare': average_color(186, 81, 116, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_3 = {
|
|
||||||
# 'location': (317, 71, 127),
|
|
||||||
# 'reference': average_color(317, 71, 127, reference_image),
|
|
||||||
# 'compare': average_color(317, 71, 127, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_4 = {
|
|
||||||
# 'location': (469, 76, 100),
|
|
||||||
# 'reference': average_color(469, 76, 100, reference_image),
|
|
||||||
# 'compare': average_color(469, 76, 100, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_5 = {
|
|
||||||
# 'location': (27, 237, 119),
|
|
||||||
# 'reference': average_color(27, 237, 119, reference_image),
|
|
||||||
# 'compare': average_color(27, 237, 119, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_6 = {
|
|
||||||
# 'location': (172, 240, 130),
|
|
||||||
# 'reference': average_color(172, 240, 130, reference_image),
|
|
||||||
# 'compare': average_color(172, 240, 130, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_7 = {
|
|
||||||
# 'location': (317, 234, 144),
|
|
||||||
# 'reference': average_color(317, 234, 144, reference_image),
|
|
||||||
# 'compare': average_color(317, 234, 144, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# stall_8 = {
|
|
||||||
# 'location': (481, 233, 112),
|
|
||||||
# 'reference': average_color(481, 233, 112, reference_image),
|
|
||||||
# 'compare': average_color(481, 233, 112, compare_image)
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# print(threshold(differences(stall_1['reference'], stall_1['compare'])))
|
|
||||||
# print(threshold(differences(stall_2['reference'], stall_2['compare'])))
|
|
||||||
# print(threshold(differences(stall_3['reference'], stall_3['compare'])))
|
|
||||||
# print(threshold(differences(stall_4['reference'], stall_4['compare'])))
|
|
||||||
# print(threshold(differences(stall_5['reference'], stall_5['compare'])))
|
|
||||||
# print(threshold(differences(stall_6['reference'], stall_6['compare'])))
|
|
||||||
# print(threshold(differences(stall_7['reference'], stall_7['compare'])))
|
|
||||||
# print(threshold(differences(stall_8['reference'], stall_8['compare'])))
|
|
||||||
|
43
index.py
43
index.py
@ -2,31 +2,44 @@ import firebase_admin
|
|||||||
from firebase_admin import credentials
|
from firebase_admin import credentials
|
||||||
from firebase_admin import firestore
|
from firebase_admin import firestore
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
import time, os
|
||||||
|
|
||||||
import camera
|
import camera
|
||||||
import image_tools
|
import image_tools
|
||||||
|
import config
|
||||||
|
|
||||||
|
config.bootstrap()
|
||||||
|
|
||||||
# Use a service account
|
# Use a service account
|
||||||
cred = credentials.Certificate('./hackku-272b6e79b2a9.json')
|
cred = credentials.Certificate(os.getenv('FIREBASE_CERT_FILE'))
|
||||||
firebase_admin.initialize_app(cred)
|
firebase_admin.initialize_app(cred)
|
||||||
|
|
||||||
db = firestore.client()
|
db = firestore.client()
|
||||||
|
|
||||||
doc_ref_lot1 = db.collection(u'Lot1')
|
doc_ref_lot1 = db.collection(os.getenv('LOT_NAME'))
|
||||||
|
|
||||||
# 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()
|
def poll():
|
||||||
|
# Take the picture
|
||||||
|
img = Image.open(camera.capture(os.getenv('CAMERA_DEVICE'))).load()
|
||||||
|
#img = Image.open('./lib/test-images/lot-empty.jpg').load()
|
||||||
|
reference = Image.open(os.getenv('REFERENCE_IMAGE')).load()
|
||||||
|
|
||||||
for stall in stalls:
|
stalls = doc_ref_lot1.get()
|
||||||
#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 )
|
for stall in stalls:
|
||||||
|
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), float(os.getenv('E_HAT_TRIGGER_LEVEL')))
|
||||||
|
stall_obj['open'] = not stall_occupied
|
||||||
|
print(stall.id)
|
||||||
|
db.collection(u'Lot1').document(stall.id).set( stall_obj )
|
||||||
|
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
poll()
|
||||||
|
poll_time = float(os.getenv('POLL_FREQUENCY'))
|
||||||
|
time.sleep(poll_time - ((time.time() - start_time) % poll_time))
|
||||||
|
Loading…
Reference in New Issue
Block a user