Skip to content

Commit

Permalink
ps - fix opencv (#7419)
Browse files Browse the repository at this point in the history
* ps - fix opencv

* fix lint
  • Loading branch information
balloob authored and pvizeli committed May 3, 2017
1 parent 203f48c commit 0f94c8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
47 changes: 24 additions & 23 deletions homeassistant/components/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/opencv/
"""
import asyncio
import logging
import os
import voluptuous as vol

import requests

from homeassistant.const import (
CONF_NAME,
CONF_ENTITY_ID,
Expand All @@ -19,7 +20,7 @@
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__)

Expand All @@ -41,9 +42,7 @@
DATA_CLASSIFIER_GROUPS = 'classifier_groups'

DEFAULT_COLOR = (255, 255, 0)
DEFAULT_CLASSIFIER_PATH = os.path.join(
os.path.dirname(BASE_PATH),
'lbp_frontalface.xml')
DEFAULT_CLASSIFIER_PATH = 'lbp_frontalface.xml'
DEFAULT_NAME = 'OpenCV'
DEFAULT_MIN_SIZE = (30, 30)
DEFAULT_NEIGHBORS = 4
Expand All @@ -57,8 +56,7 @@
[vol.Schema({
vol.Optional(CONF_COLOR, default=DEFAULT_COLOR):
vol.Schema((int, int, int)),
vol.Optional(CONF_FILE_PATH, default=DEFAULT_CLASSIFIER_PATH):
cv.isfile,
vol.Optional(CONF_FILE_PATH, default=None): cv.isfile,
vol.Optional(CONF_NAME, default=DEFAULT_NAME):
cv.string,
vol.Optional(CONF_MIN_SIZE, default=DEFAULT_MIN_SIZE):
Expand Down Expand Up @@ -156,27 +154,30 @@ def process_image(image, classifier_group, is_camera):
return group_matches


@asyncio.coroutine
def async_setup(hass, config):
def setup(hass, config):
"""Set up the OpenCV platform entities."""
_LOGGER.info('Async setup for opencv')
if not os.path.isfile(DEFAULT_CLASSIFIER_PATH):
default_classifier = hass.config.path(DEFAULT_CLASSIFIER_PATH)

if not os.path.isfile(default_classifier):
_LOGGER.info('Downloading default classifier')
import urllib3

http = urllib3.PoolManager()
request = http.request('GET', CASCADE_URL, preload_content=False)
r_class = requests.get(CASCADE_URL, stream=True)
with open(default_classifier, 'wb') as f_class:
for chunk in r_class.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f_class.write(chunk)

for group in config[DOMAIN][CONF_GROUPS]:
grp = {}

with open(DEFAULT_CLASSIFIER_PATH, 'wb') as out:
while True:
data = request.read(1028)
if not data:
break
out.write(data)
for classifier, config in group.items():
config = dict(config)

request.release_conn()
if config[CONF_FILE_PATH] is None:
config[CONF_FILE_PATH] = default_classifier

for group in config[DOMAIN][CONF_GROUPS]:
discovery.load_platform(hass, 'image_processing', DOMAIN, group)
grp[classifier] = config

discovery.load_platform(hass, 'image_processing', DOMAIN, grp)

return True
3 changes: 0 additions & 3 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,6 @@ uber_rides==0.4.1
# homeassistant.components.sensor.ups
upsmychoice==1.0.2

# homeassistant.components.opencv
urllib3==1.21

# homeassistant.components.camera.uvc
uvcclient==0.10.0

Expand Down

0 comments on commit 0f94c8a

Please sign in to comment.