Compare commits

..

2 Commits

Author SHA1 Message Date
glmdev
05e8b9a15d ref test 2019-02-09 18:32:07 -06:00
glmdev
6f7b2c9ec6 ref test 2019-02-09 18:31:26 -06:00
9 changed files with 44 additions and 69 deletions

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<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$/index.py" beforeDir="false" afterPath="$PROJECT_DIR$/index.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -13,8 +15,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="721"> <state relative-caret-position="360">
<caret line="54" column="24" lean-forward="true" selection-start-line="54" selection-start-column="24" selection-end-line="54" selection-end-column="24" /> <caret line="36" column="72" selection-start-line="36" selection-start-column="72" selection-end-line="36" selection-end-column="72" />
<folding> <folding>
<element signature="e#0#21#0" expanded="true" /> <element signature="e#0#21#0" expanded="true" />
</folding> </folding>
@ -22,6 +24,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/test-images/lot-5-cars-A.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" />
@ -30,8 +37,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="75"> <state relative-caret-position="165">
<caret line="5" column="65" selection-start-line="5" selection-start-column="65" selection-end-line="5" selection-end-column="65" /> <caret line="11" column="14" selection-start-line="11" selection-start-column="14" selection-end-line="11" selection-end-column="14" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
@ -39,11 +46,6 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/capture.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$/.gitignore"> <entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -62,11 +64,16 @@
</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$/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="30"> <state relative-caret-position="45">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" /> <caret line="3" column="23" lean-forward="true" selection-start-line="3" selection-start-column="23" selection-end-line="3" selection-end-column="23" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -74,8 +81,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/.env"> <entry file="file://$PROJECT_DIR$/.env">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45"> <state relative-caret-position="75">
<caret line="3" column="18" selection-start-line="3" selection-start-column="18" selection-end-line="3" selection-end-column="18" /> <caret line="5" column="35" selection-start-line="5" selection-start-column="35" selection-end-line="5" selection-end-column="35" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -98,11 +105,6 @@
</list> </list>
</option> </option>
</component> </component>
<component name="FindInProjectRecents">
<findStrings>
<find>poll_t</find>
</findStrings>
</component>
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
@ -112,10 +114,10 @@
<option value="$PROJECT_DIR$/image_diff_color.py" /> <option value="$PROJECT_DIR$/image_diff_color.py" />
<option value="$PROJECT_DIR$/.gitignore" /> <option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/config.py" /> <option value="$PROJECT_DIR$/config.py" />
<option value="$PROJECT_DIR$/image_tools.py" />
<option value="$PROJECT_DIR$/example.env" /> <option value="$PROJECT_DIR$/example.env" />
<option value="$PROJECT_DIR$/.env" /> <option value="$PROJECT_DIR$/.env" />
<option value="$PROJECT_DIR$/camera.py" /> <option value="$PROJECT_DIR$/camera.py" />
<option value="$PROJECT_DIR$/image_tools.py" />
<option value="$PROJECT_DIR$/index.py" /> <option value="$PROJECT_DIR$/index.py" />
</list> </list>
</option> </option>
@ -138,11 +140,6 @@
<item name="python-backend" type="b2602c69:ProjectViewProjectNode" /> <item name="python-backend" type="b2602c69:ProjectViewProjectNode" />
<item name="python-backend" type="462c0819:PsiDirectoryNode" /> <item name="python-backend" type="462c0819:PsiDirectoryNode" />
</path> </path>
<path>
<item name="python-backend" type="b2602c69:ProjectViewProjectNode" />
<item name="python-backend" type="462c0819:PsiDirectoryNode" />
<item name="test-images-vert" type="462c0819:PsiDirectoryNode" />
</path>
</expand> </expand>
<select /> <select />
</subPane> </subPane>
@ -199,7 +196,7 @@
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" /> <window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" /> <window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Terminal" order="8" weight="0.32972974" /> <window_info active="true" anchor="bottom" id="Terminal" order="8" visible="true" weight="0.32972974" />
<window_info anchor="bottom" id="Python Console" order="9" /> <window_info anchor="bottom" id="Python Console" order="9" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
@ -235,6 +232,13 @@
<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$/image_tools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="23" lean-forward="true" selection-start-line="3" selection-start-column="23" selection-end-line="3" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config.py"> <entry file="file://$PROJECT_DIR$/config.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75"> <state relative-caret-position="75">
@ -261,32 +265,25 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/.env"> <entry file="file://$PROJECT_DIR$/.env">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45"> <state relative-caret-position="75">
<caret line="3" column="18" selection-start-line="3" selection-start-column="18" selection-end-line="3" selection-end-column="18" /> <caret line="5" column="35" selection-start-line="5" selection-start-column="35" selection-end-line="5" selection-end-column="35" />
</state> </state>
</provider> </provider>
</entry> </entry>
<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="75"> <state relative-caret-position="165">
<caret line="5" column="65" selection-start-line="5" selection-start-column="65" selection-end-line="5" selection-end-column="65" /> <caret line="11" column="14" selection-start-line="11" selection-start-column="14" selection-end-line="11" selection-end-column="14" />
<folding> <folding>
<element signature="e#0#13#0" expanded="true" /> <element signature="e#0#13#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/image_tools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30">
<caret line="2" column="13" selection-start-line="2" selection-start-column="13" selection-end-line="2" selection-end-column="13" />
</state>
</provider>
</entry>
<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="721"> <state relative-caret-position="360">
<caret line="54" column="24" lean-forward="true" selection-start-line="54" selection-start-column="24" selection-end-line="54" selection-end-column="24" /> <caret line="36" column="72" selection-start-line="36" selection-start-column="72" selection-end-line="36" selection-end-column="72" />
<folding> <folding>
<element signature="e#0#21#0" expanded="true" /> <element signature="e#0#21#0" expanded="true" />
</folding> </folding>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

