kortex
April 17, 2018, 12:09pm
1
Hi Everyone,
Started to work through DLIB and have the following downpat;
–Config–
camera:
platform: ffmpeg
name: Cam
input: -rtsp_transport tcp -i rtsp://192.168.50.253/unicast
image_processing:
platform: dlib_face_identify
source:
entity_id: camera.cam
faces:
PersonA: “C:/faces/a.jpg”
PersonB: “C:/faces/b.jpg”
–Event–
INFO:homeassistant.core:Bus:Handling <Event image_processing.detect_face[L]: name=PersonA, entity_id=image_processing.dlib_face_cam>
–Data–
http://192.168.50.25:8123/dev-template
{{ states.image_processing.dlib_face_cam }}
{{ states.image_processing.dlib_face_cam.attributes.total_faces }}
{{ states.image_processing.dlib_face_cam.attributes.faces[0] }}
{{ states.image_processing.dlib_face_cam.attributes.faces[0].name }}
{{ states.image_processing.dlib_face_cam.attributes.faces[1] }}
{{ states.image_processing.dlib_face_cam.attributes.faces[1].name }}
case: faces detected and matching sample pictures (faces[] populated)
template state image_processing.dlib_face_cam=2; faces=[{‘name’: ‘PersonB’, ‘entity_id’: ‘image_processing.dlib_face_cam’}, {‘name’: ‘PersonA’, ‘entity_id’: ‘image_processing.dlib_face_cam’}], total_faces=2, friendly_name=Dlib Face cam, device_class=face @ 2018-04-17T21:52:49.987106+10:00>
{‘name’: ‘PersonA’, ‘entity_id’: ‘image_processing.dlib_face_cam’}
{‘name’: ‘PersonB’, ‘entity_id’: ‘image_processing.dlib_face_cam’}
case: faces detected but none matching samples (faces[] empty)
<template state image_processing.dlib_face_cam=1; faces=[], total_faces=1, friendly_name=Dlib Face cam, device_class=face @ 2018-04-17T21:28:40.155448+10:00>
Now i’ve made it this far, and I know where the data is stored, I would like to run an automation trigger on the event fire but need to rotate through the maximum possible number of entries with a for/while loop but also store the positive found names and notify me when detected.
Anyone able to help me (preferably keeping it simple)
petro
(Petro)
April 20, 2018, 11:44am
2
You’ll probably need appdaemon for this or a custom component. the only looping you can do in home-assistant is with templates. Templates only produce a single value.
petro
(Petro)
April 20, 2018, 11:45am
3
You could get inventive with scripts and conditions, but it would get complicated quick.
kortex
April 20, 2018, 11:45am
4
So I’ve gotten to the point that I can pass some info via a script but I can’t manipulate the data passed.
I can’t access the faces[] values calling them directly, any ideas on syntax?
I’ve tried setting the faces array (states.attributes.get(‘faces’)) as a var but I assume it’s being access as a string?
Automation.yaml
action:
alias: ‘’
data_template:
entity_id: image_processing.dlib_face_cam
testd: ‘{{ states.image_processing.dlib_face_cam.attributes }}’
service: python_script.test
alias: Face Recog
condition: []
id: ‘1524057389579’
trigger:
entity_id: image_processing.dlib_face_cam
from: ‘0’
platform: state
test.py
entity_id = data.get(‘entity_id’)
statess = data.get(‘testd’)
states = hass.states.get(entity_id)
logger.warning(“entity_id Passed = {}”.format(states))
logger.warning(“Array Passed: {}”.format(statess))
logger.warning(“Total Faces = {}”.format(states.attributes.get(‘total_faces’)))
logger.warning(“Friendly Name = {}”.format(states.attributes.get(‘friendly_name’)))
logger.warning(“Faces Array = {}”.format(states.attributes.get(‘faces’)))
Output
WARNING:homeassistant.components.python_script.test.py:entity_id Passed = <state image_processing.dlib_face_cam=1; faces=[{‘name’: ‘PersonA’, ‘entity_id’: ‘image_processing.dlib_face_cam’}], total_faces=1, friendly_name=Dlib Face cam, device_class=face @ 2018-04-20T21:42:29.760024+10:00>
WARNING:homeassistant.components.python_script.test.py:Array Passed: {‘faces’: [{‘name’: ‘PersonA’, ‘entity_id’: ‘image_processing.dlib_face_cam’}], ‘total_faces’: 1, ‘friendly_name’: ‘Dlib Face cam’, ‘device_class’: ‘face’}
WARNING:homeassistant.components.python_script.test.py:Total Faces = 1
WARNING:homeassistant.components.python_script.test.py:Friendly Name = Dlib Face cam
WARNING:homeassistant.components.python_script.test.py:Faces Array = [{‘name’: ‘PersonA’, ‘entity_id’: ‘image_processing.dlib_face_cam’}]