robmarkcole / HASS-amazon-rekognition

Home Assistant Object detection with Amazon Rekognition
https://aws.amazon.com/blogs/aws/amazon-rekognition-image-detection-and-recognition-powered-by-deep-learning/
MIT License
87 stars 8 forks source link

Image scan is failing #120

Open schettada opened 1 year ago

schettada commented 1 year ago

I get the below error in logs when i try the image scan service.

HA Version: 2023.09.2 HASS-amazon-rekognition Version: 3.2

Logger: homeassistant.helpers.entity
Source: custom_components/amazon_rekognition/image_processing.py:363
Integration: amazon_rekognition (documentation)
First occurred: 1:46:08 PM (2 occurrences)
Last logged: 1:46:09 PM

Update for image_processing.rekognition_driveway_snapshots_main fails
Update for image_processing.rekognition_front_door_snapshots_main fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 683, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 936, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/image_processing/__init__.py", line 193, in async_update
    await self.async_process_image(image.content)
  File "/usr/src/homeassistant/homeassistant/components/image_processing/__init__.py", line 174, in async_process_image
    return await self.hass.async_add_executor_job(self.process_image, image)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/amazon_rekognition/image_processing.py", line 363, in process_image
    self._image.thumbnail(newsize, Image.ANTIALIAS)
                                   ^^^^^^^^^^^^^^^
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

Below is my config.

- platform: amazon_rekognition
  aws_access_key_id: !secret rekogkey
  aws_secret_access_key: !secret rekogsec
  region_name: us-east-1
  confidence: 90
  targets:
    - target: person
    - target: car
    - target: animal
    - target: pet
    - target: cat
    - target: dog
      confidence: 50
  # roi_x_min: 0.35
  roi_x_max: 0.8
  roi_y_min: 0.4
  roi_y_max: 0.8
  scale: 0.75
  save_file_format: png
  save_file_folder: !secret rekofolder
  save_timestamped_file: true
  always_save_latest_file: true
  source:
    - entity_id: camera.driveway_snapshots_main

- platform: amazon_rekognition
  aws_access_key_id: !secret rekogkey
  aws_secret_access_key: !secret rekogsec
  region_name: us-east-1
  confidence: 90
  targets:
    - target: person
    - target: car
    - target: animal
    - target: pet
    - target: cat
    - target: dog
      confidence: 50
  # roi_x_min: 0.35
  roi_x_max: 0.8
  roi_y_min: 0.4
  roi_y_max: 0.8
  scale: 0.75
  save_file_format: png
  save_file_folder: !secret rekofolder
  save_timestamped_file: true
  always_save_latest_file: true
  source:
    - entity_id: camera.front_door_snapshots_main
Fabio72 commented 1 year ago

Pillow has been updated and does not support antialias any more. Workaround is to patch custom_components/amazon_rekognition/image_processing.py line #363 old self._image.thumbnail(newsize, Image.ANTIALIAS) new self._image.thumbnail(newsize, Image.Resampling.LANCZOS)

robmarkcole commented 1 year ago

@Fabio72 can you submit a PR? Need to use the version of pillow in HA

schettada commented 1 year ago

thank you. this works.