mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Update docstrings (#7630)
This commit is contained in:
parent
3b69de8a1a
commit
0e9728d94a
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Support for the demo image processing.
|
Support for the demo image processing.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/demo/
|
https://home-assistant.io/components/demo/
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.image_processing import ATTR_CONFIDENCE
|
from homeassistant.components.image_processing import ATTR_CONFIDENCE
|
||||||
@ -12,7 +12,7 @@ from homeassistant.components.image_processing.microsoft_face_identify import (
|
|||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the demo image_processing platform."""
|
"""Set up the demo image processing platform."""
|
||||||
add_devices([
|
add_devices([
|
||||||
DemoImageProcessingAlpr('camera.demo_camera', "Demo Alpr"),
|
DemoImageProcessingAlpr('camera.demo_camera', "Demo Alpr"),
|
||||||
DemoImageProcessingFace(
|
DemoImageProcessingFace(
|
||||||
@ -21,10 +21,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
|
|
||||||
class DemoImageProcessingAlpr(ImageProcessingAlprEntity):
|
class DemoImageProcessingAlpr(ImageProcessingAlprEntity):
|
||||||
"""Demo alpr image processing entity."""
|
"""Demo ALPR image processing entity."""
|
||||||
|
|
||||||
def __init__(self, camera_entity, name):
|
def __init__(self, camera_entity, name):
|
||||||
"""Initialize demo alpr."""
|
"""Initialize demo ALPR image processing entity."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -61,7 +61,7 @@ class DemoImageProcessingFace(ImageProcessingFaceEntity):
|
|||||||
"""Demo face identify image processing entity."""
|
"""Demo face identify image processing entity."""
|
||||||
|
|
||||||
def __init__(self, camera_entity, name):
|
def __init__(self, camera_entity, name):
|
||||||
"""Initialize demo alpr."""
|
"""Initialize demo face image processing entity."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Component that will help set the dlib face detect processing.
|
Component that will help set the Dlib face detect processing.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/image_processing.dlib_face_detect/
|
https://home-assistant.io/components/image_processing.dlib_face_detect/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Microsoft Face detection platform."""
|
"""Set up the Dlib Face detection platform."""
|
||||||
entities = []
|
entities = []
|
||||||
for camera in config[CONF_SOURCE]:
|
for camera in config[CONF_SOURCE]:
|
||||||
entities.append(DlibFaceDetectEntity(
|
entities.append(DlibFaceDetectEntity(
|
||||||
@ -35,7 +35,7 @@ class DlibFaceDetectEntity(ImageProcessingFaceEntity):
|
|||||||
"""Dlib Face API entity for identify."""
|
"""Dlib Face API entity for identify."""
|
||||||
|
|
||||||
def __init__(self, camera_entity, name=None):
|
def __init__(self, camera_entity, name=None):
|
||||||
"""Initialize Dlib."""
|
"""Initialize Dlib face entity."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self._camera = camera_entity
|
self._camera = camera_entity
|
||||||
@ -62,7 +62,7 @@ class DlibFaceDetectEntity(ImageProcessingFaceEntity):
|
|||||||
import face_recognition
|
import face_recognition
|
||||||
|
|
||||||
fak_file = io.BytesIO(image)
|
fak_file = io.BytesIO(image)
|
||||||
fak_file.name = "snapshot.jpg"
|
fak_file.name = 'snapshot.jpg'
|
||||||
fak_file.seek(0)
|
fak_file.seek(0)
|
||||||
|
|
||||||
image = face_recognition.load_image_file(fak_file)
|
image = face_recognition.load_image_file(fak_file)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Component that will help set the dlib face detect processing.
|
Component that will help set the Dlib face detect processing.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/image_processing.dlib_face_identify/
|
https://home-assistant.io/components/image_processing.dlib_face_identify/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
@ -29,7 +29,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Microsoft Face detection platform."""
|
"""Set up the Dlib Face detection platform."""
|
||||||
entities = []
|
entities = []
|
||||||
for camera in config[CONF_SOURCE]:
|
for camera in config[CONF_SOURCE]:
|
||||||
entities.append(DlibFaceIdentifyEntity(
|
entities.append(DlibFaceIdentifyEntity(
|
||||||
@ -43,7 +43,7 @@ class DlibFaceIdentifyEntity(ImageProcessingFaceEntity):
|
|||||||
"""Dlib Face API entity for identify."""
|
"""Dlib Face API entity for identify."""
|
||||||
|
|
||||||
def __init__(self, camera_entity, faces, name=None):
|
def __init__(self, camera_entity, faces, name=None):
|
||||||
"""Initialize Dlib."""
|
"""Initialize Dlib face identify entry."""
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
import face_recognition
|
import face_recognition
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -77,7 +77,7 @@ class DlibFaceIdentifyEntity(ImageProcessingFaceEntity):
|
|||||||
import face_recognition
|
import face_recognition
|
||||||
|
|
||||||
fak_file = io.BytesIO(image)
|
fak_file = io.BytesIO(image)
|
||||||
fak_file.name = "snapshot.jpg"
|
fak_file.name = 'snapshot.jpg'
|
||||||
fak_file.seek(0)
|
fak_file.seek(0)
|
||||||
|
|
||||||
image = face_recognition.load_image_file(fak_file)
|
image = face_recognition.load_image_file(fak_file)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Component that will help set the microsoft face detect processing.
|
Component that will help set the Microsoft face detect processing.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/image_processing.microsoft_face_detect/
|
https://home-assistant.io/components/image_processing.microsoft_face_detect/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Component that will help set the microsoft face for verify processing.
|
Component that will help set the Microsoft face for verify processing.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/image_processing.microsoft_face_identify/
|
https://home-assistant.io/components/image_processing.microsoft_face_identify/
|
||||||
@ -62,8 +62,8 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize base face identify/verify entity."""
|
"""Initialize base face identify/verify entity."""
|
||||||
self.faces = [] # last scan data
|
self.faces = []
|
||||||
self.total_faces = 0 # face count
|
self.total_faces = 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -71,11 +71,11 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
|||||||
confidence = 0
|
confidence = 0
|
||||||
state = STATE_UNKNOWN
|
state = STATE_UNKNOWN
|
||||||
|
|
||||||
# no confidence support
|
# No confidence support
|
||||||
if not self.confidence:
|
if not self.confidence:
|
||||||
return self.total_faces
|
return self.total_faces
|
||||||
|
|
||||||
# search high confidence
|
# Search high confidence
|
||||||
for face in self.faces:
|
for face in self.faces:
|
||||||
if ATTR_CONFIDENCE not in face:
|
if ATTR_CONFIDENCE not in face:
|
||||||
continue
|
continue
|
||||||
@ -128,7 +128,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
|||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
# send events
|
# Send events
|
||||||
for face in faces:
|
for face in faces:
|
||||||
if ATTR_CONFIDENCE in face and self.confidence:
|
if ATTR_CONFIDENCE in face and self.confidence:
|
||||||
if face[ATTR_CONFIDENCE] < self.confidence:
|
if face[ATTR_CONFIDENCE] < self.confidence:
|
||||||
@ -139,7 +139,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
|||||||
self.hass.bus.async_fire, EVENT_DETECT_FACE, face
|
self.hass.bus.async_fire, EVENT_DETECT_FACE, face
|
||||||
)
|
)
|
||||||
|
|
||||||
# update entity store
|
# Update entity store
|
||||||
self.faces = faces
|
self.faces = faces
|
||||||
self.total_faces = total
|
self.total_faces = total
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
|
|||||||
_LOGGER.error("Can't process image on Microsoft face: %s", err)
|
_LOGGER.error("Can't process image on Microsoft face: %s", err)
|
||||||
return
|
return
|
||||||
|
|
||||||
# parse data
|
# Parse data
|
||||||
knwon_faces = []
|
knwon_faces = []
|
||||||
total = 0
|
total = 0
|
||||||
for face in detect:
|
for face in detect:
|
||||||
@ -220,5 +220,4 @@ class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
|
|||||||
ATTR_CONFIDENCE: data['confidence'] * 100,
|
ATTR_CONFIDENCE: data['confidence'] * 100,
|
||||||
})
|
})
|
||||||
|
|
||||||
# process data
|
|
||||||
self.async_process_faces(knwon_faces, total)
|
self.async_process_faces(knwon_faces, total)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Component that performs OpenCV classification on images.
|
Component that performs OpenCV classification on images.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/image_processing.opencv/
|
https://home-assistant.io/components/image_processing.opencv/
|
||||||
"""
|
"""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user