ps - fix opencv ()

* ps - fix opencv

* fix lint
This commit is contained in:
Paulus Schoutsen 2017-05-03 03:15:04 -07:00 committed by Pascal Vizeli
parent 203f48cadc
commit 0f94c8a2e7
2 changed files with 25 additions and 27 deletions
homeassistant/components
requirements_all.txt

View file

@ -4,11 +4,12 @@ Support for OpenCV image/video 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/opencv/ https://home-assistant.io/components/opencv/
""" """
import asyncio
import logging import logging
import os import os
import voluptuous as vol import voluptuous as vol
import requests
from homeassistant.const import ( from homeassistant.const import (
CONF_NAME, CONF_NAME,
CONF_ENTITY_ID, CONF_ENTITY_ID,
@ -19,7 +20,7 @@ from homeassistant.helpers import (
config_validation as cv, config_validation as cv,
) )
REQUIREMENTS = ['opencv-python==3.2.0.6', 'numpy==1.12.0', 'urllib3==1.21'] REQUIREMENTS = ['opencv-python==3.2.0.6', 'numpy==1.12.0']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -41,9 +42,7 @@ CONF_SCALE = 'scale'
DATA_CLASSIFIER_GROUPS = 'classifier_groups' DATA_CLASSIFIER_GROUPS = 'classifier_groups'
DEFAULT_COLOR = (255, 255, 0) DEFAULT_COLOR = (255, 255, 0)
DEFAULT_CLASSIFIER_PATH = os.path.join( DEFAULT_CLASSIFIER_PATH = 'lbp_frontalface.xml'
os.path.dirname(BASE_PATH),
'lbp_frontalface.xml')
DEFAULT_NAME = 'OpenCV' DEFAULT_NAME = 'OpenCV'
DEFAULT_MIN_SIZE = (30, 30) DEFAULT_MIN_SIZE = (30, 30)
DEFAULT_NEIGHBORS = 4 DEFAULT_NEIGHBORS = 4
@ -57,8 +56,7 @@ CLASSIFIER_GROUP_CONFIG = {
[vol.Schema({ [vol.Schema({
vol.Optional(CONF_COLOR, default=DEFAULT_COLOR): vol.Optional(CONF_COLOR, default=DEFAULT_COLOR):
vol.Schema((int, int, int)), vol.Schema((int, int, int)),
vol.Optional(CONF_FILE_PATH, default=DEFAULT_CLASSIFIER_PATH): vol.Optional(CONF_FILE_PATH, default=None): cv.isfile,
cv.isfile,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): vol.Optional(CONF_NAME, default=DEFAULT_NAME):
cv.string, cv.string,
vol.Optional(CONF_MIN_SIZE, default=DEFAULT_MIN_SIZE): vol.Optional(CONF_MIN_SIZE, default=DEFAULT_MIN_SIZE):
@ -156,27 +154,30 @@ def process_image(image, classifier_group, is_camera):
return group_matches return group_matches
@asyncio.coroutine def setup(hass, config):
def async_setup(hass, config):
"""Set up the OpenCV platform entities.""" """Set up the OpenCV platform entities."""
_LOGGER.info('Async setup for opencv') default_classifier = hass.config.path(DEFAULT_CLASSIFIER_PATH)
if not os.path.isfile(DEFAULT_CLASSIFIER_PATH):
if not os.path.isfile(default_classifier):
_LOGGER.info('Downloading default classifier') _LOGGER.info('Downloading default classifier')
import urllib3
http = urllib3.PoolManager() r_class = requests.get(CASCADE_URL, stream=True)
request = http.request('GET', CASCADE_URL, preload_content=False) with open(default_classifier, 'wb') as f_class:
for chunk in r_class.iter_content(chunk_size=1024):
with open(DEFAULT_CLASSIFIER_PATH, 'wb') as out: if chunk: # filter out keep-alive new chunks
while True: f_class.write(chunk)
data = request.read(1028)
if not data:
break
out.write(data)
request.release_conn()
for group in config[DOMAIN][CONF_GROUPS]: for group in config[DOMAIN][CONF_GROUPS]:
discovery.load_platform(hass, 'image_processing', DOMAIN, group) grp = {}
for classifier, config in group.items():
config = dict(config)
if config[CONF_FILE_PATH] is None:
config[CONF_FILE_PATH] = default_classifier
grp[classifier] = config
discovery.load_platform(hass, 'image_processing', DOMAIN, grp)
return True return True

View file

@ -808,9 +808,6 @@ uber_rides==0.4.1
# homeassistant.components.sensor.ups # homeassistant.components.sensor.ups
upsmychoice==1.0.2 upsmychoice==1.0.2
# homeassistant.components.opencv
urllib3==1.21
# homeassistant.components.camera.uvc # homeassistant.components.camera.uvc
uvcclient==0.10.0 uvcclient==0.10.0