Person and face detection using image_processing with Sighthound

sorry yes.

Created sighthound.yaml and call it from configuration.yaml

  - platform: sighthound
    api_key: Added API Key
    save_file_folder: /config/www/
    save_timestamped_file: True
    scan_interval: 1000 # optional, in seconds
    source:
      - entity_id: camera.garage_cctv

I have
entity camera.sighthound
state attribute of:

access_token: xxxxxx
file_path: /config/www/sighthound_latest.jpg
friendly_name: sighthound

entity: image_processing.sighthound_garage_cctv
state attribute of

faces: 0
unit_of_measurement: people
friendly_name: sighthound_garage_cctv

services - image_processing.scan
entity_picture:

  /api/camera_proxy/camera.sighthound?token=xxxxxxx
supported_features: 0

Camera added all_cctv.yaml and called from configuration.yaml

# Sighthound
  - platform: local_file
    file_path: /config/www/sighthound_latest.jpg
    name: sighthound

Error logs only shows

could not read camera sighthound image from file: /config/www/sighthound_latest.jpg

Have whitelisted /config/www
Have some automation tasks running but using the dev tools to trigger but can not seem to get past this error.

Have a 8 channel DVR that has cameras/RSTP streams into HA and working fine.
Haven’t manged to work out how to get still images from the DVR yet.

#camera:

  - platform: generic

    name: Garage CCTV CH1

    still_image_url: http://10.10.10.15/jpg/image.jpg

    stream_source: rtsp://username:[email protected]:554/channel=1&stream=0.sd

Note below I trigger via DEV tools the face/counter number to show its working.

Capture2

Capture4

Ok the issue is sighthound_latest.jpg in my case after reviewing the logs is the name of the camera which makes it

  - platform: local_file
    file_path: /config/www/sighthound_garage_cctv_latest.jpg
    name: sighthound_garage

You are in docker right? Might be a permissions problem. Set the log level to debug and see if anything useful surfaces

issue was the file name is sighthound_garage_cctv_latest.jpg not sighthound_latest.jpg

/config/www/sighthound_images/sighthound_garage_cctv_latest.jpg

Is there a trick to have multiple cameras?

image_processing:
  !include sighthound.yaml

sighthound.yaml

  - platform: sighthound # 
    api_key: API Key
    save_file_folder: /config/www/sighthound_images/
    #save_timestamped_file: True
    scan_interval: 1000 # optional, in seconds
    source:
      - entity_id: camera.garage_cctv
      - entity_id: camera.deck_valley_cctv
      - entity_id: camera.back_door_cctv
      - entity_id: camera.front_dome_cctv
      - entity_id: camera.deck_drive_cctv
      - entity_id: camera.games_room_cctv
      - entity_id: camera.basement_cctv

added to configuration,yaml

  # List of folders that can be used as sources for sending files
  whitelist_external_dirs:
    - /config/www/sighthound_images/

configuration.yaml calls cctv.yaml (camera:)

# Sighthound
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_garage_cctv_latest.jpg
    name: sighthound_garage
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_back_door_cctv_latest.jpg
    name: sighthound_back_door
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_deck_drive_cctv_latest.jpg
    name: sighthound_deck_drive
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_deck_valley_cctv_latest.jpg
    name: sighthound_deck_valley
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_games_room_cctv_latest.jpg
    name: sighthound_games_room
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_front_dome_cctv_latest.jpg
    name: sighthound_front_dome
  - platform: local_file
    file_path: /config/www/sighthound_images/sighthound_basement_cctv_latest.jpg
    name: sighthound_basement
1 Like

I made the changes you indicated to me in image_processing.py and it looked like this

def process_image(self, image):
    """Process an image."""
    try:
        detections = self._api.detect(image)
        if not detections in None:			
          self.faces = hound.get_faces(detections)
          self.people = hound.get_people(detections)
          metadata = hound.get_metadata(detections)
          self._image_width = metadata["image_width"]
          self._image_height = metadata["image_height"]

          self._state = len(self.people)
          if self._state > 0:
              self._last_detection = dt_util.now().strftime(DATETIME_FORMAT)
          if hasattr(self, "_save_file_folder") and self._state > 0:
              self.save_image(image, self.people, self.faces, self._save_file_folder)
          for face in self.faces:
              self.fire_face_detected_event(face)
          for person in self.people:
              self.fire_person_detected_event(person)

    except hound.SimplehoundException as exc:
        _LOGGER.error(str(exc))
        self.faces = []
        self.people = []
        self._image_width = None
        self._image_height = None