View File

@ -1,14 +1,12 @@
import pygame import pygame
import pygame.camera import pygame.camera
import time
def capture(camera_stream = "/dev/video0", camera_res = (640, 480)): def capture(camera_stream = "/dev/video4"):
pygame.camera.init() pygame.camera.init()
pygame.camera.list_cameras() pygame.camera.list_cameras()
cam = pygame.camera.Camera(camera_stream, camera_res) cam = pygame.camera.Camera(camera_stream, (640, 480))
cam.start() cam.start()
time.sleep(5)
img = cam.get_image() img = cam.get_image()
pygame.image.save(img, './capture.jpg') pygame.image.save(img, './capture.jpg')
cam.stop() cam.stop()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -1,6 +1,7 @@
def average_color(x, y, w, h, image): def average_color(x, y, w, h, image):
r, g, b = 0, 0, 0 r, g, b = 0, 0, 0
count = 0 count = 0
print([x, y, w, h])
for s in range(x, x + w + 1): for s in range(x, x + w + 1):
for t in range(y, y + h + 1): for t in range(y, y + h + 1):
pixlr, pixlg, pixlb = image[s, t] pixlr, pixlg, pixlb = image[s, t]

View File

@ -18,11 +18,8 @@ firebase_admin.initialize_app(cred)
db = firestore.client() db = firestore.client()
doc_conf = db.collection('configurations').document(os.getenv('CONFIG_CODE')).get().to_dict()
print(doc_conf)
def poll(): def poll():
doc_ref_lot = db.collection('lots').document(doc_conf['lot_id']) doc_ref_lot = db.collection('lots').document(os.getenv('LOT_NAME'))
# Get the reference image # Get the reference image
lot_info = doc_ref_lot.collection('info').document('lotInfo').get().to_dict() lot_info = doc_ref_lot.collection('info').document('lotInfo').get().to_dict()
@ -30,16 +27,16 @@ def poll():
reference = Image.open('./ref-img.jpg').load() reference = Image.open('./ref-img.jpg').load()
# Take the picture # Take the picture
img = Image.open(camera.capture(doc_conf['stream'])).load() img = Image.open(camera.capture(os.getenv('CAMERA_DEVICE'))).load()
#img = Image.open('./lib/test-images-vert/lot-3-cars.jpg').load() #img = Image.open('./lib/test-images-vert/lot-3-cars.jpg').load()
doc_ref_stalls = doc_ref_lot.collection('stalls').get() doc_ref_stalls = doc_ref_lot.collection('stalls').get()
for stall in doc_ref_stalls: for stall in doc_ref_stalls:
stall_obj = stall.to_dict() stall_obj = stall.to_dict()
color_reference = image_tools.average_color(stall_obj['locationX'], stall_obj['locationY'], stall_obj['width'], stall_obj['height'], reference) color_reference = image_tools.average_color(75, 400, 50, 50, img)
color_compare = image_tools.average_color(stall_obj['locationX'], stall_obj['locationY'], stall_obj['width'], stall_obj['height'], img) color_compare = image_tools.average_color(stall_obj['locationX'], stall_obj['locationY'], stall_obj['width'], stall_obj['height'], img)
stall_occupied = image_tools.threshold(image_tools.differences(color_reference, color_compare), float(doc_conf['e_hat'])) 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 stall_obj['open'] = not stall_occupied
print("Updated: "+stall.id) print("Updated: "+stall.id)
@ -50,9 +47,5 @@ start_time = time.time()
while True: while True:
poll() poll()
doc_conf = db.collection('configurations').document(os.getenv('CONFIG_CODE')).get().to_dict() poll_time = float(os.getenv('POLL_FREQUENCY'))
print(doc_conf)
if doc_conf['stop']:
break
poll_time = float(doc_conf['frequency'])
time.sleep(poll_time - ((time.time() - start_time) % poll_time)) time.sleep(poll_time - ((time.time() - start_time) % poll_time))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -1,14 +0,0 @@
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path, "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path, "ai_image.jpg"), output_image_path=os.path.join(execution_path , "ai_image.out.jpg"))
for eachObject in detections:
print(eachObject["name"] , " : " , eachObject["percentage_probability"] )