when you run the automation it gives the following error

Wed Feb 26 2020 22:14:56 GMT-0300 (hora estándar de Argentina)
Update for image_processing.sighthound_cgaleria fails
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 279, in async_update_ha_state
await self.async_device_update()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 459, in async_device_update
await self.async_update()
File “/usr/src/homeassistant/homeassistant/components/image_processing/init.py”, line 132, in async_update
await self.async_process_image(image.content)
File “/usr/src/homeassistant/homeassistant/components/image_processing/init.py”, line 112, in async_process_image
return await self.hass.async_add_job(self.process_image, image)
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/sighthound/image_processing.py”, line 112, in process_image
if not detections in None:
TypeError: argument of type ‘NoneType’ is not iterable

Automatization.yaml

  • id: scan
    alias: Camera Picture Galeria
    trigger:
    • entity_id: binary_sensor.camaragaleria
      platform: state
      to: ‘on’
      action:
      • service: image_processing.scan
        data:
        entity_id: image_processing.sighthound_cgaleria

that could be happening?

@phontakly please create a pull request on the repo so I can review changes. Thx

@droidblast config looks correct

created!!!

I have it now creating images when I run image_processing.scan but how do I trigger a motion? I see the automation’s examples but I don’t see from say logs what to look for? Scan interval 1000 every 15 minutes is good if there is a face detected but generally this is not the case. So what I need or is missing is how to trigger the image_processing.scan per camera when there is a face detected?

@phontakly where did you create the PR?
@droidblast I use a PIR sensor to detect motion

Thanks is there a way to do via cameras? Camera - Home Assistant

You could tryout https://www.home-assistant.io/integrations/ffmpeg_motion/
Alternatively I think tools like motioneye will do motion detection

what is PR???

Pull request

Hello, I used…

image_processing:
  - platform: dlib_face_detect
    source:
      - entity_id: camera.veranda

But I never have an event of face recognition… even if I stare at the camera…

In the logs:

2020-04-18 23:47:16 WARNING (MainThread) [homeassistant.helpers.entity] Update of image_processing.dlib_face_veranda is taking over 10 seconds
2020-04-18 23:47:16 ERROR (MainThread) [homeassistant.components.image_processing] Error on receive image from entity: Unable to get image

robmarkcole noticed this error after a ha core check

Platform error image_processing.sighthound - requirements for sighthound not found: [‘simplehound==0.2’]

Manifest

{
        "domain": "sighthound",
        "name": "Sighthound custom component",
        "documentation": "https://github.com/robmarkcole/HASS-Sighthound",
        "requirements": [
                "simplehound==0.2"
        ],
        "dependencies": [],
        "codeowners": [
                "@robmarkcole"
        ]
}

@StefanoGiu that error is from dlib, not sighthound. Actually it appears not to be getting a camera image

@droidblast try updating your HA - we fixed that issue in a recent release

How can I fix it?

Thanks running the latest version Home Assistant 0.108.6 with HACS latest version as well.

@robmarkcole I tried to use your component, but I get the following error:

2020-04-19 12:02:20 ERROR (MainThread) [homeassistant.config] Platform error: image_processing
Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\homeassistant\config.py", line 769, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "C:\Python38\lib\site-packages\homeassistant\loader.py", line 276, in get_platform
    cache[full_name] = importlib.import_module(
  File "C:\Python38\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\stefa\AppData\Roaming\.homeassistant\custom_components\sighthound\image_processing.py", line 19, in <module>
    from homeassistant.components.image_processing import (
ImportError: cannot import name 'draw_box' from 'homeassistant.components.image_processing' (C:\Python38\lib\site-packages\homeassistant\components\image_processing\__init__.py)

@robmarkcole
draw_box is not in the definition of image_processing…

from homeassistant.components.image_processing import (
    PLATFORM_SCHEMA,
    ImageProcessingEntity,
    ATTR_AGE,
    ATTR_FACES,
    ATTR_GENDER,
    CONF_SOURCE,
    CONF_ENTITY_ID,
    CONF_NAME,
    draw_box,
)